#!/bin/csh -fb # (The "-fb" might need to be changed to "-f" on some systems) # # Mailserver -- a simple MIME mailserver script. # Makes all files under a tree available for MIME-based retrieval. # By default, it sends them as the MIME type "application/octet-stream" # However, for a file named "x/y/foo.bar", you can specify a "right" # MIME content-type by putting it in the file "x/y/foo.bar.ct". # In a distributed sendmail environment, this script can be installed with lines # somewhat like the following two in /usr/lib/aliases: # mail-server: local-mail-server@some-single-machine # local-mail-server: "|/full/path/to/mailserver" # By default the program uses "mail-server" as its local return address. # and makes available all files under /usr/spool/ftp. # You might need or want to change the following parameters: set LOCALADDR=mail-server set ROOTDIR=/usr/spool/ftp set MAINTAINER=postmaster set METAMAILDIR=/usr/local/bin set LOGADDR=andrew@thumper.bellcore.com # If LOGADDR is the empty string, no logging is done. # # The real program begins here. setenv PATH ${METAMAILDIR}:${PATH} rehash set FromName="" set Subject="" # Generate temporary file name: if ( -x /bin/mktemp || -x /usr/bin/mktemp ) then set TmpFile="`mktemp /tmp/ms.$$.XXXXXXX`" || exit 1 else set TmpFile=/tmp/ms.$$ rm -rf $TmpFile endif onintr - end # set FOORAW=$< while ("$FOORAW" != "") set FOO=(`echo "$FOORAW" | tr "[" "x"`) set BAR=($FOO) set BARLC=(`echo "$FOO" | tr A-Z a-z`) if ("$BARLC[1]" == "from:") then if ("$FromName" == "") then set FromName = ("$BAR[2-]") endif else if ("$BARLC[1]" == "reply-to:") then set FromName = ("$BAR[2-]") else if ("$BARLC[1]" == "subject:") then set Subject = ("$BAR[2-]") endif set FOORAW=$< end # Now, stdin just has the body left, to do with as we please. # We choose to interpret the first line as the request, nothing more if ("$Subject" == "") then set Subject=$< endif if ("$FromName" == "") then set noglob cat > $TmpFile < $TmpFile < $TmpFile <> $TmpFile /usr/sbin/sendmail -t < $TmpFile rm $TmpFile exit 0 endif if (-e "${Subject}.ct" ) then set ct=`cat "${Subject}.ct"` else set ct="application/octet-stream" endif metasend -b -t "$FromName" -f "$Subject" -m "$ct" -s "Re: $Subject" if ($status != 0) then set noglob cat > $TmpFile <