There is a very powerful mail processing tool called procmail which can be used to process messages before they are appended to your incoming email file. It uses the forwarding capabilities of the email system to forward the email to a specific program based on instructions contained in a file in your Unix home directory named .forward. Normally this file is used to call the vacation program or to forward your email to another account. In this case it's used to invoke the procmail program.
The "." as the first character of a Unix filename instructs Unix not to normally list it (somewhat hidden) so you need to use ls -a or ls -al command to see those hidden . files.
It is a simple text file which you can create or edit with your favorite text unix editor (pico, vi, emacs, etc).
To route mail through the procmail program, your .forward file should contain text identical to the next line except your_login_name should be changed to your own login/email name. All the other punctuation and syntax should be identical, including the double quotes at the start and end.
"|IFS=' ' && p=/usr/local/bin/procmail && test -f $p && exec $p -Yf- || exit 75 #your_login_name"
You can copy a skeleton version of the .forward file from the mail server (Ice) located in: /usr/skel/procmail.forward
Please note that the command described in the email autoresponse section: /usr/local/bin/vacation_setup will overwrite the .forward file and should not be used in conjunction with procmail. The vacation program can be used with procmail, however you will need to manually edit the .vacation.msg file. An example described below in the .procmailrc description indicates how to use vacation with procmail. It's probably a good idea to have a backup copy of the procmailrc file especially if you make it very complicated.
The procmail program is controlled by a different hidden file named .procmailrc which, if used, should also be in your home directory.
As I mentioned, procmail is a pretty powerful program and, in fact, entire SPAM filters have been written using procmail. Our mail goes through a much more sophisticated SPAM detection mechanism which tags suspect SPAM with it's own headers. We will merely use procmail to detect the presence of these particular headers.
You can copy a skeleton version of the procmail configuration file from the mail server (Ice)
located in: /usr/skel/procmailrc
Once these two files are in place, email messages will be routed through the procmail program. The reason for diverting suspected SPAM to a different mailbox instead of deleting it, is to protect against deleting false positives. You should periodically check and clear the contents of the SPAM email file.
You can find out more info about procmail by using the unix man command:
man procmail
man procmailrc
The directory defined by MAILDIR in the .procmailrc file needs to exist before procmail can be run. The directory is usually "mail" or "MAIL" and should located in your home directory.
My .procmailrc file looks like this:
Rember to change the "NAME=" line to reflect your login name"
# .procmailrc
# Please check if all the paths in PATH are reachable, remove the ones that are not.
PATH=$HOME/bin:/usr/bin:/usr/ucb:/bin:/usr/local/bin:.
NAME=your_login_name # Change to your own account.
MAILDIR=${HOME}/mail # Make sure it exists
DEFAULT=/var/mail/${NAME} # Default mail file
LOGFILE=${MAILDIR}/procmail.log # procmail logging file (to see what it did)
:0 # Anything from containing X-Spam-Level:
* ^X-Spam-Level:.*
SPAM # will go to $MAILDIR/SPAM
:0 Wc # Razor is a network SPAM detection database.
| razor-check # if the message checksum and identifier is contained
:0 Wa # in the razor database, it will go to SPAM
SPAM
#:0 # When I go on vacation, I uncomment these next two lines
#|/usr/bin/vacation ${NAME} # This does two things,
# # 1 - Vacation messages do not get sent in the case of suspected SPAM
# 2 - I am able to use the vacation program.
# The next few lines show simple examples of how to specifically
# filter based on contents of specific headers.
# procmailrc lines are processed in sequential order.
# They would also need to be uncommented in order to work.
#:0 # Anything from people at uunet
#* ^From.*@uunet
#uunetbox # will go to $MAILDIR/uunetbox
#
#:0 # Anything from Henry
#* ^From.*henry
#henries # will go to $MAILDIR/henries
#:0
#* ^Subject:.*viagra* # Subject contains viagra
#SPAM # goes to SPAM
#
# anything that passes through all the filters now gets delivered to your DEFAULT
# incoming email file or mailbox in our case: /var/mail/your_login_name.
## Anything that has not been delivered by now will go to $DEFAULT
# Note the :0: syntax, it instructs procmail to use the default file locking
# mechanism for writing to the $DEFAULT mailfile.
:0:
${DEFAULT}