#!/bin/bash # # Process Vitual Domain emails # This requires each user in the virtual domains to be entered below with a real domain # # 24-Aug-96 amo From John Levine, johnl@iecc.com, Trumansburg NY # 06-Jan-97 amo Modified for these Virtual Sites # # ------------------------------------------------------------------------------------------------ export PATH=/bin:/usr/bin:/usr/local/bin trap "rm -f /tmp/?$$" 0 # # where to put some temp files # cd /tmp # # 24-Aug-96 amo Use LOG instead of individual explicit path # # log all this stuff # NAM="procdomain" LOG="/var/log/procdomain.log" DAT="/tmp/procdomain.$$" # # Done/cleanup subroutine # Inputs: exit code..always zero here # all_done () { # # Echo stuff to a log file of what we just did # echo "`date` : -f=$from -h=$host user=$touser dom=$domain..d=$dom..new=$mailto.." >> $LOG # rm -f $DAT # remove temporary files # exit $1 # Done with procdomain, exiting w/ 0 } # # echo === $NAM : Incoming args= $* === >> $LOG exec >> $LOG 2>&1 # # Don't allow world r/w # touch $DAT chmod 640 $LOG $DAT # stash in a file cat > $DAT # set up the vars host= from= coa= auth= addfile= noresp= while :; do case "$1" in -f) from="$2" # the real sender shift 2 continue ;; -h) host="$2" shift 2 ;; *) to="$1" break ;; esac done # # extract the sender if not already given to us # [ -z "$from" ] && from=`(while read tag text do case "$tag" in From:) xfrom="$text" ;; Reply-[tT]o:) reply="$text" ;; esac done if [ -n "$reply" ]; then echo "$reply" elif [ -n "$xfrom" ]; then echo "$xfrom" else echo "nobody"; fi) < $DAT | sed -e 's/.*<\(.*\)>.*/\1/ y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ s/ *(.*) *//'` # # Extract/separate the username and domain name # touser=${to%@*} domain=`/usr/scripts/domain.pl $to` # # don't talk to ourselves # case "$from" in mailer-daemon@*) exit ;; # # de-anonymize an*@anon.penet.fi) from=`echo $from | sed 's/an/na/'` ;; # # chronic spammer # delores9@ix.net*) /usr/lib/sendmail abuse@netcom.com < $DAT ;; esac # # get subject # subject=`sed -n '/^Subject: */{ s///p q }' $DAT` # check for Re loop # should be more flexible for humans case "$subject" in "Re: Re: Re:"*) exit esac # -------------------------------- # # initialize # ProcDomainOK=0 file="" list="" LIST_SRV="" # ---------------------------------------------------------------------------------- # # These common email address is the same for all virtual domains ( maps to real me ) # # ----------------------------------------------------------------------------------- # case "$touser@$host" in # root@* ) mailto=root ;; PostMaster@*|postmaster@* ) mailto=postmaster ;; WebMaster@*|webmaster@* ) mailto=webmaster ;; # alvin@mail|postmaster@mail) mailto=alvin ;; # # # -------------------------------------------------------------------- # # Clients receive incoming email as user_1@Virt_1.com # # BUT, client POPemail account is UniqueRealUser_1@RealMachine.com # # -------------------------------------------------------------------- # # Allows only one /USERS/John: john@Virt_1.com == john@Virt_2.com # user_1@mail) mailto=UniqueReal_user_1 ;; user_2@mail) mailto=UniqueReal_user_2 ;; # # # Allows only different John: john@Virt_1.com != john@Virt_2.com # user_1@mail.Virt_1.com) mailto=UniqueRealUser_1 ;; user_2@mail.Virt_2.com) mailto=UniqueRealUser_2 ;; # esac # ----------------------------------------------------------------- # # Process Virt_3 Email stuff # if [ $domain = "Virt_3.org" ] ; then case "$touser@$host" in # # Mailing list and alias # Virt_3_staff@mail) mailto=Virt_3_staff ;; Virt_3_rsvp@mail) mailto=Virt_3_rsvp ;; # esac fi # -------------------------------- # # Shorten the virtual domain names # # /usr/local/majordomo/lists Normal Majordomo # lists.V1 majordomo for Virtual_Domain_1 # lists.V2 majordomo for Virtual_Domain_2 # # Watch out for: # test@mail.Virt_1.com vs # test@Virt_1.com # # -------------------------------- # case "$domain" in # Virt_1.com) dom=V1 ;; mail.Virt_1.com) dom=V1 ;; Virt_2.com) dom=V2 ;; mail.Virt_2.com) dom=V2 ;; Virt_3.org) dom=V3 ;; mail.Virt_3.org) dom=V3 ;; # esac # --------------------------------------------------------------------------- # # forward incoming email to virtual domain ( User_1@Virt_1.com ) # to someone else in a real domain ( UniqueReal_user@Real_Machine.com # if [ -n "$mailto" ] then # ProcDomainOK=1 # Processed virtual domain # smail -f "$from" $mailto < $DAT # fi ############################################################################### # # Process info requests by sending it thru Majordomo: info@ALL_Virtual_Domains.com # $dom uniquely identifies each Virtual Domain defined in /etc/aliases & for Majordomo # if [ $touser = "info" ] || \ [ $touser = "info-request" ] ; then # ProcDomainOK=1 # Processed virtual domain # # Just send the info file # elm -s "$subject" $domain.info < $DAT > /dev/null # fi # # Process majordomo requests sent to: majordomo@ALL_Virtual_Domains.com # $dom uniquely identifies each Virtual Domain defined in /etc/aliases & for Majordomo # if [ $touser = "majordomo" ] ; then # ProcDomainOK=1 # Processed virtual domain # # Only send along the body of the message, remove all the email headers # { # echo "From: ${respaddr:-majordomo@${to#*@}} (Majordomo Automated Response)" # formail -I "" < $DAT # } | smail -f "$from" majordomo.$domain # does not like subject line # fi # # Process majordomo requests sent to: test-requests@ALL_Virtual_Domains.com # $dom uniquely identifies each Virtual Domain defined in /etc/aliases & for Majordomo # if [ $touser = "test-request" ] || \ [ $touser = "test-digest-request" ] ; then # ProcDomainOK=1 # Processed virtual domain # { # Only send along the body of the message, remove all the email headers # formail -r < $DAT # } | elm -s "$subject" $touser.$dom > /dev/null # for Mail Sent status msg # fi # # Process incoming email to: test@ALL_Virtual_Domains.com # $dom uniquely identifies each Virtual Domain defined in /etc/aliases & for Majordomo # # Resend to everybody in distribution list # ---------------------------------------- # if [ $touser = "test" ] ; then # ProcDomainOK=1 # Processed virtual domain # # send the entire message in it's entirity # smail -f "$from" $touser.$dom < $DAT # fi # # Process incoming email to: test-archive@Virt_1.com ( to tests archiving ) # $dom uniquely identifies each Virtual Domain defined in /etc/aliases & for Majordomo # # Appends this email to: Archive.xxx/test/test.9612 # Create a copy of the email in DIGEST.xxx/test-digest/00? # --------------------------------------------------- # if [ $touser = "test-archive" ] || \ [ $touser = "test-digest" ] ; then # ProcDomainOK=1 # Processed virtual domain # smail -f "$from" $touser.$dom < $DAT # fi # ------------------------------------------------------- # # ERROR....hmmn, that's strange... Unknown Virtual Domain # # if [ ! $ProcDomainOK ] ; then # sed "s/^Subject:/Subject: procdomain_ERROR: Unknown user $to/" $DAT | /usr/lib/sendmail postmaster # fi # # all_done 0 # # done with procdomain