tkevans@fallst.UUCP (Tim Evans) (06/27/90)
For reasons I've never known, the vendor who installed our UNIX system installed a non-standard mailer, which, among other things, mangles the headers of third-party UUCP mail that passes through our system. Not a very nice thing to do. Unfortunately, I'm not a headers wizard--all I know is that people complain about my system mangling their mail. I don't even know what exactly is going wrong. :-( Since I can't get the vendor to fix this (their contract doesn't require them to support third party mail), I thought maybe someone out there could help. Remote mail is handled in this system by two shell scripts. The first replaces the standard 4.2BSD 'rmail'. This delivers incoming mail which arrives via UUCP. Here is the script: START OF 'rmail' SCRIPT : echo "`date`: $*" >>/usr/adm/rmail.log cd /tmp; umask 0066; E=0 LOCAL="`uuname -l`" sed "1s/^From \\([^ ][^ ]*\\) \\(.*\\) remote from \\([^ ][^ ]*\).*/From \\3!\\1 ${LOCAL}.UUCP/" >/tmp/rmail.$$ SUBJ=`sed -n "1,/^Subject/s/^Subject:* \\(.*\\)$/\\1/p" </tmp/rmail.$$` if /usr/bin/mail -R "$*" -s "$SUBJ" </tmp/rmail.$$ >/tmp/rmail.e.$$ 2>&1 ; then : ; else if test -s /tmp/rmail.e.$$ ; then LOCAL=`uuname -l` SENDER=`sed -n "1s/^From \\([^ ][^ ]*\\) .*$/\\1/p" </tmp/rmail.$$` ( echo "Returned mail from rmail on \"${LOCAL}\"." echo "Reason:" cat /tmp/rmail.e.$$ echo "" cat /tmp/rmail.$$ ) | if /usr/bin/mail ${SENDER} -s "Undelivered mail." ; then : ; else E=1 ; fi fi; fi rm -f /tmp/rmail.$$ /tmp/rmail.e.$$ exit $E This shell command file ("rmail") is designed to accept mail from UUX and submit it to NetMail. It implements the UUCP convention of moving the "sender" part of "remote from sender" to the beginning of the "From" name. That is, from: From pearson Fri Jan 10 00:29:36 1986 remote from cdstar it gets: cdstar!pearson and creates a new first line: From cdstar!pearson local.UUCP (where "local" is the return from uuname -l. The NetMail mail command is then called with a flag of -R. For those familiar with standard Unix mail, in NetMail, rmail is broken out of the mail command proper so that mail arriving from sources other than uucp can be submitted. To handle mail from other sources, all a command file has to do is prepare a new first line beginning with "From", then the sender's (non-local, far) network address, then a far-net node idenitfication, then pass the letter to mail with the -R flag. Use the uucp version above as a model. The Received-by line prepared with by the -R flag will contain the name of the user executing the mail -R command, so create a user to run the (non-local) network's local commands (as is done for uucp). END OF 'rmail' SCRIPT Outgoing mail with remote addresses, inlcuding, of course, the output of the 'rmail' script for third party mail, is passed to another script the vendor calls 'nmremote'. Here is this script: START of 'nmremote' SCRIPT : # @(#) "nmremote" NetMail UUCP script # called with # nmremote host1!host2!name host3!name ... # with message body coming from standard input ############################# echo "`date`: $*" >>/usr/adm/nmfarmail.log umask 0066 MAILFILE=/tmp/nmfarmail.$$ UUNAMEFILE=/tmp/nmfarmailu.$$ # Pathname of file for "@" lookups # If you want to disable "@" facility, dont define this variable # uses modified output of 'pathalias' PATHSFILE=/usr/lib/uucp/paths.netmail # Delete temporary files if an error trap 'rm -f $MAILFILE $UUNAMEFILE; exit' 1 2 3 15 # Get my host name LOCAL=`uuname -l` # Copy message to /tmp/nmfarmail.$$ adding "remote from hostname" line sed -e "1s/$/ remote from ${LOCAL}/" \ -e "1a\\ To: THE_REMOTE_NAME\\ " > $MAILFILE # Remember valid uucp destinations uuname > $UUNAMEFILE #echo "$LOCAL" >> $UUNAMEFILE # For each argument for ARG do # Copy ARG to a new variable CURRENT="$ARG" # If there's an '@', separate part before and after if [ `echo "$CURRENT" | fgrep "@"` ] then if [ "$PATHSFILE" ] then # Do the lookup ATPART=`echo "$CURRENT" | sed -e "s/[^@]*@//"` AWKARG="{if (\$1 == \"$ATPART\") {print \$2; exit(0)}}" PATHLIST=`awk "$AWKARG" $PATHSFILE` else # No file, mark as not found PATHLIST="" fi # Check that '@' refers to a valid host path if [ "$PATHLIST" ] then # Recreate $CURRENT CURRENT=`echo "$CURRENT" | sed -e "s/@.*//"` # CURRENT="$PATHSHOST"!"$PATHLIST"!"$CURRENT" CURRENT="$PATHLIST"!"$CURRENT" else # Make it a bad value so won't find it later CURRENT=UNKNOWNHOST!GARBAGE fi fi # Separate part before first ! and after USERNAME=`echo "$CURRENT" | sed -e "s/[^!]*!//"` HOSTNAME=`echo "$CURRENT" | sed -e "s/!.*//"` # Check if it's a local message or a valid hostname if [ "$HOSTNAME" = "$LOCAL" ] then sed "2s/THE_REMOTE_NAME/$ARG/" < $MAILFILE | mail ${USERNAME} elif [ `fgrep -x "$HOSTNAME" < $UUNAMEFILE` ] then # It's valid, substitute in destination argument and send sed "2s/THE_REMOTE_NAME/$ARG/" < $MAILFILE | uux - "${HOSTNAME}!rmail (${USERNAME})" else # Invalid, return message AUTHOR=`sed -n "1s/^From \\([^ ][^ ]*\\) .*$/\\1/p" < $MAILFILE` ( echo "Returned mail from NetMail farmailer on \"${LOCAL}\"." echo "Reason: remote address \"$CURRENT\" not recognized." echo "" sed "2s/THE_REMOTE_NAME/$ARG/" < $MAILFILE ) | /usr/bin/mail $AUTHOR - -s "Returned mail." fi done rm -f $MAILFILE $UUNAMEFILE exit -- UUCP: {rutgers|ames|uunet}!mimsy!woodb!fallst!tkevans INTERNET: tkevans%fallst@wb3ffv.ampr.org Tim Evans 2201 Brookhaven Ct, Fallston, MD 21047