GNU/Linux Desktop Survival Guide
by Graham Williams |
|||||
Procmail Recipes |
REVIEW We now start specifying recipes to handle email. A recipe generally contains a pattern to identify the email messages to which the actions of the recipe are to be applied. Generally, the first recipe that matches an email will process that email and then terminate the procmail processing of that message.
For the especially cautious, or for when setting up procmail and testing it, you may want to keep a copy of every email that comes through. The first recipe might then be:
:0 c: .incoming.`date +%Y.%m`/ |
All recipes are introduced with the :0. This can be followed by flags to control how the recipe works. The c flag above indicates that the email message is to be processed further by this specific recipe, but also a copy is to be pushed through to the remainder of the recipes within the .procmailrc file. The final : indicates that while procmail is processing the email message with this recipe, the recipe should be locked (so that no other procmail can write to the specified file at the same time).
After introducing the recipe with the :0 line, the next line in the above example is the action to be performed. In this case a file name is specified, beginning with a full stop and calling on the operating system to provide a current year and month string (e.g. 2006.01).
We can specify exactly which emails we wish a recipe to apply to. We do this for a recipe which will forward email on to another user, as well as keeping a copy for ourselves:
:0 c * ^From.*abc.com ! abcmail@togaware.com |
With this recipe the recipe introduction uses the c flag to pass the email message on to following recipes as a carbon copy. Also, there is no trailing colon, so we are not requesting a lockfile for this recipe—in this case we don't need to use a lockfile because two instances of procmail will not interfere with each other when the action is to send the email on to someone else.
# DEBIAN :0: * ^Resent-Sender.*debian-devel-request@lists.debian.org lists/debian-devel :0: * ^Resent-Sender.*debian-user-request@lists.debian.org lists/debian-user |
The :0
begins a recipe. The following :
ensures the mail
file is locked. A line beginning with *
begins a condition. You
can have multiple conditions within a recipe. The condition
^Resent-Sender.*debian-devel-request@lists.debian.org
captures email sent to the debian-devel mailing list. This matches
messages that include
Resent-Sender: debian-devel-request@lists.debian.org
in their header. The final line of a recipe is the mailbox into
which procmail will send the mail.