[comp.sources.misc] v05i018: ml: A catagorial mail divider

ccea3@rivm.UUCP (Adri Verhoef) (10/28/88)

Posting-number: Volume 5, Issue 18
Submitted-by: "Adri Verhoef" <ccea3@rivm.UUCP>
Archive-name: ml

Daily I receive some 65 to about 100 mail messages as they are contributed
from some 30 machines by loginnames as
	bin, news, lp, *uucp*
who have their messages forwarded to a central/private single $MAIL file.
To put these messages into categories I order them by Subject and put them
into separate files.  Then I pg(1) these files to look at their contents.

- It works as follows:
I call the mailer to show me the messages with possible Subjects; then I
order by Subject and awk(1) them into categories; then I s(ave) the
messages per Subject into files with a useful name; then per file I
preprocess (e.g. sed(1)) the file and pg(1) the output.

NOTES:
- Only New or Unread articles are s(ave)d.
- After reading, the files get processed by 'rm'; you may want to change
  this into a mv(1) command [if your own 'rm' doesn't do that already].
- You may add or delete Subjects as you prefer personally.  If you do so,
  you may have to add or delete a Subject in two (or three) places in 'ml'.
- The default directory for the saved article files is named "Mail".

Here it is, folks, enjoy:

#! /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:  ml
# Wrapped by a3@rivm on Thu Sep 29 18:26:06 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f ml -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"ml\"
else
echo shar: Extracting \"ml\" \(3114 characters\)
sed "s/^X//" >ml <<'END_OF_ml'
X#ident	"@(#)ml.sh	1.1.3	(a3)	8 aug 1988"
X# Save certain articles, currently in spooled mailbox, into several files, and
X# read those files, and clean them up.  Then proceed reading the rest.
X
X[ -d Mail -a -w Mail ] || { echo "Directory 'Mail' not available."; exit 1; }
Xcd Mail || exit 2
X
Xart_id=1
Xsender=2
X#dayOwk=3
X#monOyr=4
X#dayOmo=5
X#timOdy=6
Xartsiz=7
Xsubj_1=8
Xsubj_2=9
Xsubj_3=10
Xsubj_4=11
X
Xmailx -H |
X sed -n 's/^ [NU]//p' |	#new or unread
X  awk '
X   NF=='$artsiz' {
X	if ($'$sender'~/lp$/) f="lp";
X	if ($'$sender'~/root$/) f="root";
X	if ($'$sender'~/uucp$/) f="uucp";
X   }
X   NF=='$subj_1' {
X	if ($(NF)=="/usr/spool/uucp/.Corrupt") f="Corrupt";
X	if ($(NF)=="cleanup") f=$(NF);
X	if ($(NF)=="cores") f=$(NF);
X	if ($(NF)=="transfer-statistics") f="xfer";
X	if ($(NF)=="uu-status") f=$(NF);
X   }
X   $'$subj_1'=="Newsgroup" {
X	f=$'$subj_1';
X   }
X   NF=='$subj_2' {
X	if ($(NF-1)=="UucpLog") f=$(NF-1);
X	if ($(NF-1)=="trimlib") f=$(NF-1);
X	if ($(NF-1)=="uucp") {
X		if ($(NF)=="Admin") f=$(NF);
X		if ($(NF)=="DENIED") f=$(NF);
X		if ($(NF)=="requests") f=$(NF);
X	}
X   }
X   NF=='$subj_3' {
X	if ($(NF-2)=="Diskgebruik" && $(NF-1)=="op") f=$(NF-2);
X	if ($(NF-2)=="Warning" && $(NF-1)=="From") f=$(NF-2);
X	if ($(NF-2)=="sendsys" && $(NF-1)=="control") f=$(NF-2);
X	if ($(NF-2)=="uucleanup" && $(NF-1)=="ran;") f=$(NF-2);
X   }
X   NF=='$subj_4' {
X	if ($(NF-3)=="Problems" && $(NF)=="active") f=$(NF-3);
X	if ($(NF-3)=="response" && $(NF)=="sendsys") f=$(NF-3);
X   }
X   {
X	if (f=="") next;
X	file[f]=file[f]" "$'$art_id';
X	f="";
X	ct++;
X   }
X   END {
X	if (ct==0) exit(1);
X	for (f in file) {
X		max=480;
X		if (length(file[f]) > max) {
X			n=max;
X			while (substr(file[f],n,1)!=" ") n--;
X			printf("s%s %s\n",substr(file[f],1,n),f);
X		}
X		else printf("s%s %s\n",file[f],f);
X	}
X	for (f in file) if (f=="xfer") { print "|",file[f],"\"pg\""; break; }
X   }
X  ' | { [ $? = 0 ] && mailx; }
X
Xfor f in "lp" "root" "uucp" \
X	"Corrupt" "Newsgroup" "cleanup" "cores" "uu-status" \
X	"UucpLog" "trimlib" "Admin" "DENIED" "requests" \
X	"sendsys" "uucleanup" "Diskgebruik" "Warning" \
X	"Problems" "response" \
X	# "xfer"	# Always as last one.  But already taken care of.
Xdo
X [ -f "$f" ] || continue
X echo $f
X case $f in
X  "Diskgebruik") mailx -f "$f";;
X  "UucpLog") pg "$f";;
X  "uu-status")
X	sed '	
X		/^From/ {
X			N
X			D
X		}
X		/^>From/ {
X			N
X			/^>From.*\n>From/ {
X				D
X			}
X		}
X		s/\nSubject: .*//
X		/^Status: /d
X		/^$/d
X	' "$f" | pg;;
X  "Admin"|"Corrupt"|"DENIED"|"Problems"|"cleanup"|"lp"|"requests"|"root"|"uucp")
X	sed '	
X		/^From/ {
X			N
X			/^From.*\n>From/ {
X				D
X			}
X		}
X		/^>From/ {
X			N
X			/^>From.*\n>From/ {
X				D
X			}
X		}
X		s/\nSubject: .*//
X		s/\nStatus: .*//
X		/^Status: /d
X		/^$/d
X	' "$f" | pg;;
X#  "Corrupt"|"lp"|"root"|"uucp")
X#	sed '	
X#		/^Status: /d
X#		/^$/d
X#	' "$f" | pg;;
X  "trimlib")
X	sed '	
X		/^>From /d
X		/^To: /d
X		/^Status: /d
X	' "$f" | pg;;
X  "uucleanup") sed -n '/.Xqtdir/p' "$f" | pg;;
X  # "xfer") ;;# Already taken care of.
X  *)
X	sed '
X		/^>From /d
X		/^Status: /d
X		/^$/d
X	' "$f" | pg
X	;;
X esac
X [ $? = 0 ] && [ "xfer" != "$f" ] && rm "$f"
Xdone
X
Xecho "Read mail ? [YN]\c"
Xread x
Xcase $x in
X [Yy]) exec mailx;;
Xesac
END_OF_ml
if test 3114 -ne `wc -c <ml`; then
    echo shar: \"ml\" unpacked with wrong size!
fi
chmod +x ml
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0