Using Procmail to Filter Your Email on Panix |
|
If you ever need to disable procmail in a hurry
the shortcut to turn it off is to disable forwarding.
You can do this by running forward -d from the command line, or by running forward -e from the command line and adding a "#" to the beginning of the line that contains "procmail", or you can log into webmail, go to the Options page and select Mail Forwarding Options, and modify your forwarding instructions there. |
Procmail is invoked automatically when you run it from your forward
file.
NB: This is not a .forward file in your home
directory space.
It's a file on the mail server that you can modify
from webmail (Options->Mail/Forwarding Options) or from the shell
using the command "forward -e".
To invoke procmail, your forwarding file should contain this line,
without quotation marks:
| /usr/local/bin/procmail -t
We have created an installation and an update script that you can use if you want to use our default setup or need only minor modifications. If you are already familiar with procmail, you might want to set things up yourself. That's okay, but we have the following suggestions for those who take this route:
Note that our main spam-filtering resource is SpamAssassin, SpamAssassin, and it can be invoked directly from webmail, so you don't need to use Procmail for this purpose, although you might choose to do so.
If you're already running Procmail but not SpamAssassin, and you'd
like to run SpamAssassin from Procmail, this line will do it:
INCLUDERC=/net/local/filters/rc.spamassassin
Make sure that you put that line after any rules that whitelist
addresses. If you run vacation from
procmail, you probably want to run SpamAssassin first, so you don't
send your vacation reply to spammers.
If you're familiar with procmail and want to set it up on your own, that's fine, but we recommend that you not set DEFAULT or ORGMAIL unless you're sure you know how to set them for the way you want your mail handled at Panix.
Old filter sets
In the past, we have offered some lists of sites or IPs that were known to generate spam. Those lists are still available, but they are deprecated and are no longer being updated. For filtering, we recommend SpamAssassin (either webmail-based or procmail-based), and for more the aggressive approach of bouncing mail at the server (so it's not delivered to your account at all), we suggest the Advanced Anti-Spam Options available from the Options page of webmail.
One of the most important things that happens in your .procmailrc file is the setting of your TRASH variable. If you tell the install script that you want to delete messages unread, this will be set to /dev/null, and any messages sent there are not recoverable. You have to weigh the risk of losing mail you need against the risk of having a trash folder that grows so large it interferes with your quota. (The default setting for TRASH is .maildir/.Trash/. If you use that, messages will be deleted from the folder when they've been there one week.)
However, you can modify your .procmailrc file so that TRASH is set differently for different rules. The setup script lets you save virus-laden mail and suspected spam to different folders, although, by default, both are set to .maildir/.Trash/, the Trash folder you see from webmail. You'll find more detailed information on setting variables below.
The .procmail directory is, by default, where Panix users' keep their procmail logs and any of their own rule sets. If you use the default setup, your procmail logs will be rotated to prevent them from growing too large and exhausting your disk quota.
The line that lets you run spamassassin from procmail is this:
INCLUDERC=/net/local/filters/rc.spamassassin
As noted, you can run SpamAssassin either from webmail or
from procmail. It's not a good idea to do both because that wastes
system resources and, should you ever need to check, makes it harder
to figure out what's happening to your mail.
The line that lets you run virus checking from procmail is this:
INCLUDERC=/net/local/filters/rc.viruscheck
You can also run virus checking from webmail or from
procmail. The virus-checking option is located on the Options page
of webmail.
#Set on when debugging VERBOSE=off #The directory where your mail folders will be stored. MAILDIR=$HOME/.maildir #Directory for storing the procmail log and the rc files PMDIR=$HOME/.procmail # The log of procmail actions LOGFILE=$PMDIR/log # SPAMTRASH is used to tell SpamAssassin where to deposit the spam SPAMTRASH=$MAILDIR/.Trash/ # VIRUSTRASH is used to tell the virus filter where to deposit the virus mail VIRUSTRASH=$MAILDIR/.Trash/ # Virus check comes before all other filtering, since virus mail could be # from someone you know TRASH=$VIRUSTRASH INCLUDERC=/net/local/filters/rc.viruscheck # Your own filtering rules INCLUDERC=$PMDIR/rc.folders # Spam filtering TRASH=$SPAMTRASH INCLUDERC=/net/local/filters/rc.spamassassin
Lines beginning with # are called "comments". They're intended for people, not for computers.
The words in upper-case are variables. You'll notice that variable
names to the righ of an equal sign are preceded by $. This
tells the system to look at the value of that variable. For example,
you see the setting
PMDIR=$HOME/.procmail
which sets your "procmail directory" to the value of
.procmail in your home directory ($HOME). Then
you can set your log file this way:
LOGFILE=$PMDIR/log
using the value of $PMDIR that you have set.
Lines beginning INCLUDERC= set a special variable that tells procmail to process the specified file.
If you want to save your mail to folders that are visible from webmail or IMAP, you should set MAILDIR to $HOME/.maildir, like this:
MAILDIR=$HOME/.maildirIf you want to save your mail to the mail directory in your home directory space (which is the default for Pine), you can specify
MAILDIR=$HOME/mailYou can override your MAILDIR setting in any recipe. For instance, if you want most of your mail saved to your "mail" directory by your spam to your webmail/IMAP Trash folder, you can set MAILDIR=$HOME/mail and then specify TRASH=.maildir/.Trash separately. Or you might want most of your mail saved to $HOME/.maildir (so that's your MAILDIR setting), but not mail from one particular address, which you want to save to a special file. We'll give more examples below. It's often useful to make your own filtering rules, to filter spam or just to sort mail into different folders. The setup script provides a place for them:
You need to bear in mind that rules will be processed in the order in which they occur. So if you want to save mail with "purple" in the subject line to a special folder whether or not SpamAssassin thinks that message is spam, you have to make sure your rule about "purple" precedes the SpamAssassin rule. On the other hand, if you want to filter out the spam first and then save your "purple" mail to a special folder, you have to make sure the SpamAssassin rule comes before the "purple" rule.
If you look at your .procmailrc file, you'll see that we put the INCLUDERC line for your own procmail recipes before the INCLUDERC line for SpamAssassin. That's to give you a place, all prepared, for you to use for whitelisting addresses. (The webmail version of SpamAssassin has web-based control of SpamAssassin's own whitelisting facility, and you can modify your .spamassassin/user_prefs file to include whitelisted addresses as well, but many people prefer the flexibility of procmail rules for this purpose.)
Typically, an entry looks something like this:
From user@example.com Thu Sep 1 12:45:02 2005 Subject: Lunch tomorrow? Folder: /net/staff/home/youraccnt/.maildir/new/1125593105.7251_1.panix1.pan 1044By looking at the log, you can see whether a message that you're looking for got to your account.
You may have noticed this line in the .procmailr file:
VERBOSE=offShould you ever need to figure out exactly what is happning to a message, you can change that setting to
VERBOSE=onand bounce the message to yourself. (If you do that, you should set the message aside first and edit out any of the extra headers added by your own mail filtering, or they'll interfere with the processing. You should also modify the message-ID so it isn't exactly like the original. You can easily do this by adding "X" or "was" to the actual ID (inside the angle brackets), so that something like this:
Message-ID: <20051006173459.GA11872@panix.com>becomes
Message-ID: <was-20051006173459.GA11872@panix.com>
If you turn on verbose logging, you must not forget to turn it off as soon as you've finished testing. Verbose logging can be very verbose, and takes up a great deal of space.
Folders that are accessible from webmail are in a format called
Maildir++. (Yes, it's confusing. There's the procmail
variable MAILDIR, there's the Maildir++ folder type, and there's
your .maildir directory, or, more accurately, the symbolic
link in your home directory to your mail on the server.)
The folders that you may have used with Elm, Mutt, Pine, and certain
other Unix shell mail readers are in mbox format.
Each folder in mbox format is a single file. Messages are separated internally by the string "From " at the beginning of a line. Each Maildir++ folder is actually a directory, or, more accurately, a directory subtree. Each message is a separate file. You have to be careful to specify the right type of folder, and to make sure you get the path the way you want.
:0:
* ^Subject:.*\<testing
testing
You will note that matching upper and lower case isn't important. This recipe will not match mail with "contesting" or "protesting" in the subject line because of the \<, which marks the beginning of a word boundary.
If you have MAILDIR set to $HOME/.maildir, you can still save mail to $HOME/mail/testing this way:
:0:
* ^Subject:.*\<testing
$HOME/mail/testing
Note that there is a colon after the zero on the first line of each of these recipes. That tells procmail to lock the folder so that it won't become corrupted if more than one message arrives at once.
Note that the folder name begins with a dot (which is necessary so that the folder is visible to the IMAP server) and ends with a slash (which is necessary to tell procmail that it's saving to the maildir++ format).
If you have MAILDIR set to $HOME/mail, you can still save mail to $HOME/.maildir/.testing this way:
:0
* ^Subject:.*\<testing
$HOME/.maildir/.testing/
Again, note that the foldername has to begin with a dot and end with a slash.
Note that there is no colon after the zero on the first line of each of these recipes. As each message is a distinct file, there is no need for a lock.
You will note that matching upper and lower case isn't important. This recipe will not match mail with "contesting" or "protesting" in the subject line because of the \<, which marks the beginning of a word boundary.
Procmail is a very powerful program with a lot of features. The Panix help desk can provide support only for some basic features. The Panix user community includes a number of extremely knowledgable procmail users who are most generous with their expertise. You can generally find them in the panix.questions newsgroup.
Meantime, here is a list of resources to help you get familiar with procmail, from basic tutorial-level to advanced tricks.
© Copyright 2003,2005 Public Access Networks Corporation
[ Panix Home ] [ Help System Index ] [ Email and Spam Help ] [ Top of This Page ]