#!/bin/sh # # this script appends some text to the end of an incoming message for # the mailing list, saves a copy in the archive, then sends the # message out to everyone on the mailing list. # # Usage: mailer.sh list-name # (e.g. mailer.sh rhl-test) # # List list-name will be archived in directory $ROOTDIR/list-name, and the # file ROOTDIR/list-name.list contains the member's email addresses # SENDMAIL=/usr/sbin/sendmail TEMP=/tmp/mailer.$$ TEMP2=/tmp/mailer2.$$ PERL=/u/strauss/apo/mailer/bin/mail2html ROOTDIR=/u/strauss/apo/mailer MACHINE=astro.princeton.edu OWNER=owner-apo35 REQUEST=apo35-request USERLIST1= USERLIST2= # first, copy the incoming message to the file $TEMP cat > $TEMP # # figure out who it's from # from=`sed -n -e '/^From: /{ s/From: // s/ *([^)]*)// s/[^>]*<\([^>]*\)>/\1/ p q }' $TEMP` user=`echo $from | sed -e 's/@.*//'` # # And see if we accept mail from there # allowed="?" for f in "$USERLIST1" "$USERLIST2"; do if [ "$f" != "" ]; then if grep -s "$user" $f; then allowed=1 fi fi done if [ "$allowed" = "?" -a \ "`echo $from | sed -n -e '/\.com*$/p' -e '/\.net$/p' -e '/\.co.[^.]*$/p'`" != "" ]; then allowed=0 fi # # Did we reject that user? # if [ "$allowed" = "0" ]; then cat > $TEMP2 < /' $TEMP >> $TEMP2 mail $REQUEST < $TEMP2 rm -f $TEMP $TEMP2 exit 1 fi # next, figure out the ID number of this message - it should be the integer # one larger than the current largest file number in the archive # directory. all files in the archive have names like "msg.23". cd $ROOTDIR/$1 n=`ls msg.*.html | sed -e 's/^msg\.\([0-9]*\)\.html/\1/g' | sort -n | tail -1` if [ X"$n" = X"" ]; then n=0 fi n=`echo $n + 1 | bc` # tack an extra bit on the end of the file, telling people about # the mailing list and about this message cat >> $TEMP < msg.$n.html # now, make a copy of the message, but change some of the mail-header # information so that errors don't cause floods, and so that # users of the "vacation" program won't reply to the group, either. cat > $TEMP2 <> $TEMP2 cat $TEMP2 | $SENDMAIL -f $OWNER $1-out /bin/rm -f $TEMP $TEMP2 exit 0