lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LYNX-DEV Lynx read mail programs


From: Jim Spath (Webmaster Jim)
Subject: LYNX-DEV Lynx read mail programs
Date: Mon, 10 Mar 1997 11:23:26 -0500 (EST)

I've polished up a lynxcgi application to allow Lynx to read email folders
and display http and mailto tags.  I'm posting it to the list as a shar
file so that folks can get the whole thing, and so that it's archived as
well.  Suggestions for improvements are welcome.  Enjoy! 

------cut here------
# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#       lynxreadmail-0.1
#       lynxreadmail-0.1/README
#       lynxreadmail-0.1/mail_cgi.html
#       lynxreadmail-0.1/pineab2html.sh
#       lynxreadmail-0.1/readfolders.sh
#       lynxreadmail-0.1/readmail.sh
#       lynxreadmail-0.1/sonofbabymail.pl
#
echo c - lynxreadmail-0.1
mkdir -p lynxreadmail-0.1 > /dev/null 2>&1
echo x - lynxreadmail-0.1/README
sed 's/^X//' >lynxreadmail-0.1/README << 'END-of-lynxreadmail-0.1/README'
Xlynxreadmail is a set of programs to allow reading of mail folders
Xfrom within Lynx with display of html and mailto links.
X
XPrograms:
X
Xmail_cgi.html -- a template page to initiate the process
Xpineab2html.sh -- a shell script to convert Pine address book to html
Xreadfolders.sh -- a shell script to read your mail directory and
X                  display the current folders
Xreadmail.sh -- a shell script frontend to SonOfBabyMail
Xsonofbabymail.pl -- a perl script to convert mail folders to html
X
XUse:
X
X*)  This is for Lynxcgi, which only works on UN*X at present.
X
X*)  Lynx must be compiled with "#define LYNXCGI_LINKS" un-commented
X    in the userdefs.h file.
X
X*)  Perl is required.
X
X*)  Modify the html and shell scripts to suit your needs.  The html
X    file needs full paths to your lynxcgi code, or the LYNXCGI_PATH
X    needs to be set in lynx.cfg (I haven't done the latter).
X
X*)  The readfolders.sh script relies on your version of "file" being
X    able to distinguish mail text files.  The current version of
X    file I use is ftp://ftp.deshaw.com/pub/file/file-3.22.tar.gz
X    Doing this lets you skip files that don't seem to contain mail.
X
X*)  I've added double quotes to the second echo command in the shell
X    scripts.  Otherwise, Lynx doesn't recognize the stream as valid
X    html text.  Your shell may vary.
X
X*)  My shar program doesn't maintain mode flags.  You'll need to 
X    make the scripts executable.
X
XBugs:
X
X*)  The sonofbabymail perl script assumes the mail messages begin
X    with "From".  This is a generous assumption.
X
X*)  The perl script only recognizes email addresses with "@" in 
X    them.  Local and UUCP addresses are not recognized.
X
X*)  The perl script may incompletely transform some URLs, notably
X    those with trailing slashes.  But tildes are acceptable :-)
X
XTo Do:
X
X*)  Modify the perl script so that messages beginning with <HTML>
X    are not escaped, but delivered intact so Lynx can deal with
X    the embedded tags. 
X
X*)  Add the correct Subject to outgoing messages.
X
X*)  Create a threaded index of Subjects.
X
X*)  Updated versions of sonofbabymail.pl will be in:
X    http://www.bcpl.lib.md.us/~jspath/perl/sonofbabymail.pl
X
X*)  Updated versions of this package will be in:
X    http://www.bcpl.lib.md.us/~jspath/lynxreadmail.shar.gz
X
XAuthor:
X
XJim Spath <address@hidden>
X
XThanks:
X
XJohn Callender <address@hidden> <http://www.west.net/~jbc/> Author of 
babymail.pl
XNelson Henry Eric <address@hidden> beta tester
X
X
END-of-lynxreadmail-0.1/README
echo x - lynxreadmail-0.1/mail_cgi.html
sed 's/^X//' >lynxreadmail-0.1/mail_cgi.html << 
'END-of-lynxreadmail-0.1/mail_cgi.html'
X<html>
X<head>
X<title>Lynx EMail Gateway</title>
X</head>
X<body>
X<h2>Mail directory</h2>
X<a 
href="lynxcgi://localhost/usr/acct/spath/lynxreadmail/readfolders.sh">folders</a>
X<h2>Address Books</h2>
X<ul>
X<li><a 
href="lynxcgi://localhost/usr/acct/spath/lynxreadmail/pineab2html.sh">Pine 
.addressbook</a>
X<li><a 
href="file://localhost/usr/acct/spath/.netscape/address-book.html">Netscape 
address-book.html</a>
X</ul>
X</body>
X</html>
END-of-lynxreadmail-0.1/mail_cgi.html
echo x - lynxreadmail-0.1/pineab2html.sh
sed 's/^X//' >lynxreadmail-0.1/pineab2html.sh << 
'END-of-lynxreadmail-0.1/pineab2html.sh'
X#!/bin/sh
Xecho "Content-type: text/html"
Xecho ""
XMYHOME=/usr/acct/spath ; export MYHOME
Xcat ${MYHOME}/.addressbook |\
X  awk -F "\t" '{printf "<li><a href=\"mailto:%s\";>%s</a> %s\n", $3, $1, $2}'
END-of-lynxreadmail-0.1/pineab2html.sh
echo x - lynxreadmail-0.1/readfolders.sh
sed 's/^X//' >lynxreadmail-0.1/readfolders.sh << 
'END-of-lynxreadmail-0.1/readfolders.sh'
X#!/bin/sh
XMYHOME=/usr/acct/spath
Xecho "Content-type: text/html"
Xecho ""
Xcd ${MYHOME}/mail
X
Xecho "<h1>Mail Folders in ${MYHOME}/mail</h1>"
Xecho "<ul>"
Xfor f in `file * | grep "mail text" | awk -F: '{print $1}' `
Xdo
X  echo "<li><a href=\""
X  echo "lynxcgi://localhost${MYHOME}/lynxreadmail/readmail.sh?"
X  echo $f
X  echo "\">"
X  ls -l ${f}
X  echo "</a>"
Xdone
Xecho "</ul>"
END-of-lynxreadmail-0.1/readfolders.sh
echo x - lynxreadmail-0.1/readmail.sh
sed 's/^X//' >lynxreadmail-0.1/readmail.sh << 
'END-of-lynxreadmail-0.1/readmail.sh'
X#!/bin/sh
XMYHOME=/usr/acct/spath
Xif [ $# = 0 ]
Xthen
X  echo "Content-type: text/html"
X  echo ""
X  ${MYHOME}/perl/sonofbabymail.pl <${MYHOME}/mail/mbox
Xelse
X  echo "Content-type: text/html"
X  echo ""
X  ${MYHOME}/perl/sonofbabymail.pl <${MYHOME}/mail/$1
Xfi
X  
END-of-lynxreadmail-0.1/readmail.sh
echo x - lynxreadmail-0.1/sonofbabymail.pl
sed 's/^X//' >lynxreadmail-0.1/sonofbabymail.pl << 
'END-of-lynxreadmail-0.1/sonofbabymail.pl'
X#!/usr/bin/perl
X# Jim Spath <address@hidden>
X# sonofbabymail.pl
X# created: Mon Feb 24 13:31:24 EST 1997
X# changes: Tue Feb 25 20:05:05 EST 1997
X#          added ~ and : to allowable http characters
X#          allow "X-Url" headers to display 
X# This script is http://www.bcpl.lib.md.us/~jspath/perl/sonofbabymail.pl
X################################################################
X#  Derived from:
X################################################################
X#  babymail.pl
X#  Last updated June 23, 1996
X#  This script, which was inspired by Kevin Hughes' (and Tom
X#  Grubers') hypermail program
X#  (http://www.ipps.lsa.umich.edu/software/hypermail/hypermail.html),
X#  is designed to convert messages from Unix mailbox format to HTML.
X#  The latest version of the script is at:
X#  http://www.west.net/~jbc/tools/babymail.html
X#  You're free to use babymail however you like. As a courtesy, I 
X#  ask that you not remove my name and contact information from it. 
X#  And if you make improvements to it, I would very much appreciate 
X#  hearing about them.
X#  Happy archiving!
X#  John Callender
X#  address@hidden
X#  http://www.west.net/~jbc/
X##################################################################
X#                 * * * Configuration: * * *
X# $maintainer_name = "Your Name Here";
X# Don't forget the backslash in front of the "at" sign...
X# $maintainer_address = "address@hidden";
X# $maintainer_site = "My Home Page";
X# $maintainer_URL = "http://www.something.com/~me/";;
X#          * * * End of configuration section * * *
X################################################################
X
Xopen(IN, '-');
Xopen(OUT, '>-');
X
X$msg_number = 1;
X
Xprint OUT <<EOH;
X<html>
X<head>
X<title>Mail Drop</title>
X</head>
X<body>
X<a href="#index">index of messages</a>
XEOH
X
X$forward="no";
Xif ($forward eq "yes") { 
X       $header = "bogus";
X} else {
X       $header = "yes";
X}
X
Xwhile(<IN>) {
X       $last_line = $this_line;
X       chop($this_line = $_);
X       $this_line =~ s/^[\s]+$//;
X       if (($this_line eq "") && ($last_line eq "")) { next; }
X
X       if ($header eq "bogus") {
X               if ($this_line eq "") { 
X                       $header = "yes";
X               }
X               next;
X       }
X
X       $this_line =~ s/\</\&lt\;/g;
X       $this_line =~ s/\>/\&gt\;/g;
X#      unless (($this_line =~ /^From [^ ]+\@/) && ($last_line eq "")) {
X       unless ($this_line =~ /^From /) {
X
X               # add mailto: hrefs to email addresses
X
X               $this_line =~ 
Xs/\b(address@hidden)\b/<A HREF=\"mailto:$1\";>$1<\/A>/g;
X       }
X
X               # add http: hrefs to URLs
X
X       $this_line =~ 
Xs/(http\:\/\/[\w\-\.\/\?\=\~\:]+)\b/\<A HREF\=\"$1\"\>$1\<\/A\>/ig;
X
X               # add ftp: hrefs
X
X       $this_line =~ 
Xs/(ftp\:\/\/[\w\-\.\/\?\=]+)\b/\<A HREF\=\"$1\"\>$1\<\/A\>/ig;
X
X       if ($header eq "yes") {
X               if ($this_line eq "") { 
X                       $header = "no"; 
X                       next;
X               }
X               if (/^From: /) {
X                       $from = substr($this_line,6);
X                       $sender[$msg_number] = $from;
X                       next;
X               }
X               if (/^Newsgroups: /) {
X                       $newsgroups = substr($this_line,12);
X                       next;
X               }
X               if (/^Subject: /) {
X                       $subject = substr($this_line,9);
X                       next;
X               }
X               if (/^Date: /) {
X                       $date = substr($this_line,6);
X                       next;
X               }
X               if (/^Organisation: /i) {
X                       $org = substr($this_line,13);
X                       next;
X               }
X               if (/^Organization: /i) {
X                       $org = substr($this_line,13);
X                       next;
X               }
X               if (/^X-Url: /i) {
X                       $xurl = substr($this_line,7);
X                       next;
X               }
X       }
X       if ($header eq "no") {
X#              if (($this_line =~ /^From [^ ]+\@/) && ($last_line eq "")) {
X               if ($this_line =~ /^From /) {
X                       if ($forward eq "yes") {
X                               $header = "bogus";
X                       } else {
X                               $header = "yes";
X                       }
X                       &process_msg;
X                       next;
X               }
X               $body .= "$this_line\n";
X       }
X}
X
X&process_msg; # to get the last message...
X
Xprint OUT "<a name=\"index\">Index of messages</a>";
Xprint OUT "<ul>";
Xfor ($it = 1 ; $it < $msg_number; $it++) {
X  print OUT "<li>Msg: <a href=\"#msg".$it."\">", $it, "</a> From: \n", 
$sender[$it];
X}
Xprint OUT "</ul>";
X
Xprint OUT <<EOT;
X</body>
X</html>
XEOT
X
Xexit;
X
Xsub process_msg {
X       if ($body eq "") { exit; }
X       $last_char = chop($body);
X       while ($last_char eq "\n") {
X               $last_char = chop($body);
X       }
X       $body .= $last_char;    
X       &write_letter;
X}      
X
Xsub write_letter {
X       print OUT <<EOM;
X<h2>Message Number: $msg_number</h2>
X<a name="msg$msg_number"></a>
X<h3>$subject</h3>
X<pre>From: $from
XDate: $date
XEOM
X       unless ($org eq "") {
X               print OUT "Organisation: $org\n";
X       }
X       unless ($newsgroups eq "") {
X               print OUT "Newsgroups: $newsgroups\n";
X       }
X       unless ($xurl eq "") {
X               print OUT "URL: $xurl\n";
X       }
X       print OUT <<EON;
X$body
X</pre>
X<hr>
XEON
X       $msg_number++;
X# Okay, forget everything till the next line comes along.
X       $body="";
X       $date="";
X       $from="";
X        $newsgroups="";
X        $org="";
X        $subject="";
X        $xurl="";
X
X}
END-of-lynxreadmail-0.1/sonofbabymail.pl
exit
------cut here------


;
; To UNSUBSCRIBE:  Send a mail message to address@hidden
;                  with "unsubscribe lynx-dev" (without the
;                  quotation marks) on a line by itself.
;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]