Tke key knowledge areas are: procmail configuration files, tools and utilities. Usage of procmail on both server and client site. Partial list of used files and utilities:
.procmail |
/etc/procmailrc |
procmail |
| mbox and Maildir formats |
Procmail is a mail filtering utility and is used for preprocessing and sorting incoming mail. It can be used to sort out mail from mailinglists, filter spam, sent auto-replies. The configuration of procmail is based on a file placed in the user's homedirectory. Procmail is rarely run from the commandline (except for testing purposes) but it's an autonomous program which is normally invoked by a MTA (Mail Transport Agent like Sendmail or Postfix).
Procmail follows the following scheme for reading it's configuration:
/etc/procmailrc |
$HOME/.procmailrc |
A simple .procmailrc example:
SHELL=/bin/sh MAILDIR=$HOME/Mail LOGFILE=$HOME/Mail/procmail.log :0: * ^Subject: test testing
The first three lines are just common parameters, not procmail specific.
In this example mail with subject test is placed into the
subfolder testing.
The :0: falls apart in the first colon, the start of a new recipe,
the 0 is for historical reasons, just leave it there. The second
colon means to use locking. You have to use this when saving to a file. In this
case the mail is writting into the subfolder testing.
The * indicates the beginning of a condition. The condition itself
is a regular expression. This condition is matched against the headers of the mail.
The last line testing has nog special character, in this case, the
simplest form o delivery is shown, saving the mail to the subfolder testing.
This example was really simple. Probably the hardest part of procmail are the flags. These
flags are given after the 0. Some usefull flags:
HB, or BH match against both the headers and body
of the mailmessage. |
B match against the body of the mailmessage instead of the headers |
f modify the mailmessage and continue processing the modified message.
|
c clone, even when delivering a mailmessage, continue processing as
if the message was stil undeliverd. This makes it possible to do more than one thing
with a mailmessage |
Get A overview of all flags with procmail -h.
A little bit more complicated example used for soring out mailmessages sent from a
mailinglist called owner-info@listserv.com. In this example the mailmessage the
filtering is done by two conditions. First the mail must be from
owner-info@listserv.com and second, the subject must end with kernel
infoWhen these conditions are met, the message is saved in a folder called
maillist.linux
:0: * ^From owner-info@listserv\.com * ^Subject:.*kernel info maillist.linux
Here is an other example. In this case mail which meets the conditions is forwarded to a
secretary and saved in a specific follder of the destinated original user. Mail from
the domain microsoft.com with the subject ending with licenses
is forwarded to secretary. With the second rule the mail which meets the
two conditions is saved in the folder forwarded.secretary
:0c * ^From.*@microsoft\.com * ^Subject:.*licenses ! secretary :0: forwarded.secretary