Deflexion.com
blog >>
Join the conversation >>
|
PROCMAIL
QUICK START
|
Copyright © Nancy McGough
& Infinite Ink
Originally published in 1994 as part of the Filtering Mail FAQ
Last modified
27-Nov-2007
“... Quick Start at Infinite Ink, one of the best primers to a complex program I've ever seen.” |
-- Kai Schätzl, 2004 May 16, Procmail list |
Procmail is free/libre open-source software that is both a mail processor and a mail delivery agent (MDA). It can be used by either a system administrator or a user to automatically process and deliver incoming mail messages. It can also be used to re-process and re-deliver messages that are already in a mailbox.
This Procmail tutorial is aimed at regular users, not system administrators. In order to use these instructions, you need:
In addition to understanding Internet mail flow, your mail messages must be delivered to a system that:
.forward
file to set procmail as your LDA,
or
.maildelivery
; with getmail,
use .getmailrc
; and with fetchmail,
use .fetchmailrc
.
If your system satisfies 4a or 4c, make sure that you skip Steps 8 & 9 below, that is, do not set up a .forward file.
|
||
If you are looking for a provider that has procmail installed, see my list of Free or Reasonably-Priced IMAP Service Providers — most of the providers who give full Unix shell access also let their users write and manage their own procmail recipes. |
Note about the ordering of these terms: The terms listed earlier are used in the definitions of later terms.
pmlog
for the Procmail log file, PMRE for Procmail
regular expression (defined below), and PMDIR
for the variable
that points to the directory that holds your Procmail-related files.
Note that there are others who use this abbreviation, for example, Paul
Chvostek's Procmail Log Watch awk script is called pmlw
and Jari Aalto's Procmail Documentation and Procmail Library are located
at pm-doc.sf.net and pm-lib.sf.net.Metacharacter or Metaphrase |
Meaning in a Procmail Regular Expression |
. |
any character other than newline (i.e., other than Line Feed or LF or ASCII character 10) |
( string) |
treat string as a single item |
* |
zero or more of preceding item |
? |
zero or one of preceding item |
+ |
one or more of preceding item |
^ |
newline; usually used to match beginning of line;
Note: As discussed in Re:
procmail help! $MATCH grabs newline too, the meaning of the
^ metacharacter is different in Procmail than
in most other RE tools. |
$ |
newline; usually used to match end of line; Note: As
discussed in Re:
procmail help! $MATCH grabs newline too, the meaning of the
$ metacharacter is different in Procmail than
in most other RE tools. |
[ characterList] |
any single character in characterList |
[^ characterList] |
any single character NOT in characterList |
\< \> |
each of \< and \> is a metaphrase
for a "non-word character"; details are in the
definition of word & Matching a
Word below, and in Jari Aalto's Procmail
and egrep differences |
| |
OR; ORing in Procmail is discussed below |
() |
() is the null item and is always a match; it is
used to make a recipe condition more readable, to escape a leading
backslash (\ ), or to escape the special meaning of
other metacharacters or metaphrases. For examples,
see this
discussion of ()< and this
discussion of ()\/. Note that it is more common to escape
a metacharacter with a backslash, which is discussed
in the next item. |
\ metacharacter |
Escape the special meaning of metacharacter and treat
it as the literal character that it is; for example
\. means the dot character rather
than backslash followed by any character and
\* means the asterisk character
rather than zero or more backslashes. Note: The
less-than character (< ) needs to be escaped differently.
Also see David W. Tamkin's 2004-April-24 message about leading
backslash problem (was persistent lock files). Tip: Another
way to escape a metacharacter is to put it in a [characterList] ,
e.g., you can use either \. or [.] to
mean a literal dot (. ) in a PMRE. Example:
In Setting Keywords or Labels below, there
is a recipe condition that contains a literal $ character. |
\/ |
extraction operator (discussed below) |
\ newline |
If the last two characters on a line are a backslash (\ )
followed by newline, this is a “continuation backslash”
and it tells Procmail to continue the current line with the text
on the next line and ignore these characters: backslash (\ ),
newline, white space (spaces, tabs, and/or newlines). |
|
||
|
|
-
letters, digits, and underscores -
and is bounded on the
left by the beginning of a line or non-word character and on the right
by the end of a line or non-word character. For example, in the line
Subject: testing procmailthe substrings Subject, testing, and procmail are each words and the substrings Subject:, mail, and test are not words. The diagram below shows the relationship between words and substrings, namely: Every word is a substring but not every substring is a word.
+----------------+ | +---------+ | | | words | | | +---------+ | | substrings | +----------------+Since you need to look at the boundaries of a string to determine whether it is a word, the term word only makes sense when you are talking about a substring in the context of a larger string. For more information, see the discussion about matching the word “test” in Understanding and Refining Your Procmail Recipes below.
cd cd ~ cd $HOME cd ${HOME}Note: Do not use
~
in a procmailrc file; use $HOME
or ${HOME}
instead.~
With procmail you can organize your environment variables, recipes,
mailboxes, and directories however you like. Only the .procmailrc
file, which I discuss below in Step by Step Through Setting
Up and Testing Procmail, is required to have this name and to reside
in your home directory. This freedom is part of what gives procmail its
power but it can lead to chaos if you do not have a strategy for organizing
and naming your procmail-related environment variables, files, and directories.
Everything should be as simple as possible but no simpler. |
-- Albert Einstein as quoted and discussed in
the |
The first strategy that I recommend and try to follow in this article is simplicity. For example, I recommend that you use the Procmail defaults whenever possible and do not set unnecessary environment variables in your procmailrc file(s). For more about this, including problems caused by not using the defaults, see the Warnings () notes in Step 4 below.
A key to good programming is modularization. This, along with simplicity, will help to make your Procmail configuration portable and will make it easy to plug in, unplug, or reorder recipes. Here are examples of recipe modules you might want to use:
rc.testing
rc.subscriptions
(aka rc.sbe
or rc.bulk
or rc.blue
)rc.log
rc.forward
rc.rmdupes
rc.munge-windows-1252
rc.munge.newsgroups
,
which I discuss on my main Pine page in this
sectionrc.autoreply
rc.vacation
rc.green
used, along with a greenlist (AKA whitelist or accept
list or allow list or goodguy list or
trusted senders), to do Reverse
Spam Filteringrc.greenlister
uses an incoming message to trigger
an update to the greenlist; for details see Reverse
Spam Filtering: Winning Without Fightingrc.quarantine
(aka rc.virus
or rc.violet
)
see Snagging Viruses belowrc.spamassassin
see Using SpamAssassin
belowlistname_id.rc
, which I discuss in Generic
SBE Sorting below.inc
(include) files, which
are here
& here,
and the .rc
and other files in his
procmail directoryvsnag.genvars.rc
,
which is part of Dallman's Vsnag
package and about which Dallman said “the
genvars contents are meant for, and I'm fine with their use for, satisfying
your general private procmail needs. Ditto public, if that means a server
running procmail for the good of its users, including commercially,
so long as I don't lose credit for what I've offered.” In the Step-By-Step section below, I walk you through
creating the first two recipe modules and then, after testing, I show
you how to unplug rc.testing. I discuss rc.quarantine
and
rc.spamassassin
in the Advanced Recipes
section.
The rc in procmailrc and in my recipe module names is a Unix naming convention that stands for either runtime configuration, runlevel change, or run commands (take your pick!). Thanks to Richard Smith, the maintainer of geekrave.org, for telling me he thinks of rc as runtime configuration; Elmar Hinz for telling me he thinks of it as runlevel change; and Imperial College for FOLDOC, the Free On-Line Dictionary Of Computing, for its definition and history of rc. |
Using consistent naming and formatting styles will help you keep your directories, files, and mailboxes organized. Here are the styles that I use:
What | My Naming & Formatting Style | |
directory | initial upper-case letter | |
file | all lower case | |
procmail recipe module | begins with rc. |
|
unplugged command in an rc file | begins with ## |
|
comment (that is not an unplugged command) in an rc file | begins with # |
|
environment variable | all upper case; also see the 2005-Jan-20 message Re: Variable names by Ruud H.G. van Tol | |
symbolic link to a file | begins with L. (for an example, see Tips for Managing Your Procmail Files below) | |
symbolic link to a directory | begins with LD. | |
mailbox (*) | does not contain forward slash (/ ), dot (. ),
backslash (\ ), hash (# ), colon (: ),
asterisk
(* ), percent (% ), quotes, apostrophes,
parentheses, brackets, or braces; is not the string inbox
or mbox or mail.txt
or inbox.mtx or default
or Mailbox
or any combination of upper and lower case letters of these strings.
Also, because of this
story, you may want to avoid using core as a
mailbox name. (* Also see the
Notes About Mailbox Names below.) |
|
incoming mailbox | begins with -- or IN- (I use one
of these prefixes so that all my incoming mailboxes are grouped together
when they they are sorted by name.)
|
|
incoming “Solicited Bulk Email” (SBE) mailbox | begins with --s- or IN-S- (you could
also think of the S as standing for subscription
or shared) |
|
archived SBE mailbox | begins with == or zz- or S-
and ends with -YYYY-MM-DD (the date of the latest message
in the box) |
|
special mailbox such as SENT , DRAFTS ,
and TRASH |
Some email clients and IMAP servers do not let users change the
names of special mailboxes but if it's possible, I like to use all
upper case for these so they are more noticeable. I also prefer to
use the name SENT-FCC (FCC = “Folder Carbon Copy”)
for my sent mailbox to distinguish it from SENT-BCC ,
which is where I deliver (via procmail) messages that I Bcc
to myself. |
|
personal special mailbox | begins with plus (+ ), dash (- ), equals
(= ), or a number so that it is listed near the top when
all mailboxes are sorted by name using an ASCII
sort. For example, I use 2Reply for messages that I want
to reply to and 2Web for messages that contain information
that I'd like to incorporate into my web site. |
|
“catch-all” mailbox | contains either the string catchall or dregs
or fallthrough or dropthrough or wildcard
or yellow or red (this is where messages
that are not delivered to one of my virus, magenta, blue, green, or
lime mailboxes are delivered; for more about catch-all mailboxes and
my general email strategy, see Reverse
Spam Filtering: Winning Without Fighting) |
|
mailbox when I care about the mailbox format | ends with a meaningful extension, for example .unix
for Unix mbox format or.cmbx for c-client MBX format.
(Tip: Do not use the extension .mbx
because different mail clients use it to mean different mailbox formats
and thus it is ambiguous. Also some viruses go after files
with the .mbx extension.) |
* | Notes About Mailbox Names | |
Here are more details about my strategy for choosing mailbox names.
These notes are in addition to the comments in the starred
item (*) above.
|
Request: I'm revising my mailbox
naming style and I'd like to learn about names that other people use,
especially any mailbox-naming scheme that is in common use. I'm thinking
about changing the prefix of my incoming mailbox names from IN-
to something that will sort above all alphabetic characters in an ASCII
sort. I'm leaning towards prefixing these box names with a dash (-
),
so, for example, incoming procmail mailing-list messages would be put
in --procmail
. And then I'd put the archive of that mailbox
in zz-procmail-YYYY-MM-DD
or ==procmail-YYYY-MM-DD
because the leading zz-
or ==
will make it sort
below my incoming mailboxes. I realize that these are kind of odd-looking
names so I'm interested to hear what ideas other people have — please
let me know what you think and
if you have suggestions.
Note 1: Someone emailed me and mentioned that if
a mailbox name starts with a dash, it is a pain to manipulate from a Unix
shell. That is true, but it provides a bit of security if a lamer
breaks into your account and tries to read your mailboxes using shell
commands such as more
or less
or pine
-f mailboxName
Note 2: I'm now using this naming scheme and so far I haven't had problems with Procmail or with any mail client or IMAP server that I've used. For example, here are mailbox names that could be used with my reverse-spam-filtering system:
--magenta --violet --blue --green --limegreen --yellow --red ==archive1 ==archive2 |
To force my most important incoming mailboxes to the top of an ASCII sort, I prefix each mailbox name with an appropriate number of dashes. For example:
-------green ------limegreen -----yellow ----blue ---red --violet -magenta ==archive1 ==archive2 |
I actually use a modified version of this and don't really have a mailbox name that begins with seven dashes! If you are interested in why I name my incoming mailboxes after the colors of the rainbow, see Reverse Spam Filtering: Winning Without Fighting.
I recommend that you order Procmail flags using the style that Jari Aalto suggests on his Procmail Tips page in the section called The order of the flags. I use this style throughout this page, for example in the SpamAssassin recipes below.
A lot of people are learning Procmail because they want to automatically separate non-spam messages from spam messages. My strategy is to do the following, in this order:
To implement step number . . .
For more about my spam-deflexion strategy and about Unsolicited Bulk Email (UBE or spam), see my Reverse Spam Filtering: Winning Without Fighting page.
For other people's spam-deflexion strategies, see the December-2005 gmane.mail.procmail
discussion about Spam and Procmail, which takes place in these
two threads.
Especially useful is this
message from G.W.
Haywood, in which he describes the system that he uses on his mail
servers and says:
“Most people haven't the faintest idea how much work is
involved in keeping the bulk of spam and other |
I am collecting Spam-related links at del.icio.us/Deflexion.com/Messaging/Spam.
The step-by-step instructions below guide you through setting up Procmail
to deliver to mailboxes that are in traditional
Unix mail spool format (mbox). To deliver to a mailbox that is in
maildir format, you need to append a forward
slash (/
) to the mailbox name. The table below gives examples
of the various types of mailbox specifications that can be used in the
action line of a Procmail recipe.
Traditional Unix mbox format |
maildir format |
maildir format on a Courier IMAP server |
MH format (*) |
||||
---|---|---|---|---|---|---|---|
|
|
|
|
||||
|
|
|
|
||||
|
|
|
|
||||
|
An explanation of how Procmail delivers to various folder formats is in the latest (3.22) procmailrc man page. Here is the relevant section.
[ . . .] Anything else will be taken as a mailbox name (either a filename or a directory, absolute or relative to the cur- rent directory (see MAILDIR)). If it is a (possibly yet nonexistent) filename, the mail will be appended to it. If it is a directory, the mail will be delivered to a newly created, guaranteed to be unique file named $MSGPRE- FIX* in the specified directory. If the mailbox name ends in "/.", then this directory is presumed to be an MH folder; i.e., procmail will use the next number it finds available. If the mailbox name ends in "/", then this directory is presumed to be a maildir folder; i.e., proc- mail will deliver the message to a file in a subdirectory named "tmp" and rename it to be inside a subdirectory named "new". If the mailbox is specified to be an MH folder or maildir folder, procmail will create the neces- sary directories if they don't exist, rather than treat the mailbox as a non-existent filename. When procmail is delivering to directories, you can specify multiple direc- tories to deliver to (procmail will do so utilising hardlinks).
When delivering to a maildir or MH format mailbox, you do not need to
use a lock file so the first line of a recipe does not need the second
colon. For example, instead of using this as the first line:
:0:
you can use this:
:0
There are examples of recipes that deliver to maildir-formatted mailboxes in Step 7D and in Using SpamAssassin below.
|
||
If you want your system mailboxes $ORGMAIL and $DEFAULT
to be in maildir format, it is best to specify this in the procmail
source code and recompile procmail. This is discussed in the following
messages, which were posted to the Procmail mailing
list.
|
If you are delivering messages to maildir-formatted mailboxes that will
be served to mail clients by Courier IMAP (which supports only maildir
format mailboxes), put a dot (.
) in front of the mailbox
name in your Procmail recipe. This leading dot is a hierarchy separator
and will ensure that IMAP clients can see these mailboxes. IMAP clients
will display the mailbox name without the leading dot (or the trailing
slash, which is just used to tell procmail the format of the mailbox and
is not part of the name that's used on the Unix system).
Technical Note: On Courier IMAP, private mailboxes
reside under the INBOX.
hierarchy. On the server,
this hierarchy is usually in the directory $HOME/Maildir
but users do
not need to tell their IMAP clients the actual name of this directory
because the IMAP protocol will pass that information to the IMAP client.
The Qmail MTA |
||
Systems that use the qmail MTA usually use maildir-formatted mailboxes. To use Procmail with qmail, put a line like one of the following in the relevant dot-qmail file: |preline /usr/local/bin/procmail ~/.procmailrc || exit 111 |preline procmail -m -p myprocmail.rc |preline procmail (It is not clear to me which of the above is best and it would be great if someone could fill me in so I can include more information about this here.) To learn more about using Procmail with qmail, see:
Qmail Tip: Depending on the |
“Firstly, the word MAILDIR as a variable name in procmail predates, and has absolutely nothing to do with, the mail storage format called "Maildir" which was invented quite some years later.
Secondly, . . .”
These 18 steps walk you through ensuring that procmail is installed on your system, setting it up to sort your incoming mailing-list messages, and testing your setup.
|
||
Important: For the following steps to work,
you must be a regular user, not root.
If you are a system administrator who is learning Procmail, I highly recommend that you step through this procedure before you try to set up a global procmail rc file. You are much more likely to understand the basics of Procmail if you learn by doing (rather than by reading only). And your system & users will be much less likely to experience an email nightmare if you do your Procmail learning — and making mistakes — as a regular user! |
Shell | Command |
csh, tcsh | which procmail |
sh, bash, ksh | type procmail |
various | whereis procmail |
various | where procmail |
various | locate procmail |
Make a note of the path to procmail because this is needed in Step
9 below.
procmail -v
|
||
|
~/.forward
, ~/.procmailrc
,
and the global procmailrc, if they exist. This will ensure that you
do a clean Procmail setup.
~/.forward
exists and what its contents
are if it does, type:
cat ~/.forwardIf
~/.forward
exists, rename it using a command similar
to this:
mv -i ~/.forward ~/.forward-2007-11-27This will ensure that you use the optimal
~/.forward
file for your system, which is discussed in Steps
8 and 9 below.~/.procmailrc
exists and what its
contents are if it does, type:
cat ~/.procmailrcIf
~/.procmailrc
exists, rename it using a command
similar to this:
mv -i ~/.procmailrc ~/.procmailrc-2007-11-27Steps 3 and 4 (in the next section) walk you through setting up a minimal
~/.procmailrc
file. If you would like to
use some of the recipes that are in your old procmailrc file, I
recommend that you call them by using an INCLUDERC
command in your new minimal ~/.procmailrc
. For an example
of an INCLUDERC
command, see the end of Step 4 below
(in the #### Processing Section
####
cat /etc/procmailrc cat /usr/local/etc/procmailrcIf a global procmailrc exists and if you are the administrator of your system, rename it using a command similar to this:
sudo mv -i /etc/procmailrc /etc/procmailrc-2007-11-27 ^^^^^^^^^^^^^^^ change to the path on your systemAfter you have experience setting up and using a personal procmailrc, you can, if you want, re-install this renamed global procmailrc. Details about using a global procmailrc are in See if There is a Global procmailrc below.
/usr/local/etc/procmailrc
for
the global procmailrc file. Also note that you can view the VPS
default files and directory structure in the /skel
directory. (Verio is where I host the Infinite Ink web pages, including
this page.)/etc/procmailrc
.
~/.procmailrc
by typing:
cd pico -w .procmailrc
|
||
|
~/.procmailrc
either by typing
it or by using copy &
paste*.
But first note these warnings.
|
|
# Note: Anything after a hash character (#) is a comment & is ignored by procmail. #### Begin Variables Section #### # It is essential that you set SHELL to a Bourne-type shell if # external commands are run from your procmailrc, for example if # you use rc.spamassassin, rc.quarantine, or other advanced recipes. # Setting SHELL should not be needed for the simple sorting recipes in # this step-by-step section, but to be safe and to future proof your # procmailrc, set it anyway! Details are in Check Your $SHELL and $PATH. SHELL=/bin/sh # Directory for storing procmail configuration and log files # You can name this variable anything you like, for example # PROCMAILDIR, or don't set it (but then don't refer to it!) PMDIR=$HOME/Procmail # LOGFILE should be specified ASAP so everything below it is logged # Put ## before the next line if you want no logging (not recommended) LOGFILE=$PMDIR/pmlog # To insert a blank line between each message's log entry in $LOGFILE, # uncomment the next two lines (this is helpful for debugging) ## LOG=" ## " # Set VERBOSE to yes when debugging; VERBOSE default is no ## VERBOSE=yes # Replace $HOME/Msgs with the directory where your personal (non-system-spool) mailboxes reside # Mailboxes in maildir format or served by Courier IMAP are often in $HOME/Maildir # Mailboxes served by UW IMAP are sometimes in $HOME, sometimes in $HOME/mail, & sometimes elsewhere # MAILDIR default is the value of $HOME # Make sure that $MAILDIR exists and that it is a directory! MAILDIR=$HOME/Msgs # # * On most systems $MAILDIR is a subdirectory of $HOME # * Upon reading a line that contains MAILDIR= # Procmail does a chdir to $MAILDIR # ...and $MAILDIR becomes the Procmail working directory # ...and relative paths are relative to $MAILDIR # * Do not include a trailing slash in your MAILDIR setting # * The $MAILDIR directory must exist and must be writable by your LOGNAME # * The MAILDIR variable is an entirely different entity from maildir mailbox format #### End Variables Section; Begin Processing Section #### INCLUDERC=$PMDIR/rc.testing INCLUDERC=$PMDIR/rc.subscriptions # Messages that fall through all your procmail recipes are delivered # to your default INBOX. To find out yours, run 'procmail -v' #### End Processing Section #### # EOF
$PMDIR
that you set in Step 4), type:
cd mkdir Procmail
cd Procmail pico -w rc.testing
~/Procmail/rc.testing
:
:0: * ^Subject:.*test IN-testing # EOF
|
||
|
.forward
File (not required on most systems) In 1994 when I wrote the Filtering Mail FAQ, which is what this
document evolved from, most Unix systems used sendmail
as
the message transfer agent (MTA) and Procmail was invoked
via the .forward
file. Nowadays, on most systems, the
.forward
file is not used to invoke procmail. Instead, either:
~/.procmailrc
exists, it will be used (regardless
of the existence of ~/.forward
).exim
as the MTA, and the default RedHat
Linux (since at least version 4.1), which uses sendmail
as the MTA. According to
this 2007-March-18 comment
in
my blog
from Jim Syler (aka Calion), Mac OS X uses Procmail
as the default LDA for fetchmail
, but does not use Procmail as the default LDA for postfix
. .forward
file and calls
procmail using some other method. For example:
qmail
MTA uses a dot-qmail file (discussed above)
to pass incoming messages to procmail.~/.forward.postfix
to pass incoming messages to
procmail.
|
||
|
-w
command-line argument
tells pico not to auto-wrap lines, that is, don't insert extra line
breaks.)
cd pico -w .forward
"|/absolute/path/to/procmail"The vertical bar (|) is a pipe and is typed as SHIFT-backslash on a standard US keyboard. Make sure you replace
/absolute/path/to
|
||
If sendmail is configured to use smrsh (sendmail restricted shell), you will only be able to invoke the version of procmail that is listed as an smrsh-allowed program. For more about this, see What are some typical installation problems? in era eriksson's Procmail FAQ and Q3.34 -- What does "foo not available for sendmail programs" mean? in the Sendmail FAQ. |
.forward
(if it exists), .procmailrc
,
and rc.testing
are in Unix ASCII text format by typing
cd file .procmailrc file ~/Procmail/* file .forwardFor each of these that exist, the response should be
ASCII text
or ASCII English text
. If it is anything else, for example
ASCII text, with CRLF line terminators
, go to Make Sure Your Configuration Files Use LF (Line Feed) Line Terminators in
the Troubleshooting section below and fix this problem..procmailrc
if either it or your home directory is either group or world writable.
Also, on some systems your .forward
file, if it exists,
needs to be world-readable & not executable and your home
directory needs to be world-searchable in order for the message transfer
agent to see the .forward
file. To set these
permissions, type the following:
cd chmod go-w,a+x . chmod go-w .procmailrc chmod 644 .forwardIf you skipped Step 8 and 9, you obviously don't need to chmod your non-existent .forward file. (But it won't hurt if you do!)
|
||
Once your .forward (if it is needed to invoke procmail)
and .procmailrc files are in place, procmail is alive.
To kill it, see Pulling the Plug on Procmail
below. |
If these two messages were not delivered correctly, see Troubleshooting below.
rc.subscriptions
,
or rc.sbe
if you prefer that name, for sorting solicited
bulk email (newsletters and mailing lists) into mailboxes. To do this,
type:
cd cd Procmail pico -w rc.subscriptions
rc.subscriptions
create a recipe, like the two example
recipes below, for each mailing list to which you are subscribed.
:0: * ^TO_procmail@lists.rwth-aachen.de IN-S-procmail :0: * ^TO_vim@vim.org IN-S-vimThe first recipe puts messages that are sent to the procmail mailing list into a mailbox named IN-S-procmail and the second recipe puts messages that are sent to the vim mailing list into a mailbox named IN-S-vim. The following table describes the meaning of the second recipe.
Notation | Meaning |
:0 | Begin a recipe |
: | Use a lock file |
* | Begin a condition |
^TO_ | Look for a header that begins with To, Cc, Resent-To, or another destination specification, followed by any or no characters, followed by an email address that begins with the string... |
|
vim@vim.org |
IN-S-vim | If there is a match, put the message in the mailbox $MAILDIR/IN-S-vim and stop processing this message; if there is not a match, pass the message to the next recipe |
Important Notes About Procmail's ^TO_ Macro | ||
|
|
||
|
rc.testing
1) so that it won't catch
non-testing messages that contain the string test
in the
Subject and 2) to save processing power. To turn the line into a comment,
put #
at the beginning of that INCLUDERC
line. Your .procmailrc
will now look like the following (possibly with the other
comments that I include in Step 4 above or your own comments).
#### Begin Variables Section #### # Next line is needed if programs are invoked from your procmailrc SHELL=/bin/sh PMDIR=$HOME/Procmail # Make sure this directory exists! LOGFILE=$PMDIR/pmlog ## LOG=" ## " ## VERBOSE=yes MAILDIR=$HOME/Msgs # Make sure this directory exists! #### End Variables Section; Begin Processing Section #### ## INCLUDERC=$PMDIR/rc.testing INCLUDERC=$PMDIR/rc.subscriptions # Messages that fall through all your procmail recipes are delivered # to your default INBOX. To find out yours, run 'procmail -v' #### End Processing Section #### # EOF
LOG
(2 lines), VERBOSE
,
and rc.testing
lines in your ~/.procmailrc
so you can use them for future debugging or experiments. ~/Procmail
directory that points to ~/.procmailrc
. You can do this
by typing:cd ~/Procmail ln -s ~/.procmailrc L.procmailrc ls -lNow when you are in your
~/Procmail
directory, L.procmailrc
is a “shortcut” or “alias” for ~/.procmailrc
.
If the file /etc/procmailrc
or
the directory /etc/procmailrcs
exist on your system,
I suggest that you also make symbolic links to those so that when you
are in your Procmail directory you'll remember that those exist. You
might also want to make a symbolic link to other mail-related files
and directories, such as the directory where your mailboxes are stored.
To learn more about symbolic links, see symbolic
link at FOLDOC, man
symlink, man
ln, and Lew Pitcher's The
difference between hard and soft links. For another example of symbolic
linking, see Using Multiple Clients to Access
Your Mailboxes below.
|
||
Do not try to deliver mail to a symbolic or hard link. Because of potential locking problems, a mailbox that Procmail delivers to should be an actual file and the $ORGMAIL mailbox, which is discussed in the Troubleshooting section below, must not be a symbolic link or a file with more than one hard link. |
After procmail delivers messages to your mailboxes, you can access your mailboxes using
If you are looking for an IMAP service provider that has procmail installed, see my list of Free and Reasonably-Priced IMAP Service Providers -- most of the providers in the list that give Unix shell access also have procmail installed.
If you use a mail or news client to change a mailbox that is receiving messages for example, to delete a message make sure that both procmail and your client use the same locking scheme. To determine what locking strategies are used by your installation of procmail, and the order in which these locking strategies are used, run:
procmail -v
and look at the value of “Locking strategies.”
To learn about file locking, see:
|
Here are instructions for how to use some clients to open a mailbox that is in that client's default mailbox directory. (Please send me information about other mail and news clients!)
Client | Default Mailbox Directory |
Command Line | Within Client | Lock? | ||
pine | pine -if mailbox | G mailbox | yes | |||
mutt | mutt -f +mailbox | c +mailbox | yes | |||
elm | elm -f =mailbox | c =mailbox | yes | |||
mail -f /path/mailbox | yes | |||||
nn | ~/News | nn +mailbox | G +mailbox | no |
If a client does not use a lock file, you should not use that client to
change the mailbox while it is receiving messages. To learn more about
your mail or news client, see your client's documentation. I describe
how to set up Pine mailbox collections in Setting
Up Local and Remote Folder Collections in my Power Pine.
Most Unix mail clients store mailboxes in a directory named either "Mail"
or "mail" and most Unix NNTP clients use a directory named "News."
If you want to use more than one client to access your mailboxes (or make
it easy to do that in the future), you can use the Unix
ln
command to link the directory where your mailboxes
are stored to the names of the mailbox directories used by other clients.
Here are instructions for merging the mailboxes in your existing mailbox
directories into a new directory named Msgs, and then linking this directory
to the names mail, Mail, and News. In Steps 3-5 below
replace mail with the name of one of your existing mailbox directories.
Type this | To do this | |
1 | cd | Go to your home directory. |
2 | mkdir Msgs | Create a directory named Msgs. (Alternatively, you could
use the mv command to rename one of your existing mailbox
directories to Msgs.) |
3 | mv -i mail/* Msgs/. | Move files in the directory named mail to the directory named Msgs and inquire if files with the same name should be overwritten. Answer no (n) to these inquiries. |
4 | mv -i mail/Duplicate Msgs/Unique | Move file with a duplicate name to the Msgs directory and rename it to a unique name. Do this for each duplicate name you encountered in Step 3. |
5 | rmdir mail | Delete the mail directory |
|
||
Type this | To do this | |
ln -s Msgs mail | Link the Msgs directory to the name mail. | |
ln -s Msgs Mail | Link the Msgs directory to the name Mail. | |
ln -s Msgs News | Link the Msgs directory to the name News. |
Of course, you can also link the Msgs directory to any other name that a program uses for its mailbox directory. Now all your mailboxes are in one place and you can easily save to and access them from different news and mail clients.
|
||
The above procedure works only if your mailboxes are in a single-file format, such as traditional Unix mbox format, and your mail and NNTP clients can all access the same mailbox formats. |
In Step 3 above, I put slash dot
after the target directory name (i.e., Msgs/.)
to ensure that a directory named Msgs rather than a file
named Msgs is the target. |
The Procmail log is located in $LOGFILE
, which, if you
used the instructions in Step 4 above, is $HOME/Procmail/pmlog
.
The contents of $LOGFILE
depend on the values of $VERBOSE
,
$LOG
, $LOGABSTRACT
, and $TRAP
,
which you can read about in the Environment
section of the procmailrc man page. You can use many commands to view
the log including cat
,
more
,
less
, and my favorite, tail
, which I discuss in the next section.
If you want to continually follow your log, you can use
tail -f $HOME/Procmail/pmlog
To start tailing with the last 50 lines of the log, use
tail -n 50 -f $HOME/Procmail/pmlog
which on my system is equivalent to
tail -50 -f $HOME/Procmail/pmlog
To quit live monitoring your log, type
CTRL-C
If you want to be able to run other commands while the tail is happening,
use
&
to put it in the background:
tail -f $HOME/Procmail/pmlog &
To learn about tail, see man
tail.
Another tail option is to use Paul Chvostek's ProcMail
Log Watch (pmlw
), which is an “awk script that
tails your procmail log file, summarizing results and giving you basic
traffic statistics, live.”
You can use mailstat
, a script that is part of the procmail
package, to get a concise summary of your procmail log file. To see if
it is on your system type one of the following commands:
which mailstat type mailstat whereis mailstat where mailstat locate mailstat
If mailstat
is on your system, type:
mailstat $HOME/Procmail/pmlog
This moves pmlog
to pmlog.old
and displays
a concise description of the contents that looks like the following:
Total Number Folder ----- ------ ------ 9964 3 IN-S-procmail 3408 1 IN-S-vim ----- ------ 13372 4
You may want to put the mailstat
command in your .login
or .profile
so that each time you log in you will see a list
of how many messages you have received since the last time you ran mailstat,
and what mailboxes these messages were delivered to. Or, if your system
lets you use the cron command to run programs on a regular schedule, you
could automatically run mailstat once a day or once a week and either
save the results in a file or mail the results to yourself. A typical
cron command line to collect the stats at 1:00 each morning and mail them
to yourself would be:
0 1 * * * mailstat $HOME/Procmail/pmlog | mail YourAddress
To get a listing of pmlog.old
, the previous log file, use
the -o
command-line argument:
mailstat -o $HOME/Procmail/pmlog
To get help on the mailstat
command-line arguments, type
one of the following:
mailstat -h man mailstat (I think this works only on a Debian Linux system)If
mailstat
is not on your system, ask your system administrator
to install it. It is located with all the other procmail tools (see www.procmail.org
for where to get procmail).
Your procmail log file will keep growing unless you regularly
delete it by using mailstat , the Unix rm
command, or some other technique. To minimize logging, put VERBOSE=no
(which is the default) and LOGABSTRACT=no in your
.procmailrc . To turn logging off, which I do not
recommend, turn the LOGFILE setting in your .procmailrc
file into a comment by preceding it with # , for example:
## LOGFILE=whatever |
Other scripts that you can use to summarize a Procmail log are:
Some ideas for changing what is logged and where it is logged are in
To be notified about incoming email messages in an RSS/Atom/XML feed reader, you can use a service or tool such as one of the following. Note that most feeds can be accessed by anyone, so make sure that you either secure your feed or send only non-private messages to your feed.
To use one of these services, you could set up Procmail to forward messages (or message headers or other message fragments) to the appropriate email address at the service provider.
https://gmail.google.com/gmail/feed/atom
and messages labeled label are available at
https://mail.google.com/mail/feed/atom/label/
.
I discuss using Procmail to forward messages to Google Mail in Forwarding
and Plus Addressing below. mail2RSS
or search
for the phrase mail to RSS
I list more tools and services that can be used to deflect email messages to RSS/Atom/XML feeds — and vice versa — on the following pages. These pages include links to tools & services that can be used for doing many different types of message deflexion.
Please tell me about other tools or services that can be used to send a message or Procmail log entry to an RSS/Atom/XML feed.
If you are looking
for a desktop feed reader, check out Opera,
which is free/gratis, ad-free, and registration-free for all.
To me, it's especially nice when the Newsfeeds
are set up with View > Display > List and message
on right List and message below Opera is also a multi-platform standards-based customizable HTTP, IRC, BitTorrent, NNTP, & IMAP client. |
In addition to the Procmail-specific notification tools that I discuss above, there are many other programs, such as biff, that can notify you about incoming messages. For details, see:
mailutil
, which is a command-line utility distributed
with the University of Wasington
(UW) IMAP Toolkit and with both Unix- and PC-Pine
4.50+. It can be used to check local and IMAP-accessible mailboxes for
RECENT messages and to do a lot of other things too. For details, see
Using
mailutil on the Power Pine page and man mailutil
at the UW. i
typed seven times or in geek speak i^7
)
or use this link to
initiate your registration.]Also, some IMAP clients can be set up to monitor mailboxes on IMAP servers. For example, I run Mulberry along with my primary mail client, Pine, mainly for its customizable monitoring of mailboxes and mailbox-specific alerts.
On the Power Pine page, I discuss techniques for Checking for Recent Messages in Pine. Especially useful are the “newmail-fifo” and “newmail-window” features, which are available in Pine 4.62+.
A Procmail recipe looks like this:
:0 flags: LockfileName * condition1-PMRE (PMRE = Procmail regular expression) * condition2-PMRE exactly one action item
where flags, the second colon (:
), LockfileName,
and the condition lines are optional. So a minimal Procmail recipe looks
like this:
:0 exactly one action item
which means perform the exactly one action item on every message that is passed to this recipe and don't do any mailbox locking (that's what the missing second colon means).
A recipe that uses no flags and does not explicitly specify the lock file, but instead uses the implicit lock file, looks like this:
:0: * condition1-PMRE * condition2-PMRE exactly one action item
In this case, the header only is passed to the conditions and if both condition1-PMRE AND condition2-PMRE are satisfied, the whole message (header & body) is passed to the exactly one action item and procmail stops processing the message.
|
In the previous section, we saw that it is easy to create a Procmail
recipe that ANDs conditions. If you want to OR conditons,
see Jari's ORing
traditionally, ORing
and score recipe, and ORing
by using De Morgan rules. There is an example of ORing traditionally
in Using the Extraction Operator (\/
)
and $MATCH to Sort Solicited Bulk Email below. Dallman Ross's virus-snagger
recipes include elegant examples of ORing with scores.
The recipe in rc.testing is:
:0: * ^Subject:.*test IN-testing
The following table explains the meaning of this recipe.
Notation | Meaning |
:0 | Begin a recipe |
: | Use a lock file |
* | Begin a condition |
^Subject: | Look for a header that begins with the string Subject: |
. | ... followed by .
(any character) |
* | ... 0 or more of preceding item [i.e. any, possibly empty, sequence of characters] |
test | ... followed by the string
test |
IN-testing | If there is a match, put the message in the mailbox $MAILDIR/IN-testing and stop processing this message; if there is not a match, pass the message to the next Procmail recipe |
If you want a recipe to match only the word
test, rather than the string test,
surround test with the Procmail word delimiters \<
and \>
as in the following:
:0: * ^Subject:.*\<test\> IN-testing
This recipe would not match on a message that contained procmail
testing in the Subject but it would match on a message that contained
procmail test in the Subject. The next section includes another
example of a Procmail recipe condition that uses \<
(the example is in the Tip).
To learn more about Procmail regular expressions, see regular expression in the Terminology section above and Jari Aalto's Procmail and Egrep Differences. Jari includes technical details about Procmail's word delimiters.
Important Warning: Procmail
Cannot Reliably Route Users' Messages in a |
The most frequently asked question about Procmail is “How can I use Procmail to separate messages that were sent to different addresses?” And the answer is: “That is a job for the MTA (message transfer agent).” Unfortunately, it is now common for people to have a virtual (aka vanity) domain and to not be able to use an MTA to route the domain's mail. Instead, the domain's mail is delivered to a “dropbox” and then people try to use Procmail to do the routing long after the messages pass through the MTA that is running on the domain's purported mail server (the server pointed to by the DNS MX record for the domain). This is fraught with problems as you will discover if you try to do it.
The current Procmail maintainer, Philip Guenther, summed it up well in a message in the procmail mailing list in which he said:
“You can't do virtual domains in pure procmail, as you need the MTA to provide you with the original envelope recipient address. Once you have that, sort the messages on that directly (do *not* use ^TO_).” |
Sometimes the MTA is set up to record the original envelope
recipient address in one of the following headers.
Header | Comment | |
Delivered-To: |
used by qmail and its companions preline
and safecat ;
used by postfix when possible as discussed here
and here;
used by courier (when courier is the
MTA) and its companion maildrop ; used by getmail ;
used at Gmail as discussed
below, GMX,
and Verio
|
|
X-Delivered-To: |
used at FastMail.FM as discussed here | |
Envelope-To: |
used by exim as discussed in the book Exim: The
Mail Transfer Agent near the end of this
section of Chapter 3; used at providers who use the cPanel
web-hosting control panel; used at 1and1.com |
|
X-Envelope-To: |
used by sendmail with help from procmail ,
for details see the sendmail-related links below; used at Pair.com and
Tuffmail.com |
|
X-Original-To: |
used by postfix 2.0.?+ as discussed here
and here;
used at DreamHost as discussed here;
used at Panix.com |
|
X-Apparently-To |
used by Yahoo! | |
X-MailNull-To: |
used at MailNull.com | |
X-Rcpt-To: |
was used at the now defunct Best.com | |
X-Real-To: |
used by CommuniGate Pro as discussed here; used at APK.net |
And then you can use a Procmail recipe, such as the following recipe, to process messages sent to a specific address in your virtual domain.
:0: * ^X-Rcpt-To:.*secretBccAddress@my\.domain IN-sent-bcc
Note that the condition in this recipe uses \.
(backslash
dot) to specify an actual dot. If you use .
without
a preceding backslash, it is a metacharacter that means
any character.
|
||
|
|
||
Even if your mail-hosting provider has set up their MTA to inject
a header such as X-Rcpt-To into incoming messages, there
can still be problems. For example,
|
Once SPF (Sender Policy Framework) is adopted, some headers from some users will matter, i.e., be trustable. Currently no header should be trusted.
For exhaustive information about this, see:
IfTo check your answer, see the links below.a@b.c
is the recipient of an email message, which headers will contain the addressa@b.c
?
“There is a procmail mantra. Please recite it with me:PROCMAIL IS NOT AN MTA.”
The recipes that I suggest in Step 15
for sorting solicited bulk email use the special procmail expression ^TO_
,
which catches any message that contains the list address in the To, Cc,
Resent-To, or some other destination header. If someone sends a message
to a mailing list by putting the mailing list address in the Bcc header,
this address will usually not appear in any of the destination headers
that the ^TO_
expression checks — that's why it is
called Blind Carbon Copy!
You can catch these Bcc'd messages, and all other messages that are sent to the list, by determining a header that all messages that are passed to the list contain, and messages that are not sent to the list do not contain. Such a header depends on either the mailing-list management software that the list is using or the address that you used to subscribe to the list (this will work if you use a unique address for each list you join). Examples of such headers are:
List-ID:
(can be used by Majordomo,
Majordomo2, and Mailman;
see RFC 2919 for
details about this header)
List-Post:
(see RFC 2369
for details about this and related List-* headers)
Mailing-List:
(used by ezmlm
and Yahoo! Groups)
X-Mailing-List:
(used by SmartList)
X-BeenThere:
(used by Mailman)
X-MDMailing-List:
Sender:
Resent-Sender:
Return-Path:
Delivered-To:
(discussed in previous
section and in the Vim list example below)
From
(without the quote marks;
this is sometimes referred to as the -
including
those that were Bcc'd -
to the vim mailing list by using the
following recipe:
:0: * ^Delivered-To:.*vim@vim.org IN-S-vimAnd the following recipe will catch all messages that are sent to the procmail mailing list.
:0: * ^List-ID:.*procmail.lists.RWTH-Aachen.DE IN-S-procmail
(This procmail recipe works on messages sent to the procmail mailing list after 18 May 2000, which is when the mailing list management software changed and started including the List-ID header.)
|
|
||
Some people prefer to use the ^TO_ expression
to catch mailing-list messages because:
Details about the |
\/
) and $MATCH to Sort Solicited
Bulk EmailIf you subscribe to a lot of mailing lists and each one has its own recipe like this:
:0: * ^TO_vim@vim.org IN-S-vim
You can speed up processing by combining all your subscription recipes into a single recipe like this:
:0: * ^TO_\/(subscription1|subscription2|subscription3) IN-S-$MATCH
Here is what this means:
Notation | Meaning |
:0 | Begin a recipe |
: | Use a lock file |
* | Begin a condition |
^TO_ | Look for a header that begins with To, Cc, Resent-To, or another destination specification, followed by any or no characters, followed by an email address that begins with... |
\/ | [Begin extraction; if there is a match after the
extraction
operator \/ , put it into a variable named MATCH.
] |
|
...the string subscription1 or subscription2 or subscription3. |
IN-S-$MATCH | If there is a match, put the message in the mailbox $MAILDIR/IN-S-$MATCH and stop processing this message; if there is not a match, pass the message to the next recipe |
The disadvantage of this recipe is that your mailbox will be named whatever
you specify as subscriptionn
. For example, if you
use this:
:0: * ^TO_\/(procmail@lists.rwth-aachen.de|vim@vim.org) IN-S-$MATCH
Your mailboxes will be named:
IN-S-procmail@lists.rwth-aachen.de IN-S-vim@vim.org
which are ugly and would be a pain to type in your mail client or at a command-line prompt. So you might want to use the following:
:0: * ^TO_\/(procmail|vim) IN-S-$MATCH
This produces nice mailbox names but has the disadvantage that it might
match on messages that were not actually sent to the mailing lists. For
example, it would match on a message sent to vimala@example.com. (FYI,
Vimala
is an Indian name that means "pure.") You can refine this
recipe by appending the "at" character (@
) to the
condition:
:0: * ^TO_\/(procmail|vim)@ IN-S-$MATCH
This should be pretty good about matching only messages that were actually sent to the list but now your mailbox names look like this:
IN-S-procmail@ IN-S-vim@
To delete the trailing @ from the mailbox names, you can use the following recipe (assuming you are using Procmail version ??? or later):
:0: * ^TO_\/(subscription1|subscription2|subscription3)@ * MATCH ?? ()\/[^@]+ IN-S-$MATCH
Here is what this recipe means:
Notation | Meaning |
:0 | Begin a recipe |
: | Use a lock file |
* | Begin a condition |
^TO_ | Look for a header that begins with To, Cc, Resent-To, or another destination specification, followed by any or no characters, followed by an email address that begins with... |
\/ | [Begin extraction; if there is a match after the extraction
operator \/ , put it into a variable named MATCH.
] |
|
...the string subscription1@ or subscription2@ or subscription3@. |
* | If the first condition was satified, begin the second condition; if the first condition failed, pass the message to the next recipe. |
MATCH ?? |
Test the variable named MATCH against... |
()\/ | [Begin extraction; if there is a match after the extraction
operator ()\/ , put it into a variable named MATCH
(replacing the old value).] |
[^@] | ...any character other than the @ character |
+ | one or more of previous item. In this case the test is looking for a non-empty sequence of characters that does not contain the @ character. |
IN-S-$MATCH | If the test was successful (i.e., if the original $MATCH contained
a non-empty sequence of characters that did not contain the @ character),
put the message in the mailbox $MAILDIR/IN-S-$MATCH and stop processing
this message; if the test failed, pass the message to the next recipe
(the only way this test would fail would be if subscriptionN
contained only @ characters!). |
Most mailing lists are sorted fine by the above recipe, but there is
a problem if the string subscriptionn
in the mailing-list
address is not consistent in the capitalization of its letters. For example,
debian-user messages
are delivered to mailboxes named
IN-S-debian-user IN-S-Debian-user
and all other combinations of upper- and lower-case letters that list participants use in the ^TO_ address. This happens when mailing-list-management software does not rewrite the list address into a canonical form and instead leaves it in the form that the message's author used.
To solve the problem with the inconsistent capitalization of the string 'debian-user' and any other non-canonicalized list addresses, you can do one of the following.
One way to avoid the inconsistent-capitalization problem described in the previous section is to extract the list name from a header that is inserted by the mailing-list software, such as Sender, List-ID, List-Post, Mailing-List, or one of the other alternatives to ^TO_ that I list above. For a simple example of extracting the mailing-list name from the Sender header and using $MATCH to construct the mailbox name, see the Recipes section at the bottom of this FreeBSD Diary Procmail page. This contains Neil Blakey-Milner's recipe for sorting all the FreeBSD lists that he subscribes to.
Sean B. Straw, of Professional Software Engineering, has a much more generic SBE sorting system. He created listname_id.rc, which extracts the list name from the headers of a message and assigns it to a variable named LISTNAME. He then uses something like the following in his .procmailrc.
INCLUDERC=$PMDIR/listname_id.rc :0: * ! LISTNAME ?? ^^^^ IN-S-$LISTNAME
For more about this, see:
listmail.rc
,
which is a variation of Sean's listname_id.rc
Note that I do not currently use these generic-SBE recipes but I plan to try them one of these days.
|
||
If the extracted $LISTNAME contains a dot (. ),
forward slash (/ ), or backslash (\ ) and
the mailbox IN-S-$LISTNAME is accessed using IMAP,
the IMAP server may interpret one of these characters as an IMAP
namespace hierarchy separator. For details, see Notes
About Mailbox Names above.
|
In the sections Using SpamAssassin and Using a Nesting Block to Optimize the SpamAssassin Recipes below, there is an example of using the extraction operator to prepend text at the beginning of the Subject of a message. This technique can also be used to append text to the end of the Subject.
Dallman Ross's Virus Snaggers include recipes that extract the values of the Content-Type and From headers and assign them to variables named CTYPE and VFROM, respectively.
Also see Philip Guenther's 1997-Jan-15 message Re: Wierd regex Behaviory [sic] in the Procmail list.
In addition to the techniques for downcasing a mailbox name listed above,
another option is to use forwarding and plus addressing. I discovered
this because I deflect some of my mailing-list messages
to my Tuffmail.com and Gmail.com
accounts and use plus
addressing to deliver directly to an appropriate mailbox or “label”
at Gmail. For example, instead of delivering to a mailbox named IN-S-$MATCH
as in the extraction-operator recipe above, I forward these
messages by putting the following in the recipe's action line:
! MyUID+$MATCH@tuffmail.com
or this:
! MyUID+$MATCH@gmail.com
or to route these messages to both Tuffmail and GMail, I use this:
! MyUID+$MATCH@tuffmail.com MyUID+$MATCH@gmail.com ^ Note that these 2 addresses are separated by a space If this doesn't work try using comma space (', ') or comma (',') instead
If a mailbox named $MATCH
exists in my Tuffmail mailstore,
the message is automatically delivered directly to it.
In other words, all Debian-user messages are delivered to a mailbox named
debian-user
(if it already exists) regardless of how the
string dEbIaN-uSeR
was capitalized in the original message
or in the envelope recipient address that Tuffmail received.
To learn more about plus addressing, which is also known as “subaddressing,” user-extension addressing, and detailed addressing, see my del.icio.us bookmarks about plus addressing and this section of my IMAP Service Providers page.
To learn more about Gmail (aka Google Mail), see my
del.icio.us bookmarks related to Gmail and the Gmail
discussion groups, especially the threads about The
PLUS (+) feature and Filtering
for list mail. At
Gmail you need to create a Gmail filter to automatically label incoming
messages. The Gmail MTA records the original envelope recipient address (for example
MyUID+$MATCH@gmail.com
) in a Delivered-To
header,
but unfortunately the Gmail filter cannot filter on this header. I describe
how I get around this in a 2004-July-20 message with the subject Tip:
Simultaneously file a message in an IMAP mailbox and assign a Gmail label
that I posted to the Procmail list — make sure you read the entire
thread.
Gmail Tips:
|
|
Doing MTA-style forwarding with Procmail can be problematic, most notably there can be problems with:
man
procmailex
(search for Loop
)
For more about this and related problems, see:
News
Details about these programs are below. |
Nowadays many mail
service providers give their users the option to have incoming mail
scanned for viruses, but if
then you can use Procmail — preferably running on your incoming mail server — to detect and snag viruses. There are many Procmail recipes that (attempt to) do this, including:
|
When you are choosing or creating a virus-snagging recipe, or
any recipe, do not use a recipe that has an
If you decide to use a recipe that uses the |
I am collecting Virus-related links at del.icio.us/Deflexion.com/Viruses.
News 2007 August 9: The Apache Software Foundation released SpamAssassin 3.2.3. |
SpamAssassin is free/libre open-source software (FLOSS) that can be used to analyze a message and tag it with a “spamminess” score. The higher the score, the more likely it is that the message is spam. After a message is tagged, Procmail can be used to filter the message to an appropriate mailbox, assign an IMAP keyword (label), or delete it.
|
||
The recipes below are specific to my system and my configuration
files. Before using these recipes, you need
(which is also known as ).
The message Re:
add headers by Theo
Van Dinter is also useful. |
# IMPORTANT # For these recipes to work, you need to first set the standard Procmail # environment variables, which are described in the step-by-step section # above. Since the first two recipes below pipe messages through external # programs, you must ensure that PM is using a Bourne-type shell. # # # Recommendation 1: Filter your viruses, greenlisted & solicited-bulk # email before you plug in your SpamAssassin recipes. This will save # CPU/memory and make it less likely that a non-spam message is tagged # as spam. # # Recommendation 2: Read the SA discussion group and make sure that # you are using the most up-to-date version of SA and that you know # about any caveats. # # If a message is larger than 256000 bytes (~250 KB), I use the # extraction operator (\/) and formail, which is part of the # Procmail package, to tag the Subject with {* -BIG- *} # so I can easily tell that the message was not analyzed # by SA and I should be wary of it because it is rare for a # legitimate message to be this big. I do not use SA on # large messages because it consumes too much CPU/memory. # Note: This is an example of a non-delivering recipe and all # messages will pass through it and continue to the next recipe. :0 fh w * > 256000 * ^Subject:\/.* | formail -I "Subject: {* -BIG- *} $MATCH" # ELSE if the previous recipe's conditions did not match (i.e., if the # message is smaller than or equal to 250 KB), pipe it through spamc # (the client part of the spamc/spamd client-server pair). # Note: No lock file is needed for spamc. :0 E f w | /absolute/path/to/spamc # If the spamd daemon is not running on your system, comment out the # above spamc recipe and uncomment the following (much less efficient) # spamassassin recipe. The explicit lock file (spamassassin.lock) # ensures that this recipe invokes only one instance of spamassassin # at a time. This is to try to prevent the memory-hog spamassassin from # using too much CPU/memory. ## :0 E f w: spamassassin.lock ## | /absolute/path/to/spamassassin # If the spam score is 49.00 or higher (at least 49 R's), put it in my # --infrared mailbox. I do this because Finding Bad Spam Delights Geeks and # I might want to post about these in What's your highest-scoring spam. # Note that SA 2.60+ records at most 50 spam-level "stars" so if you # specify 51 or more "stars" in a Procmail recipe, it will never match. # Important: If your "star" character (aka X-Spam-Level character) is a # PMRE metacharacter, such as * or +, escape it with a backslash (\) so it # will be interpreted as a literal character rather than a metacharacter. :0 * ^X-Spam-Level: RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR .--infrared/ # If the spam score is between 10.00 and 48.99, put it in my --2delete # mailbox. Once I am assured that only spam is delivered to this box, # I will have procmail delete it (discussed below). :0 * ^X-Spam-Level: RRRRRRRRRR .--2delete/ # If the score is between 5.00 and 9.99, put it in my --red mailbox # (which some people call the Spam or Junk mailbox). :0 * ^X-Spam-Level: RRRRR .--red/ # All messages that get here are put in my --yellow mailbox (which # some people call MaybeSpam or MaybeJunk). This includes {* -BIG- *} # messages and messages with a score of 4.99 or less. :0 .--yellow/ # IMPORTANT: The 4 delivering recipes above are delivering to mailboxes # that are in maildir format on a Courier IMAP server. That's why no # lock file is used and why each mailbox specification begins with dot (.) # and ends with forward slash (/). If you use a different mailbox format, # make sure you change these delivering recipes so that they are # appropriate for your system.
We can improve the SpamAssassin-related recipes in the previous
section by immediately delivering any {* -BIG- *}
X-Spam-Level
header, which it should not have
because it was not piped through spamc
. One way to
do this is to replace the first recipe above with a recipe whose exactly
one action item (discussed in
Anatomy of a Recipe above)
is a nesting
block. For example, you could replace it with a recipe similar to
the following.
# This outer "container" recipe is a non-delivering recipe and does # not need a lock file. That's why there is no colon (:) after :0 in # the next line. :0 * > 256000 { :0 fh w * ^Subject:\/.* | formail -I "Subject: {* -BIG- *} $MATCH" :0: --yellow } # IMPORTANT: In this example, the --yellow mailbox is in mbox format # and thus a lockfile is needed. If you use a different mailbox format, # make sure that you change the delivering recipe so that it is # appropriate for your system.
This is an example of a nesting block, which you can read about
in man procmailrc
and see examples of in man procmailex
.
For information about and links to the Procmail manual pages, see The
Fine Man Pages below.
See Also:
Inspired by cheap disk space and Opera Mail's & Gmail's search-don't-sort approach to email, some people are starting to keep all their messages in one giant universal mailbox and then using a combination of keywords (aka labels or flags or tags) and saved searches to zoom in on various groups of messages (“create virtual mailboxes”). This system has a number of advantages over using separate mailboxes, including:
I have not yet switched to this one-mailbox strategy, but I have started delivering my “yellow” (unknown, possibly spam) messages, which I discuss in the Using SpamAssassin section above, to my $DEFAULT mailbox. To set an IMAP keyword on these messages, I use a Procmail recipe like the following.
Note: The dollar sign ($
) is escaped with
a backslash (\
) so it will not be interpreted as a Procmail metacharacter.
# this recipe will usually work with an mbox-formatted mailbox on a UW IMAP server :0 * condition that matches a message that is yellow (unknown, possibly spam) { :0 fh w | formail -i "X-Keywords: \$Label5" :0: $DEFAULT }
I then have my mail clients, Alpine,
Pine 4.60+, Cone, Mulberry
4.0.1+,
and SeaMonkey Suite,
set up so that messages that have the $Label5
keyword are
colored yellow.
If you use Opera Mail,
the $Label5
IMAP keyword is not supported and you instead need
to use an IMAP keyword named XOPL-N
. For example,
if you would like your possibly-spam messages to be labeled “Funny”
() in Opera Mail, substitute
the following in the recipe above:
| formail -i "X-Keywords: XOPL-6"
I have tested this only with the Opera 9.0 Preview. Please let me know what, if any, IMAP keywords are supported in other versions of Opera.
|
||
|
|
See Also:
|
||
Before you use a procmail recipe to delete a message, you should
first have the recipe deliver to a 2delete or
infrared mailbox (see
the SpamAssassin recipe above for an example).
Then monitor this mailbox — and delete the messages by hand
— for about a month. After you are sure that the recipe catches
only messages that you want to delete, edit the recipe so that it
deletes the messages. |
One way to have procmail delete a message is to deliver it to /dev/null
by using a recipe such as this:
:0 * ^X-Spam-Level: RRRRRRRRRR /dev/null
Another way to delete a message is to set the HOST variable to anything other than the hostname of the machine on which procmail is running. This will make Procmail immediately stop reading the procmailrc and return an exitcode of zero (success). For example:
:0 * ^X-Spam-Level: RRRRRRRRRR { HOST = adios }
Another option, which is a variation of the previous option, is to unset the HOST variable by using a recipe like this:
:0 * ^X-Spam-Level: RRRRRRRRRR { HOST }
This last recipe is more cryptic to someone — including you —
who might try to understand it in the future so I recommend explicitly
setting HOST to something such as adios
or byebye
or hasta.la.vista.baby
|
|
By the time Procmail gets a message it is too late to reject
it at the SMTP level (aka “block it at the SMTP level”
or “send a 5xx error code”). It is sometimes possible
to use Procmail to “bounce back” a message or to send a fake
SMTP-rejection message, but this is not recommended
For more about all this, see:
|
||
The word bounce is sometimes used to mean bounce forward, which is also known as redirect, resend, remail, relay, or MTA-style forward. Because of the potential for confusion, I try to always use either the phrase bounce forward or bounce back instead of the single word bounce, unless it is absolutely clear from the context which type of bounce I mean. Note that bouncing forward, which can be done using ! in a procmail action item, also has problems. For details about bounce forwarding, see Forwarding and Plus Addressing above, especially the subsection called The Problems With Forwarding. I am collecting links about both bouncing forward and bouncing back in my Del.icio.us bookmarks under the tag Messaging/Bouncing. |
If you use recipes, such as the SpamAssassin recipes above, to try to sort spam into a “red” (rubbish) box, you will no doubt have experienced a
false positive (FP) — a non-spam message that was falsely identified as spam and delivered to a rubbish box.
A key to avoiding this type of false positive is to first sort messages that are almost surely not spam. For example, I use a bluelist and a greenlist, along with Procmail, to pre-sort my solicited-bulk-email (SBE) and my trusted (good) non-SBE senders.¹
To be able to optimally use this strategy, you
2greenlist
, 2bluelist
, 2ungreenlist
,
and 2unbluelist
IMAP mailboxes and then periodically
run a script against these mailboxes to update your procmail-usable
greenlist and bluelist.greenFrom
and
sbeRecip
keywords.
Soon I (and I hope others) will write about various ways to implement this in the upcoming Infinite Ink wiki-blog, which will probably be based on Dokuwiki. For now, see:
---
¹ Some people and programs stratify messages using whitelists and
blacklists, and call the messages that are in between these extremes “gray.”
I prefer to use the metaphor of the full
color spectrum to stratify my messages and that's why I deliver messages
to magenta, violet, blue,
green, lime, yellow, red, and infrared mailboxes.
The terms “whitelist” and “greenlist” are discussed
in this
message and this
message in the Procmail list.
² In the ideal world, mailing-list management software would detect
(& block!) viruses & spam, and not send these to the list members.
But because 1) everyone, including mailing-list management software, can
be infected; 2) viruses can be engineered to sneak into green & blue
boxes; and 3) viruses can be destructive, I recommend that you check all
messages for viruses.
³ When thinking about how to implement tools and procedures for maintaining
greenlists and bluelists, we need to remember that most users are not
going to have (or want) direct access to their server or their procmail
recipes. We also cannot assume anything about their email client and we
do not want to force them to do updates through a web browser (although
that could be an option). [It sure would be nice to be able to assume
clients and servers that support IMAP
mailboxes, IMAP
keywords, IMAP annotations, and server-side address books though!]
Once the .forward and .procmailrc files are in place and readable by your message transfer agent, procmail is plugged in and will be invoked each time a message arrives for you. If you have a problem, such as losing messages or a mail loop, you can quickly unplug procmail by getting rid of your .forward file. One way to do this is to rename it by typing the following:
cd mv .forward .forward.OFF
Just in case procmail is your system's local delivery agent (or becomes the LDA in the future), it is a good idea to also rename your .procmailrc file by typing:
mv .procmailrc .procmailrc.OFF
To turn procmail back on, type the following:
cd mv .forward.OFF .forward mv .procmailrc.OFF .procmailrc
|
||
Did you notice I violated my naming style by
using capital letters in a file name?! Bear in mind the wise words
of
Ralph Waldo Emerson in his essay Self-Reliance:
A foolish consistency is the hobgoblin of little minds, adored by little statesmen and philosophers and divines. |
If messages are not delivered correctly, here are steps you can use to try to solve the problem.
Look at your $LOGFILE ($HOME/Procmail/pmlog
)
to see if you can determine what the problem is.
Check these, and any other Procmail configuration files that you are using, for typos.
~/.forward ~/.procmailrc ~/Procmail/rc.testing
Also, if you have comments within a recipe, move them completely outside the recipe, for example, like this:
# comment # another comment :0: rest of the recipe with no embedded comments
Comments are not allowed in some parts of a recipe and it is safest to not use them at all within a recipe. For example, if you specify a conditon like this:
* condition # commentthen Procmail will interpret the string
# comment
to
be part of the regular expression that it is trying to match!
Make sure that each configuration file is a Unix ASCII text file with
Line
Feed (aka \n
or ^J
or ASCII character 10 or LF) line
terminators. To view all characters in a file, both printing and non-printing
characters, run this command:
cat -vet filename | less ||| ||+--display tab as '^I' |+--display end of each line as '$' +--display non-printing characters
If filename
contains a Carriage
Return character, which will almost always cause a problem in a Procmail
rc file, it will be displayed as ^M
by this variation of
the cat
command.
Alternatively, on some (‡) sytems, you can run this command:
file filename
Or, to check all files in your Procmail directory, run this:
file ~/Procmail/*
Each Procmail configuration file should be listed as one of the following.
ASCII text ASCII English text
If a file was created or edited on a non-Unix system and transferred
using Copy & Paste, Samba,
or a
ASCII text, with CRLF line terminators ASCII text, with CRLF, CR, LF line terminators
Each of these means that there are lines in the file that are terminated with something other than the Line Feed character.
|
||
(‡) Not all versions of the file command distinguish between
the different types of ASCII files -- does anyone know which versions
of file make this distinction??? To learn more about
the file command, see the file
man page at gsp.com,
linux.gr
or (preferred) on your system. |
Since Unix uses only the Line Feed character to terminate a line, the
Carriage
Return character (aka \r
or ^M
or ASCII character 13 or CR)
is interpreted to be a regular character by Procmail and it will almost
always cause a problem. For examples of this causing a problem in Procmail
and suggestions for how to fix it, see the following:
od
piped through fgrep
(FYI, od
is octal/decimal/hex/ASCII dump)
Tip 1:
An easy way to fix the carriage-return problem in a single file is to open it in either nano
or pico
and then simply writeOut and eXit. For example, run
Press... To... ======== ===== ^O writeOut ENTER accept the filename ^X eXit
This will convert the file to Unix format (LF line terminators) if it's not already in Unix format.
Tip 2: Another option is to use the command-line tool dos2unix, which is also known as tofrodos.
Tip 3: To learn about ASCII file transfers, see Dan Tobias's Use ASCII mode for HTML FTP transfers.
Use the instructions below to check the file and directory permissions
of your .forward file. (These were set with the chmod commands in Step
11.)
Type This | To Do This |
cd | Go to your home directory |
ls -l .forward | Check the access permissions of your .forward;
it should say
|
ls -l .procmailrc | Check the access permissions of your .procmailrc;
it should say (or what else
will work here???) |
ls -ld . | Check the access permissions of your home directory;
it should say where
each question mark may be the letter r or a hyphen
( , ,
,
are each acceptable) |
|
LOG=" " VERBOSE=yes
Test procmail by sending yourself messages as described in Steps 12 and 13 again. Look at your $LOGFILE, which will contain verbose entries and a blank line between each message's log entry (that's what the two-line LOG setting does), to see if you can now determine what the problem is.
If you can't figure out what's going on in your log because messages are arriving simultaneously and their log info is intertwined, see Bart Schaefer's message Re: Procmail log intelligibility and David W. Tamkin's followup message in the Procmail mailing list.
After you decipher your log and get procmail to work, you probably will
want to set VERBOSE=no
and "unplug" the LOG
line by preceding it with #
(or ##
if you are
using my style).
If there is a global procmailrc file on your system, its settings and recipes are used by all users on the system and it is read before your personal procmailrc file. It often resides in one of the following files:
/etc/procmailrc /usr/local/etc/procmailrc
If neither of these files exist on your system, it is possible that your system administrator configured Procmail to use a different global rc file. The location of the global rc file may be documented in the Procmail manual page on your system. To see how your local Procmail is configured, type
man procmail
followed by
/global
The second command searches forward in the man page for the string
global
and will jump to a line that looks something
like this:
/etc/procmailrc initial global rcfile
If the manual page is from the same install as the Procmail binaries, it should contain the correct path to the global rc file. If neither the procmail man page nor exploring your system turns up a global procmail rc file, ask in your system's discussion group or ask your system administrator.
Another thing to look for on your system is the directory /etc/procmailrcs
.
To see if this directory is on your system and to list the directory's
contents if it exists, type
ls -l /etc/procmailrcs ^ make sure you type this s!
To learn more about the global procmailrc
file, the files
in the procmailrcs
directory, what user the recipes in these
files are run as, and how they relate to the user procmailrc file, see:
man procmail
DROPPRIVS=yes
, SWITCHRC
,
and a lot moreSWITCHRC
and more. Especially
useful is this
comment by Ruud:
“SWITCHRC is like a GOTO, INCLUDERC like a GOSUB.”
If you invoke programs from your .procmailrc
, it is possible
that either the SHELL or PATH environment variable that procmail is using
is causing problems. To check the settings that procmail is using, put
the following three lines in your .procmailrc
after the line
that sets the LOGFILE environment variable.
LOG="My PATH is currently $PATH My SHELL is currently $SHELL "
The third line contains only the double quote character. It closes the beginning quote, which is on the first line, and inserts an extra linefeed (and thus a blank line) in your log to make it more readable.
Next, send yourself a message so that the commands in your .procmailrc
are run and the above lines are appended to your $LOGFILE. Now view
the tail of your log using for example
tail -n 30 $HOME/Procmail/pmlog
This displays the last 30 lines of your log. If $SHELL is anything other
than the Bourne shell
(sh
), the Bourne
again shell (bash
), or another Bourne shell derivative,
put a line like this at the top of your .procmailrc
file.
SHELL=/bin/sh
Of course you should make sure that /bin/sh
exists on your
system! To determine the path to sh
on your system, run one
of the following:
which sh type sh whereis sh where sh locate sh
For some information about the problems with non-Bourne-derived shells, see the 2004-Jan-29 message Re: forward to multiple users by David W. Tamkin.
If your $PATH does not contain all the directories from which you run
programs and if you don't always specify the absolute path to programs,
you need to add the needed directory (or directories) to your $PATH. For
example, if you installed a CVS version of SpamAssassin (SA) in your $HOME
directory and if you want to invoke that version of spamassassin
or sa-learn
from Procmail, you may want to add a line like
this
PATH=$HOME/SAusr/local/bin:$PATH
This line should be put near the top of your .procmailrc
.
For example, immediately after the SHELL setting.
|
||
“... you shouldn't alter PATH
unless there's something actually missing from it or the order |
||
-- Philip Guenther in a message in the procmail mailing list |
In this Quick Start, I suggest that you do not explicitly set the Procmail
DEFAULT and ORGMAIL environment variables, which are used to specify the
default inbox (defined above) and the ORiGinal
default inbox, respectively. Instead I suggest that you use Procmail's
default DEFAULT and default ORGMAIL settings because doing
If you want to override the default DEFAULT setting, include lines
similar to the following in your .procmailrc
:
MAILDIR=$HOME/Msgs # Make sure this directory exists! DEFAULT=IN-catchall
Note that the mailbox IN-catchall
will be located in the
MAILDIR directory (as long as the value of DEFAULT is specified using
a relative path rather than an absolute path). If you want DEFAULT to
be a maildir-formatted mailbox (rather than mbox-formatted), append a
trailing slash (/
) to the mailbox name. For example, use
this:
DEFAULT=IN-catchall/or, if this maildir-formatted mailbox will be served by a Courier IMAP server, use this:
DEFAULT=.IN-catchall/ ^ Note the leading dot
In any case, the Procmail MAILDIR variable, which is
an entirely different entity from maildir mailbox format, should be specified
in your .procmailrc
without a trailing slash.
If you want your DEFAULT maildir-formatted mailbox to be at the
top level of your Procmail MAILDIR directory, you can put something like
these two lines in your .procmailrc
:
MAILDIR=$HOME/Maildir # Make sure this directory exists! DEFAULT=$HOME/Maildir/ ^ Note that DEFAULT includes a trailing '/' and MAILDIR does not
Alternatively, you could use these two lines:
MAILDIR=$HOME/Maildir DEFAULT=$MAILDIR/ ^^^^^^^^ Note
Or these two lines:
MAILDIR=$HOME/Maildir DEFAULT=./ ^^ Note
I prefer to explicitly set DEFAULT
to $HOME/Maildir/
rather than $MAILDIR/
or ./
because there are
sections of my procmailrc
where I change Procmail's current
working directory ($MAILDIR
), and I want DEFAULT
to have a fixed value, i.e., be independent of the cwd.
On a Courier IMAP server with a default configuration, these settings
will make your Procmail “default inbox” or “system mailbox”
(i.e., the mailbox that is specified by the Procmail DEFAULT
variable) be the mailbox that is served when an IMAP client sends a request
for the IMAP INBOX
. Note that INBOX
is a special
IMAP name and the IMAP protocol translates this special name to the actual
default mailbox on that particular IMAP server. Examples of actual default
mailboxes include:
/var/spool/imap/user/username /var/spool/mail/username /var/mail/username /usr/spool/mail/username /usr/mail/username $HOME/Maildir (often used on a Courier IMAP server).
[Yes, it is confusing that the word maildir has three different meanings — the name of the mailbox format (maildir), the name of the Procmail variable (MAILDIR), and the name of the directory (Maildir)!]
You can check $DEFAULT and $MAILDIR, which $DEFAULT may depend on,
by using the technique described in the previous section, i.e., by putting
the following three lines in your .procmailrc
after the lines
that set the LOGFILE, MAILDIR, and DEFAULT environment variables.
LOG="My MAILDIR Directory is currently $MAILDIR My DEFAULT Inbox is currently $DEFAULT "
If Procmail is unable to deliver to $DEFAULT, for example if there is no space available, it will attempt to deliver to $ORGMAIL. To determine $ORGMAIL, run:
procmail -v
and look at the value of “Your system mailbox.”
|
||
|
The first thing to do when you are trying to figure out where Procmail delivered your mail is to look at your log file. If it is hard to interpret your log file, or if you don't have a log file, good places to look for missing messages are your $DEFAULT and $ORGMAIL mailboxes. If Procmail cannot deliver a message to the intended mailbox, it will try to deliver it to $DEFAULT. If it cannot deliver to $DEFAULT, it will try to deliver to $ORGMAIL. Details are in the previous section, Check $DEFAULT and $ORGMAIL.
To see if ~/.forward exists and display it if it does, type the following
cat ~/.forward
If this file exists and if your system is set up to use it, it is invoked before Procmail. If you want your mail to be processed by the recipes that are in your ~/.procmailrc file, set up your system so that your ~/.forward file either
If you want to both forward messages and use Procmail, do the forwarding via a Procmail recipe.
For more about the ~/.forward file, see Set Up Your .forward File (not required on most systems) above and the next section.
If you invoke procmail via a .forward file and you are still having problems, try these alternate .forward files and see era eriksson's Debugging Procmail Recipes at www.iki.fi/era/mail/procmail-debug.html.
|
||
If your system uses procmail as its local delivery agent or uses an MTA that does not respect the .forward file, this section is not relevant to you. |
The command you put in your .forward file depends on the version of Unix your system is running, the message transfer agent your system is using, and how your system administrator configured the system. On some systems the procmail manual page contains information that is specific to your system, including the best command to put in your .forward file. To see what is suggested in your system's procmail manual page, type the following at your system's Unix prompt:
man procmail | less
To search forward in the manual page for the word kludge, type:
/kludge
The command in the paragraph below the paragraph that contains the word kludge may be the best command to use on your system. If you want to read earlier text in the manual page, you can go up half a page by typing u.
If neither the .forward command in Step 9, which is
"|/absolute/path/to/procmail"
nor the one suggested in your system's procmail man page work, try a modified version of the following
"|IFS=' ' && exec /absolute/path/to/procmail -f- || exit 75 #nancym"
|
||
|
If that doesn't work, try these (with nancym replaced by your login name of course!):
"|exec /usr/local/bin/procmail #nancym" "|exec /usr/local/bin/procmail USER=nancym" "|IFS=' ';exec /usr/local/bin/procmail #nancym" "|IFS=' ';exec /usr/local/bin/procmail USER=nancym" "|/usr/local/bin/procmail #nancym" "|IFS=' '&&p=/usr/local/bin/procmail&&test -f $p&&exec $p -f-||exit 75#nancym"
These formats can be tried in different combinations; and the leading "| can be tried as |", or vice versa. Make sure you replace nancym with your user ID! era eriksson's Procmail FAQ includes a detailed explanation of the last .forward command.
H
or B
flag in a line that starts with :0
. This will help you
avoid a bug that is described (along with how to work around it) in
the following messages.
B
flag in the
:0
line, make sure that there is not — and never
will be — an earlier recipe that has the H
flag in
the top line.# EOF (workaround for procmail-v3.22 bug)
For more about Procmail bugs and patches for fixing them, see Philip's TODO list for procmail, Philip's list for procmail warts, the Procmail HISTORY file, and the October 2004 thread in the Procmail list about Who is the procmail maintainer?
If you are still having problems, see:
vsnag.point-n-shoot.sh
shell script, which
is part his Virus Snaggers (vsnag)
package
Make sure you read the six Procmail man pages on your system. If the manual pages are from the same install as the Procmail binaries on your system, they will document the configuration that is specific to your system. To find out which Procmail version is documented, type man procmail and then type /SOURCE to search for the SOURCE section. For example, here is the SOURCE section of man procmail at linux.gr and monkey.org.
If you want to read or link to hypertext man pages, here are the apple.com 3.22, gsp.com (version 3.22 I think), linux.gr 3.15.2 and monkey.org 3.15.1 man pages. Some links in the monkey.org man pages are broken so I recommend that you use the gsp.com or linux.gr pages.
man procmail
at apple.com,
gsp.com,
linux.gr
and monkey.org
man 5 procmailrc
at apple.com, gsp.com,
linux.gr,
and monkey.orgman 5 procmailex
at apple.com,
gsp.com,
linux.gr
and monkey.orgman 5 procmailsc
at apple.com, gsp.com,
linux.gr
and
monkey.orgman formail
at apple.com,
gsp.com,
linux.gr
and
monkey.orgman lockfile
at apple.com,
gsp.com,
linux.gr
and
monkey.orgman mailstat
at apple.com,
annys.eines.info
The following man pages are not part of the Procmail package, but may be useful to you.
man 5 filtering
at gsp.com,
viaverio.com,
and digitaldaze.com
man
savelogs
at viaverio.com
Many more man pages are available at the FreeBSD
Hypertext Man Pages, where you can choose from a drop-down list of
over 100 flavors and versions of Linux and Unix. Some have recent Procmail
man pages and some have ancient ones.
You can get concise help for procmail, formail, lockfile, and mailstat by typing the following at the Unix prompt on your system
procmail -h formail -h lockfile -h mailstat -h
More Procmail docs are sometimes in /usr/share/doc/procmail
,
but these are very outdated and you can get more current and robust Procmail
information in the documents listed in the next two sections.
This is one of the most popular pages here at Infinite Ink. I am collecting a list of pages that link to this page so I can find out where everyone is coming from, to provide some links that might be interesting to readers of this article, and as a way to thank everyone who links to this page.
Public discussion groups are a tremendous resource and they — along with the fine manual — are where I learned almost everything I know about Procmail. For details about the Procmail mailing list, including how to subscribe and unsubscribe, see mailman.rwth-aachen.de / mailman / listinfo / procmail. In addition to participating in the list via email, you can access — and in some cases participate in — the list using any of the following.
For an overview of the various Gmane incarnations of the Procmail list, including a form for searching the Gmane archive of the list, see Information about gmane.mail.procmail. Currently the Gmane archive of the Procmail list goes back to February 2002, but it would be great if someone would submit the entire Procmail list archive to Gmane. If you would like to support Gmane and get rid of the Gmane Google ads, donate money to Gmane.
There are a lot of other places around the Net where people discuss Procmail, including the groups that show up in the results of these searches:
If you visit the Usenet group comp.mail.misc (c.m.m), please ignore the anonymous coward, his many aliases (one of which is AC), and any thread started by AC or an AC alias. Tip: To maintain (or restore!) your sanity, I recommend avoiding c.m.m altogether.
|
||
Many archives munge
email addresses in order to hide them from email-address
harvesters. But this is a problem when the discussion is about
an email address (or about a fragment of an email address). For example,
a 2004-Nov-26 message from Ruud H.G. van Tol with Subject “Re:
alleged bug in ^TO_ macro: character '+' *is* allowed in emails”
was archived in many different ways, including:
/raw to the message's URL.
This is discussed in the Gmane
FAQ. |
In addition to searching discussion groups, which is discussed in the previous section, you can use the following links to search for Procmail-related tools and documents.
You can also use this form to search the web, the Infinite Ink site, or the Deflexion.com site (my blog) for information about Procmail (or about anything!).
Nancy McGough started Infinite Ink, www.ii.com, in 1992. Infinite Ink is dedicated to writing, teaching, and publishing about mathematics, science, computing, and philosophy. Before she started Infinite Ink, Nancy worked at Microsoft first as a technical writer and then as a program manager designing tools and strategies to improve communication and information access within Microsoft. The project, called Integration of Information Access Tools (IOIAT), included WinBBS, a MS Windows front end to Usenet News. Nancy has taught mathematics and computer science courses at universities, colleges, and at a grade school. She is a fan of standards-compliant, modular, open-source software, and she is especially interested in intertwingular software and software that helps people communicate and collaborate. Her primary software tools are Pine and Mulberry for IMAP messaging; nn and Pine for NNTP messaging; Dreamweaver and Vim for web page development; Vim for powerful text editing; SecureCRT for ssh connections & port forwarding; Powermarks for intertwingular bookmark management; Info Select for intertwingular information management; and (of course!) Procmail for automated message processing. Her favorite operating systems are Mac OS X & FreeBSD and her favorite mail- and web-hosting providers are Verio and JohnCompanies.com.
Thanks to Philip Guenther, the current former Procmail maintainer, for sending
me feedback on the 23 April 2001 incarnation of this page
and for all the work he's done on Procmail.
Thanks to John Levine of Taughannock Networks for giving me an account on his system which is running Courier IMAP, Qmail, and Procmail. It's because of this account that I was able to learn about and write about delivering to maildir-formatted mailboxes.
Thank you to these people who sent me feedback on this Procmail Quick Start:
And to these people who sent me feedback back in 1994 when I first wrote the Filtering Mail FAQ:
Thank you also to the developers of procmail, especially the creator, Stephen R. van den Berg, and the current maintainer, Philip Guenther; the people who have written procmail documentation; the members of the Procmail mailing list; and everyone else who has sent me feedback. Please let me know if I have left you out of my thank-you lists, or if you know the URL of any of the unlinked people in the lists.
Thanks to Norm Walsh and Lenny Muellner for letting me use these DocBook admonition graphics:
Tip
Note
Important
Warning
Finally thank you to my friends, family, and Internet acquaintances who have helped me to make Infinite Ink what it is. Special thanks to Bob Tinkelman of New York Net for giving me a free T1 line to my apartment (wow!) and to Sean Shapira of Jazzie Systems for giving me free web space and bandwidth for years.
|
||
Procmail Quick Start: An introduction to email filtering with a focus <http://www.ii.com/internet/robots/procmail/qs/> Copyright © Infinite Ink & Nancy McGough |
1st published in Filtering
Mail FAQ 1994 published here 1999 updated 05-Jun-2006 tweaked 27-Nov-2007 |