How do I automatically filter E-Mail?
How do I automatically filter E-Mail?
I want to send all my genlist mail to one folder, and all my backup
messages to another. I also receive lab results via e-mail can I
do anything with them?
There is a utility called 'deliver' that can process incoming e-mail
and 'act' on the mail headers e.g To: Subject: etc. This How To gives
a brief overview of some of the uses.
(Note: The examples below refer to the the user 'tom' make sure you
change all occurrences of 'tom' to the login account you are wanting to
filter.)
If you have never used deliver before (most of you won't have),
- Check it's installed - type
deliverat the # or $ prompt, if you receive a message 'delivernot found' then pick up a copy from the robot (asdeliver.tgz) or from www.sco.com/skunkware. - Create a file in the home directory of the account that receives the
mail called
.forwardand add into it:
"|/usr/local/bin/deliver tom"
This tells the mailer to pass all mail messages through the program deliver. This utility using basic Unix shell scripting to handle all the work. It may seem complicated but it's not. - Now create the file
.deliverin the home directory, (cut the text out of here and paste directly in).
#----- Cut Here ------ #!/bin/sh PATH=/usr/local/bin:$PATH ; export PATH ; User=$1 TO=`header -f To -f CC -f Cc -f Apparently-To $HEADER` SU=`header -f Subject $HEADER` # OK Look at the Subject and sent it there. e.g. Backup/Pass/Fail case "$SU" in *BACKUP*) cat $HEADER $BODY | deliver -nb Mail/backup ; echo DROP ; exit ;; esac # Look at the To header and send it the appropriate mail box case "$TO" in *general*) cat $HEADER $BODY | deliver -nb Mail/general ; echo DROP ;; *) echo $User ;; esac # ----- Cut Here ----
The above options look for 'Subject: BACKUP' and puts all the results into a folder called '
backup' and any messages
to 'general' (all genlist
mail) will be filtered to the folder 'general'.
Taking it one step further, you receive mail with the subject 'Lab-Results' from one of the labs - yes you can use the same script to automatically add to a record card. As there is no 'standard' for receiving mail (yet) you will have to 'tweak' the script to handle the labs you use.
Add onto the above .deliver script
.. case "$SU" in
.. *BACKUP*) cat $HEADER $BODY | deliver -nb Mail/backup ; echo DROP ; exit ;;
*Lab-Results*) Client=`grep "^Ref No " $BODY |head -1| awk '{ print $4}'`
/usr/local/bin/vet -p attach $BODY $Client Idexx.$$ ;;
.. esac
This line will catch any mail addressed to 'Lab-Results', it will look for a line starting 'Ref No' and use the 4th field as the animal number. This will be attached to the card automatically.
(Note: vet -p attach appeared with version 2.191 of Premvet 5).
Yes until there is some standard as to identifying the animal the results refer too there will have to be that cryptic 'grep .... ' part to isolate the animal. Don't worry, if you are wanting to implement this then forward a sample set of results to support and they will send back the cryptic bit.