procmailrc | Début | Suivant | Sommaire | Préc.page.lue | Accueil |
NAME | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
SYNOPSIS | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
DESCRIPTION | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
The rcfile can contain a mixture of environment variable assignments (some of which have special meanings to procmail), and recipes. In their most simple appearance, the recipes are simply one line regular expressions that are searched for in the header of the arriving mail. The first recipe that matches is used to determine where the mail has to go (usually a file). If processing falls off the end of the rcfile, procmail will deliver the mail to $DEFAULT.
There are two kinds of recipes: delivering and non-delivering recipes. If a delivering recipe is found to match, procmail considers the mail (you guessed it) delivered and will cease processing the rcfile after having successfully executed the action line of the recipe. If a non-delivering recipe is found to match, processing of the rcfile will continue after the action line of this recipe has been executed.
Delivering recipes are those that cause header and/or body of the mail to be: written into a file, absorbed by a program or forwarded to a mailaddress.
Non-delivering recipes are: those that cause the output of a program or filter to be captured back by procmail or those that start a nesting block.
You can tell procmail to treat a delivering recipe as if it were a non-delivering recipe by specifying the `c' flag on such a recipe. This will make procmail generate a carbon copy of the mail by delivering it to this recipe, yet continue processing the rcfile.
By using any number of recipes you can presort your mail extremely straightforward into several mailfolders. Bear in mind though that the mail can arrive concurrently in these mailfolders (if several procmail programs happen to run at the same time, not unlikely if a lot of mail arrives). To make sure this does not result in a mess, proper use of lockfiles is highly recommended.
The environment variable assignments and recipes can be freely intermixed in the rcfile. If any environment variable has a special meaning to procmail, it will be used appropriately the moment it is parsed (i.e., you can change the current directory whenever you want by specifying a new MAILDIR, switch lockfiles by specifying a new LOCKFILE, change the umask at any time, etc., the possibilities are endless :-).
The assignments and substitutions of these environment variables are handled exactly like in sh(1) (that includes all possible quotes and escapes), with the added bonus that blanks around the '=' sign are ignored and that, if an environment variable appears without a trailing '=', it will be removed from the environment. Any program in backquotes started by procmail will have the entire mail at its stdin.
Comments | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
Recipes | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
A line starting with ':' marks the beginning of a recipe. It has the following format:
Conditions start with a leading `*', everything after that character is passed on to the internal egrep literally, except for leading and trailing whitespace. These regular expressions are completely compatible to the normal egrep(1) extended regular expressions. See also Extended regular expressions.
Conditions are anded; if there are no conditions the result will be true by default.
Flags can be any of the following:
There are some special conditions you can use that are not straight regular expressions. To select them, the condition must start with:
Local lockfile | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
If you put a second (trailing) ':' on the first recipe line, then procmail will use a locallockfile (for this recipe only). You can optionally specify the locallockfile to use; if you don't however, procmail will use the destination filename (or the filename following the first '>>') and will append $LOCKEXT to it.
Recipe action line | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
The action line can start with the following characters:
Anything else will be taken as a mailbox name (either a filename or a directory, absolute or relative to the current 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 $MSGPREFIX* 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., procmail 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 necessary 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 directories to deliver to (procmail will do so utilising hardlinks).
Environment variable defaults | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
Other cleared or preset environment variables are IFS, ENV and PWD.
For security reasons, upon startup procmail will wipe out all environment variables that are suspected of modifying the behavior of the runtime linker.
Environment | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
Before you get lost in the multitude of environment variables, keep in mind that all of them have reasonable defaults.
Extended regular expressions | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
These were only samples, of course, any more complex combination is valid as well.
The following token meanings are special procmail extensions:
EXAMPLES | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
CAVEATS | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
Don't put comments on the regular expression condition lines in a recipe, these lines are fed to the internal egrep literally (except for continuation backslashes at the end of a line).
Leading whitespace on continued regular expression condition lines is usually ignored (so that they can be indented), but not on continued condition lines that are evaluated according to the sh(1) substitution rules inside double quotes.
Watch out for deadlocks when doing unhealthy things like forwarding mail to your own account. Deadlocks can be broken by proper use of LOCKTIMEOUT.
Any default values that procmail has for some environment variables will always override the ones that were already defined. If you really want to override the defaults, you either have to put them in the rcfile or on the command line as arguments.
The /etc/procmailrc file cannot change the PATH setting seen by user rcfiles as the value is reset when procmail finishes the /etc/procmailrc file. While future enhancements are expected in this area, recompiling procmail with the desired value is currently the only correct solution.
Environment variables set inside the shell-interpreted-`|' action part of a recipe will not retain their value after the recipe has finished since they are set in a subshell of procmail. To make sure the value of an environment variable is retained you have to put the assignment to the variable before the leading `|' of a recipe, so that it can capture stdout of the program.
If you specify only a `h' or a `b' flag on a delivering recipe, and the recipe matches, then, unless the `c' flag is present as well, the body respectively the header of the mail will be silently lost.
SEE ALSO | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
BUGS | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
Unquoted variable expansions performed by procmail are always split on space, tab, and newline characters; the IFS variable is not used internally.
Procmail does not support the expansion of `~'.
A line buffer of length $LINEBUF is used when processing the rcfile, any expansions that don't fit within this limit will be truncated and PROCMAIL_OVERFLOW will be set. If the overflowing line is a condition or an action line, then it will be considered failed and procmail will continue processing. If it is a variable assignment or recipe start line then procmail will abort the entire rcfile.
If the global lockfile has a relative path, and the current directory is not the same as when the global lockfile was created, then the global lockfile will not be removed if procmail exits at that point (remedy: use absolute paths to specify global lockfiles).
If an rcfile has a relative path and when the rcfile is first opened MAILDIR contains a relative path, and if at one point procmail is instructed to clone itself and the current directory has changed since the rcfile was opened, then procmail will not be able to clone itself (remedy: use an absolute path to reference the rcfile or make sure MAILDIR contains an absolute path as the rcfile is opened).
A locallockfile on the recipe that marks the start of a non-forking nested block does not work as expected.
When capturing stdout from a recipe into an environment variable, exactly one trailing newline will be stripped.
Some non-optimal and non-obvious regexps set MATCH to an incorrect value. The regexp can be made to work by removing one or more unneeded '*', '+', or '?' operator on the left-hand side of the \/ token.
MISCELLANEOUS | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
If the regular expression contains `^TO' it will be substituted by `(^((Original-)?(Resent-)?(To |Cc |Bcc) |(X-Envelope |Apparently(-Resent)?)-To) :(.*[^a-zA-Z])?)', which should catch all destination specifications containing a specific word.
If the regular expression contains `^FROM_DAEMON' it will be substituted by `(^(Mailing-List : |Precedence :.*(junk |bulk |list) |To : Multiple recipients of |(((Resent-)?(From |Sender) |X-Envelope-From) : |>?From )([^>]*[^(.%@a-z0-9])?(Post(ma?(st(e?r)? |n) |office) |(send)?Mail(er)? |daemon |m(mdf |ajordomo) |n?uucp |LIST(SERV |proc) |NETSERV |o(wner |ps) |r(e(quest |sponse) |oot) |b(ounce |bs\.smtp) |echo |mirror |s(erv(ices? |er) |mtp(error)? |ystem) |A(dmin(istrator)? |MMGR |utoanswer))(([^).! :a-z0-9][-_a-z0-9]*)?[%@>\t ][^<)]*(\(.*\).*)?)?$([^>] |$)))', which should catch mails coming from most daemons (how's that for a regular expression :-).
If the regular expression contains `^FROM_MAILER' it will be substituted by `(^(((Resent-)?(From |Sender) |X-Envelope-From) : |>?From )([^>]*[^(.%@a-z0-9])?(Post(ma(st(er)? |n) |office) |(send)?Mail(er)? |daemon |mmdf |n?uucp |ops |r(esponse |oot) |(bbs\.)?smtp(error)? |s(erv(ices? |er) |ystem) |A(dmin(istrator)? |MMGR))(([^).! :a-z0-9][-_a-z0-9]*)?[%@>\t ][^<)]*(\(.*\).*)?)?$([^>] |$))' (a stripped down version of `^FROM_DAEMON'), which should catch mails coming from most mailer-daemons.
When assigning boolean values to variables like VERBOSE, DELIVERED or COMSAT, procmail accepts as true every string starting with: a non-zero value, `on', `y', `t' or `e'. False is every string starting with: a zero value, `off', `n', `f' or `d'.
If the action line of a recipe specifies a program, a sole backslash-newline pair in it on an otherwise empty line will be converted into a newline.
The regular expression engine built into procmail does not support named character classes.
NOTES | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
The leading `|' on the action line to specify a program or filter is stripped before checking for $SHELLMETAS.
Files included with the INCLUDERC directive containing only environment variable assignments can be shared with sh.
The current behavior of assignments on the command line to INCLUDERC and SWITCHRC is not guaranteed, has been changed once already, and may be changed again or removed in future releases.
For really complicated processing you can even consider calling procmail recursively.
In the old days, the `:0' that marks the beginning of a recipe, had to be changed to `:n', whereby `n' denotes the number of conditions that follow.
AUTHORS | Début | Précédent | Suivant | Sommaire | Préc.page.lue | Accueil |
Sommaire | Début | Suivant | Sommaire | Préc.page.lue | Accueil |
Table des mots clés | Début | Suivant | Sommaire | Préc.page.lue | Accueil |
! | Recipe action line |
$ | Extended regular expressions |
> | Recipes |
< | Recipes |
(abc)* | Extended regular expressions |
. | Extended regular expressions |
? | Recipes |
[^-a-d] | Extended regular expressions |
\ | Recipes |
\< or \> | Extended regular expressions |
\. | Extended regular expressions |
\/ | Extended regular expressions |
^ | Extended regular expressions |
^ or $ | Extended regular expressions |
^^ | Extended regular expressions |
A | Recipes |
a* | Extended regular expressions |
a+ | Extended regular expressions |
a? | Extended regular expressions |
b | Recipes |
c | Recipes |
COMSAT | Environment |
D | Recipes |
DEFAULT | Environment |
DELIVERED | Environment |
de|abc | Extended regular expressions |
DROPPRIVS | Environment |
E | Recipes |
EXITCODE | Environment |
f | Recipes |
H | Recipes |
HOST | Environment |
i | Recipes |
INCLUDERC | Environment |
LASTFOLDER | Environment |
LINEBUF | Environment |
LOCKEXT | Environment |
LOCKFILE | Environment |
LOCKSLEEP | Environment |
LOCKTIMEOUT | Environment |
LOG | Environment |
LOGABSTRACT | Environment |
LOGFILE | Environment |
LOGNAME, HOME and SHELL | Environment variable defaults |
MAILDIR | Environment |
MATCH | Environment |
MSGPREFIX | Environment |
NORESRETRY | Environment |
ORGMAIL | Environment |
PATH | Environment variable defaults |
PROCMAIL_OVERFLOW | Environment |
PROCMAIL_VERSION | Environment |
r | Recipes |
SENDMAIL | Environment |
SENDMAILFLAGS | Environment variable defaults |
SHELLFLAGS | Environment |
SHELLMETAS | Environment |
SHIFT | Environment |
SUSPEND | Environment |
SWITCHRC | Environment |
TIMEOUT | Environment |
TRAP | Environment |
UMASK | Environment |
variablename ?? | Recipes |
VERBOSE | Environment |
w | Recipes |
{ | Recipe action line |
| | Recipe action line |