ssaroff@newton.ncsa.uiuc.edu (Stephen Saroff) (02/22/91)
Is there an easy way to screen in coming mail? I would like to take all messages with a given subject, and automatically resend them to a mailing list. Any simple suggestions. Stephen Saroff (Thinking Machines) o o TMC Application Scientist for NCSA (_)_____o 405 N Matthews Ave ~~~~~~~~~(_____)~~~~~~~~~~~~~~~~~~~~ 5215 Beckman Institute oo oo The Bear who Swims (217) 244 5556 <tmc@ncsa.uiuc.edu> <saroff@think.com>
brunette@sjuphil.uucp (Glenn M. Brunette) (02/22/91)
In article <1991Feb21.164534.5413@ux1.cso.uiuc.edu> ssaroff@newton.ncsa.uiuc.edu (Stephen Saroff) writes: > >Is there an easy way to screen in coming mail? I would like to take all >messages with a given subject, and automatically resend them to a >mailing list. > >Any simple suggestions. > The ELM mailing system comes with a program called "filter" which will do exactly what you want. Its free and can be obtained via the mail-server at the dsinc archive. Glenn -- ******************************************************************************* Glenn Brunette, Academic Computing Network Consultant sssss ss jjjjjjj Addresses: ss j brunette@sjuphil.UUCP ss j u u brunette%sjuphil.sju.edu@RELAY.cs.net sssss j u u
jik@athena.mit.edu (Jonathan I. Kamens) (02/22/91)
If you use mh, you can write a script to use "pick" to pick out the messages that have the given subject, and forward them appropriately. If you don't use mh, then you can snarf one of the many mail-handling packages which have been posted to the net which allow you to do what you describe. The two packages which come to mind are mush, the Mail user's shell, which is available in volume 18 of the comp.sources.unix archives, or deliver, which is available in volume 20 of the comp.sources.unix archives. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710
weimer@garden.kodak.COM (Gary Weimer (588-0953)) (02/26/91)
In article <1991Feb21.164534.5413@ux1.cso.uiuc.edu>, ssaroff@newton.ncsa.uiuc.edu (Stephen Saroff) writes: |> Is there an easy way to screen in coming mail? I would like to take all |> messages with a given subject, and automatically resend them to a |> mailing list. I don't remember where I posted this last week, so I'll repost it here. This works in SunOS: =================== Start .forward file ============================ "|<path>/mailsort.csh <login id> ~/MAIL" ==================== End .forward file ============================= for debugging, you may wish to use: =================== Start .forward file ============================ <login id>,"|<path>/mailsort.csh <login id> ~/MAIL" ==================== End .forward file ============================= =================== Start mailsort.csh file ============================ #!/bin/csh -fb # login id of person using this script # environment vars take precidence over defaults if (!($?USER)) set USER=weimer # mail directory of person using this script # environment vars take precidence over defaults # NOTE: USER will not be set when prog called by mail daemon if (!($?MAILDIR)) then if (-e ~$USER/MAIL) then set MAILDIR=~$USER/MAIL else set MAILDIR=~$USER/mail endif endif ################################################################### # NOTE: mail message will be saved in the file $MSG, # the mail header only will be saved in the file $HEADER # the mail body only will be saved in the file $BODY ################################################################### # mail header lines to skip when saving message # $MSG will still have these, $HEADER will not set HDRSKIP='$1=="Received:" || $1=="id" || $1=="Message-Id:"' #set HDRSKIP="" # arguments take precidence over defaults and environmen vars # NOTE: this is not important part of code logic (you can skip it) set PARAMS=($*) if ($#PARAMS > 1) then set USER=$PARAMS[1] set MAILDIR=$PARAMS[2] set TMP=`echo $MAILDIR|awk '{print index($1,"//")}'` if ($TMP == 1) set MAILDIR=~$USER`echo $MAILDIR|awk '{print substr($1,2)}'` else if ("$PARAMS" != "") then set $USER=$PARAMS if (-e ~$USER/MAIL) then set MAILDIR=~$USER/MAIL else set MAILDIR=~$USER/mail endif endif ####################################################################### # # generic setup stuff # ####################################################################### # date in case I want it for file names set DATE = `date +"%y-%m-%d"` # awk script for separating mail header from mail body set PARSER=('{if (b) {print $0>>bf;next}};{if (NF==0) {b=1;next}};{if (""'$HDRSKIP'){next}};{print $0>>hf};END{print>>bf;print>>hf}') # files for msg, header, & body set MSG="/tmp/$USER.mail.$$" set HEADER=$MSG.head set BODY=$MSG.body /bin/rm -f $HEADER $BODY $MSG # just in case we've found a duplicate name... # our mail server uses /usr/spool/mail, other machines mount this in /var if (-e /usr/spool/mail) then set MAILBOX=/usr/spool/mail/$USER else set MAILBOX=/var/spool/mail/$USER endif # stdin is the mail message being sent, put it in $MSG cat > $MSG # separate header and body awk "$PARSER" hf=$HEADER bf=$BODY $MSG while (1) #we really only go through loop once # this allows us to use break instead of goto ####################################################################### # # BEGIN SORTING # ####################################################################### ####################################################################### # if you do not want a message to be sent to yourself, and you do not # want it to match any other conditions, 'break' after sending message-- # DO NOT 'exit'--temporary files will not get removed ####################################################################### # when concatinating to a mailbox, you should always add a blank line # to the end of what you are concatinating (hence all the 'echo ""'s # below) ####################################################################### # # extra stuff just for me :-) # # intro to prepend to forwarded msg's (stating this has been auto-forwarded) set AUTOHDR=$MAILDIR/auto.header # flag for who a copy was sent to (put at end my copy of files auto-forwarded) set COPYHDR=$MAILDIR/copy.header # # template # #set SUBJECT=`grep '^Subject:.<subj to check for>' $HEADER` #set TO=`grep '^To:.<id you expect forwarded mail from>' $HEADER` #set OTHER=`grep '<text to look for in body of msg>' $BODY` #if ("$<SUBJECT, TO, or OTHER>" != "") then # we found a match # # do any other calculations/parsing here # # # save to a file # (cat $<MSG, HEADER, and/or BODY>; echo "") >> $MAILDIR/<file> # # put in your own mailbox (as if we never did this script) # (cat $MSG; echo "") >> $MAILBOX # # forward to someone else # cat $<MSG, HEADER, and/or BODY> | /usr/ucb/Mail -s "<subject>" <userid> # # # run any programs, edit files, etc. that you want to here # break #endif # # Budtool Report # # simply write $MSG to appropriate file # set SUBJECT=`grep '^Subject:.Budtool.Report$' $HEADER` if ("$SUBJECT" != "") then set MACH=`grep '^rsh' $BODY | awk '{print $2; exit}'` (cat $MSG; echo "") >> $MAILDIR/backups/$MACH/$DATE break endif # # warehouse submissions -- cc: edj # set SUBJECT=`grep '^Subject:.wh.submission$' $HEADER` if ("$SUBJECT" != "") then (cat $AUTOHDR $HEADER $BODY) | /usr/ucb/Mail -s "wh submission" edj (cat $MSG $COPYHDR;echo "edj";echo "") >> $MAILBOX break endif # # warehouse requests -- cc: cwhite # set SUBJECT=`grep '^Subject:.*\<[rR]equest' $HEADER` set TO=`egrep '^To: wareh' $HEADER` if ("$SUBJECT" != "" && "$TO" != "") then (cat $AUTOHDR $HEADER $BODY) | /usr/ucb/Mail -s "wh request" cwhite (cat $MSG $COPYHDR;echo "cwhite";echo "") >> $MAILBOX break endif # # test (see if any of this works...) # #set SUBJECT=`grep '^Subject:.test$' $HEADER` #if ("$SUBJECT" != "" ) then # (cat $HEADER; echo "test successful"; echo "") >> $MAILBOX # break #endif ####################################################################### # # No matches--Put in mailbox # ####################################################################### cat $MSG >> $MAILBOX echo "" >> $MAILBOX break #don't repeat while loop end /bin/rm -f $HEADER $BODY $MSG exit ==================== End mailsort.csh file ============================= e-mail me if you have questions--I don't always have time to read this newsgroup. weimer@ssd.kodak.com ( Gary Weimer )
nelson@berlioz.nsc.com (Taed Nelson) (02/26/91)
In article <1991Feb25.210133.24256@ssd.kodak.com> weimer@ssd.kodak.com writes: > >I don't remember where I posted this last week, so I'll repost it here. >This works in SunOS: > >=================== Start .forward file ============================ >"|<path>/mailsort.csh <login id> ~/MAIL" >==================== End .forward file ============================= Careful. This will only work if there is no centralized mailserver, ie where the OS will create a mail daemon for you running AS YOU. Otherwise, it won't understand the meaning of "~" or any path variables. I know because I made this mistake over the weekend. I tested it on my local machine, and it worked fine, but it bounced all incoming mail that went through the central server.