[alt.sources] from -- mail summary generater

lee@sq.sq.com (Liam R. E. Quin) (12/18/89)

The enclosed shell script prints a summary of my incoming mail.  The summary
is better than Mail/mailx's "h" line; it looks a bit like this:
----------------------------------- M A I L -----------------------------------
waterloo.edu!looking!brad: S/ Re: Modifying news storage for fast searches Ok, 
             toad.com!gnu: S/ Re: GNU License OK...if you ever find out more ab
             research!bwk: S/ Re: job offer Yes, when can I start at Unixsys?
o.edu!Sun.COM!uunet!henry: S/ troff and such Thanks for the help. Software Prac
nrcaer!cognos!alzabo!tris: S/ Re: Word list wanted. In rec.puzzles you write: >
       research!alice!dmr: S/ Thanks for the help learning C
roys%uk.ac.sussex.cogs@NF: S/ Re: BOOK REQUEST Okay - address from 15th Dec - 9
.eu.net!westhawk.UUCP!thp: S/ modems etc. I'm keen (if a bit skint). > give me 
                     dave: Oh yeah! I forgot about this 
                      msb: S/ .uimp idea What about making .uimp trimodal? .uim
-------------------------------------------------------------------------------

[OK, I admit it, I made up a couple of the items in there, real wizards know
which ones :-) :-)]

uucp !-style paths are truncated on the left, so you get to see the username
(as in the first line); Internet %/@-style addresses are truncated on the
right (as in roys%uk.ac. ....) for the same reason.

Then it shows S/ if there was a Subject: line (not all mailers add one),
followed by the text of the subjectline (if any) and the first few words of
text from the body of the message.

There are a three control characters at one point.


Have fun!

Lee

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  from
# Wrapped by lee@sq on Sun Dec 17 17:25:01 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'from' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'from'\"
else
echo shar: Extracting \"'from'\" \(2075 characters\)
sed "s/^X//" >'from' <<'END_OF_FILE'
X#! /bin/sh
X# print summary of mail.
X# Hacked by Liam Quin (using nawk) to account for Internet addresses...
X# on SysV, put the next line at the start of the script:
X: use /bin/sh
X
if      test -s "$MAIL"
then    nawk '
X	BEGIN {
X	    h = "-----------------------------------"
X	    print h " M A I L " h
X	}
X
X	/^[ 	]/ { next } # skip RFC822 continuation lines from Sendmail etc
X
X	# You might want to remove the >From
X	($1 == ">From" || $1 == "From") && $(NF-3) != "forwarded" {
X	    # Delete common (boring) domains
X	    ## Uncomment if you have mks awk
X	    ## $0 = $0 "."
X	    ## gsub(/[.!@%][cC][oO][mM]([^A-Za-z0-9-])/, "\\1") 	# .com
X	    ## gsub(/[.!@%][rE][dD][uU]([^A-Za-z0-9-])/, "\\1") 	# .edu
X	    ## gsub(/[.!@%][uU][uU][cC][pP]([^A-Za-z0-9-])/, "\\1")	# .uucp
X	    ## gsub(/\.$/, "")
X	    # deal with control characters other than TAB & LF:
X	    # (if you do not have nawk, comment this out and use vis, cat -v
X	    # or col -b on the input to deal with this --
X	    # i.e., col -b < $MAIL | awk ... )
X	    gsub(/[-]/, "?")
X	    # above line reads gsub(/[^A-^H^K^_]/, "?"), with control chars
X
X	    if (x==1) {printf "%.79s\n",str;sender=""}
X	    x=0
X
X	    # From anything remote from utzoo
X	    if ($(NF-2) == "remote") sender = $NF "!" $2
X	    else if ($2 !~ /^uucp/) {  # From user <date> other-stuff
X		if (sender != "") sender = sender "!" $2;
X		else sender = $2
X	    }
X
X	    # str = sprintf("%-20s: ",sender);
X	    len = length(sender)
X	    if (len > 25) {
X		if (sender ~ /[^!@]*[@%]/) {
X		    # Internet address, lose the end
X		    str = sprintf("%-25.25s: ",sender);
X		} else { # uuucp address, lose the beginning
X		    str = sprintf("%-25.25s: ", substr(sender, len-24, 25))
X		}
X	    } else { # it all fits
X		str = sprintf("%25.25s: ", sender);
X	    }
X	    next
X	}
X
X	/^[a-zA-Z0-9-]*:/ && $1 != "Subject:" {next}
X
X	$1 == "Subject:"  { $1 = "S/" } # delete this line to see "Subject:"
X	!/^From /&&length(str)<79 {
X	    for (i=1;i<=NF;i++) str = str $i " "
X	    x = 1
X	}
X
X	END {
X	    if (x==1) printf "%.79s\n", str
X	    print h "---------" h
X	}' $MAIL
fi
END_OF_FILE
echo shar: 3 control characters may be missing from \"'from'\"
if test 2075 -ne `wc -c <'from'`; then
    echo shar: \"'from'\" unpacked with wrong size!
fi
chmod +x 'from'
# end of 'from'
fi
echo shar: End of shell archive.
exit 0
-- 
Liam R. Quin, lee@sq.com Until Dec. 20th  (visiting sq, not an employee)
After Dec 20, Unixsys (UK) Ltd, Knutsford, UK -- +44 565 50021
At home: +44 925 831084 (0830 GMT to midnight GMT only please...)
rn: .signature: cannot open: no such fire or dirigible