Candidates should be able to implement client mail management software to filter, sort and monitor incoming user mail. This objective includes using software such as procmail on both server and client side.
Key files, terms and utilities include:
procmail |
.procmailrc |
References: McGough01 and the manual pages of
procmail and procmailrc.
Procmail is the default MDA (Mail Delivery Agent) for most
linux distributions. When delivering mail,
procmail first sets some environment
variables to default values, reads the mail message from
standard input, separates the body from the header and then
starts to look for a file called
$HOME/.procmailrc. According to the
processing recipes in this file, the mail message gets
delivered. If no .procmailrc file is
found, or processing of the rc file falls off the end,
procmail will store the mail in the default
system mailbox.
The rc file can contain a mixture of environment-variable
assignments (some of which have a special meaning to procmail)
and recipes. In their simplest appearance, the recipes are
simply one-line regular expressions that are searched for in
the header of the arriving mail. The first recipe that matches
is used to determine where the mail has to go (usually a file).
If processing falls off the end of the rc file, procmail will
deliver the mail to $DEFAULT.
By using multiple recipes, you can pre-sort your mail into several mailfolders. Bear in mind though that mail can arrive simultaneously in these mail folders (if several procmail programs happen to run at the same time, which is not unlikely if a lot of mail arrives). To make sure this does not result in mayhem, proper use of lock files is highly recommended.
Environment variable assignments and recipes can be freely
intermixed in the rcfile. If any environment variable has a
special meaning to procmail, it will be
used appropriately the moment it is parsed (i.e., you can
change the current directory whenever you want by specifying a
new MAILDIR, switch lockfiles
by specifying a new LOCKFILE,
change the umask at any time -- the possibilities are
endless).
A line starting with “:0” marks the beginning of a recipe. It has the following format:
:0 [flags] [ : [locallockfile] ] <zero or more conditions (one per line)> <exactly one action line>
Conditions start with a leading “*”, everything after that character is passed on to the internal egrep literally, except for leading and trailing whitespace. These regular expressions are completely compatible with the normal egrep extended regular expressions.
Conditions are anded; if there are no conditions the result will be true by default.
A simple .procmailrc file will look
something like this:
# Next two are needed if you invoke programs, such as # formail, sendmail, or egrep, from your procmailrc # SHELL=/bin/sh # PATH=/usr/bin:/bin # Put # before LOGFILE if you want no logging (not recommended) LOGFILE=.procmail.log # To insert a blank line between each message's log entry, # uncomment next two lines (this is helpful for debugging) # LOG=" # " # NOTE: Upon reading the next line, Procmail does a chdir to $MAILDIR MAILDIR=$HOME/Mail # Make sure this directory exists! :0: * ^Subject:.*test testing
The recipe consists of the following parts:
| Notation | Meaning |
|---|---|
:0 | Begin a recipe |
: | Use a lock file |
* | Begin a condition |
^Subject:.*test | Match lines in the message. |
testing | Store message in the given mailbox in case matching. |
To store mailing-list messages in a separate folder, use a recipe like this:
:0: * ^TO_procmail@informatik\.rwth-aachen\.de procmail
When you are subscribed to the procmail mailinglist, you will
receive messages that are sent to the list. The
^TO_ expression will match
any destination specification (To, Cc, Resent-To, etc.). The
string following the ^TO_
expression is used to match (the beginning of) an E-mail
address.
Procmail recipes are not case sensitive, so the above
example will also match
procmail@informatik.RWHT-Aachen.de.
If you need to match case, you can use the “D”
flag at the start of the recipe:
:0D: * ^Subject:.*ADV Potential.SPAM
This will only match if the “Subject:” header
contains the substring “ADV” in capitals. This
recipe will deliver this E-mail to the
Potential.SPAM folder, because,
allegedly, more respectable, unsolicited advertising has an
“ADV” marker in upper case on the subject line.
Because we are not 100% sure that the substring
“ADV” will always be spam, we store the
message in a spam folder. We can “store” the
message in /dev/null if we know that a
message will always be spam:
:0 * ^From:.*@cyberspam\.com /dev/null
This will delete all E-mail from anyone at cyberspam.com. Note that you should not use file locking in this case, hence the missing colon after “:0”.
For more options, please read the man pages of procmail or visit the procmail web-site.