proctut0 - Procmail Basics
This tutorial will discuss what procmail is and why it might be useful to you in controlling what comes into your mailbox.
Procmail, at its heart, is a mail processor; it PROCesses MAIL. Part of its process is to scan the mail and look for anything you've told it to look for, and then to deliver the mail where you tell it to be delivered. Simple.
Now the trick is to figure out how to tell it what to look for and what to do with it once it's found what it's looking for. A little terminology is appropriate here.
Procmail uses recipes to determine what to look for and what to do once it's found what it's looking for. A simple procmail recipe might look like this:
:0:
* ^From:.*joe@schmoe\.org
joe
This recipe looks for email messages from 'joe@schmoe.org' and delivers them to a file called joe. Once an email is delivered (i.e., written to a file), procmail stops processing[1] immediately[2] and all subsequent recipes are ignored.
If an email message does not match a recipe (e.g., in this case, if the message were not from 'joe@schmoe.org'), the email moves on to the next recipe until a matching recipe is found. If no matching recipes are found, the next recipe file is examined.
Procmail looks for recipes in the following locations[3] (and in this order):
/usr/local/etc/procmailrc (or /etc/procmailrc)
$HOME/.procmailrc
Once procmail finds one of the above files, it reads it for recipes. If the file does not exist, or none of the recipes match the email, procmail will read the next file until a matching recipe is found. If no matching recipes are found, the mail message is said to "drop off the end" and is delivered to the default mailbox for the recipient (e.g., /var/mail/scott).
Procmail is a powerful tool for scanning and redirecting incoming mail. Procmail uses recipes to determine what to look for and what to do with mail. Recipes are found in the /usr/local/etc/procmailrc and $HOME/.procmailrc files[3]; procmail searches each of these files in turn until a matching recipe is found. Once a matching recipe is found, procmail delivers the mail and processing immediately ceases[2] and subsequent recipes are skipped[1].
This is the first procmail tutorial in a series.
Anatomy of a Procmail Recipe, Part I
procmail(1), procmailrc(5), procmailex(5)
Scott Wiersdorf <scott@perlcode.org>
Copyright (c) 2003 Scott Wiersdorf. All rights reserved.
$Id: proctut0.pod,v 1.7 2003/09/17 13:16:07 deep Exp $