translated by Google

Machine-translated page for increased accessibility for English questioners.

What is procmail?

Procmail is used to process incoming mail. At FI, there is no need to use a file to make it work .forward , but the configuration file just exists .procmailrc . The procmail program will run for each message, and according to the rules it finds in the configuration file, it will execute the action of the respective rule. For example, you can save the message to the specified mailbox or send a message to an external program.


File .procmailrc must be in the home directory. It consists of rules that have 2 parts. The first part describes the report for which the rule is to be applied and the second is the action itself - so what to do with the rule that suits the rule. For example:

* ^From.*peter

This rule saves every message coming from the address that contains the sub-string peter into the "peterbox" mailbox. All paths are relative to the directory set in the variable MAILBOX (on FI home directory). If you want to read mail via an IMAP that searches for mailboxes in the mail directory /, add to the beginning of the file .procmailrc row


The rule always begins with a line where the first character is ":" followed by a list of flags describing the message processing, ie, for example, whether the message body should be checked in addition to the headers, whether the post-processing message should be forwarded to other rules and the like see the man page procmailrc ).

In the example above, the first line starts with a rule. (Number 0 is a historical remnant and has no function, but it is part of the start of the rule and must be left there.) Failing to show any flags means that we expect default behavior (which makes it more important to check only the message headers rather than the body). Line 2 is a condition that describes which rule applies. Each condition is on one line and begins with the "*" and everything is interpreted as a regular expression (POSIX 1003.2 RE) compatible with the regular regular expressions of the egrep program (see the man page egrep and regex ). Finally, the third line is an action. The action is always one line at the end of the rule. In this case, the message is saved in the mailbox peterbox .

Modifying the previous simple example is a procmail rule that stores all incoming mail in a mailbox myspool :

More complicated example:
:0 c
* ^From.*peter
* ^Subject:.*compilers
* ^Subject:.*perl compilers

This example has two rules. Line 1 shows flag "c" saying that the message does not end with this rule, but the copy is sent for further processing. Thus, the rule for all messages from the peter user with the subject that contains subtitle compilers performs action on line 4, that is, it sends a message to . The second rule saves all messages about Perl compilers into the mailbox perlcomp .

Forwarding emails using Procmail

Procmail allows us to set the same email forwarding as the file .forward , thus maintaining the envelope address of the sender. For example, see below. Note: there are always two white characters in the square brackets: space and tab.

* !^X-FI-Xuzivatel-Loop
    | formail -a 'X-FI-Xuzivatel-Loop: loop prevention'

    * ^Return-Path:[ 	]*\/[^ 	].+
    { env=$MATCH }

    ! ${env+-f "$env"}

In the faculty environment, there is a major difference over use .forward in that all Procmail settings are applied, for example, before forwarding spam filter or automatic reply to email in absence .