[comp.mail.sendmail] Filter for bounced mail

andy@jhunix.HCF.JHU.EDU (Andy S Poling) (08/08/90)

With all of this talk in comp.mail.misc lately of postmastering and ethics,
I finally remembered to post this little filter Bourne shell script.  It
aint fancy, but it does work.  I wouldn't be surprised to find a couple
hundred other postmasters have done something similiar.

It is intended for use with sendmail as the error address (you know, the "P"
macro).  It filters out all private information, leaving only the headers
(minus the Subject), before forwarding the bounced mail to the postmaster.  

I feel much better scanning bounced mail knowing I can't accidentally see
the message body.  In several months of constant use (probably a thousand
bounced mail messages) it has not failed to remove the private information
once.  One very pleasant side effect is the reduction in the size of the
postmaster's mailbox.

I set the "P" macro to "errors", then alias errors to
"|/usr/local/lib/error_filter" in the aliases file.

--
Andy Poling                              Internet: andy@gollum.hcf.jhu.edu
Network Services Group                   Bitnet: ANDY@JHUNIX
Homewood Academic Computing              Voice: (301)338-8096    
Johns Hopkins University                 UUCP: uunet!mimsy!aplcen!jhunix!andy



#!/bin/sh
#
#  This is a filter for error messages to avoid disclosing
#  private mail to the postmaster
#
#  What it does is:
#  * remove the Subject: line from the headers of the bounced mail
#  * remove the message body
#
# Andy Poling	5-29-90
# (andy@gollum.hcf.jhu.edu)
#

TMPFILE=/tmp/mailfail.$$
trap "rm $TMPFILE; exit" 1 2 3 4 5 6 7 8 9 15

echo "Subject: FAILED MAIL

================================= FAILED MAIL =============================" > $TMPFILE
chmod 600 $TMPFILE

##
## read everything up to the failed message header
##
while read LINE
do
	if [ "$LINE" = "----- Unsent message follows -----" ]
	then
		echo "----- Unsent message headers -----" >> $TMPFILE
		break
	fi
	echo $LINE >> $TMPFILE
done

##
## read the failed message header, then stop before message to preserve privacy
##
while read PART1 PART2
do
	if [ "$PART1" = "" -a "$PART2" = "" ]	## end of mesage header
	then
		echo "\n[message body removed for privacy]" >> $TMPFILE
		break
	fi
	if [ "$PART1" = "Subject:" ]		## delete Subject: line too
	then
		echo $PART1 "[removed for privacy]" >> $TMPFILE
	else
		echo $PART1 $PART2 >> $TMPFILE
	fi
done

/usr/lib/sendmail postmaster < $TMPFILE

rm $TMPFILE