translated by Google

Machine-translated page for increased accessibility for English questioners.

What is procmail?

Procmail is used to process incoming mail. On FI, it is not necessary to call it using a file .forward , but the existence of a configuration file is sufficient .procmailrc . The procmail program runs for each message and, according to the rules it finds in the specified configuration file, performs the action corresponding to the given rule. For example, it can save a message to a specified mailbox or send a message to an external program.


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

* ^From.*adam

This rule stores every message coming from an address that contains a substring adam , to the mailbox adambox . All paths are relative to the directory set in the variable MAILBOX (to FI home directory). If you want read mail via IMAP who searches FI for mailboxes in the directory ~/mail/ , add to the beginning of the file .procmailrc line


The rule always starts with a line where the first character is ":" and is followed by a list of flags that describe message processing, ie whether the message body should be checked in addition to headers, whether the message should be forwarded to other rules after processing actions and so on (details see man page procmailrc ).

Therefore, in the example shown, the first line begins with the rule. (The number 0 is a historical remnant and has no function, but it is part of the beginning of the rule and should be left there.) ). The second line is a condition that describes to which messages the rule applies. Each condition is located on one line, begins with a "*", and everything after it is interpreted as a regular expression (POSIX 1003.2 RE) compatible with egrep extended regular expressions (see man page egrep and regex ). Finally, the third line is the action. The action is always one line at the end of the rule. In this case, this means that the message is saved in the mailbox adambox .

A modification of the previous simple example is the procmail rule, which stores all incoming mail in the mailbox myspool :


A more complicated example:

:0 c
* ^From.*adam
* ^Subject:.*compilers
* ^Subject:.*perl compilers

This example has two rules. Line 1 contains the "c" flag, which says that the message does not end with this rule, but a copy is sent for further processing. Therefore, for all messages from user adam with a subject that contains the substring "compilers", the rule performs the action on line 4, which means that the message is forwarded to the address . The second rule stores all messages related to Perl compilers in the mailbox perlcomp .

Forwarding of e-mails using Procmail

Procmail allows us to set up the same email forwarding as the file .forward , that is, preserving the sender's envelope address. See below for an example of the settings. Note: There are always two whitespace characters in these square brackets: a space and a tab. String Xuzivatel replace with your login, e.g. Xnovak29 .

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

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

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

In the faculty environment, the main difference is compared to the use .forward in that all Procmail settings are applied before forwarding, for example spam filter or automatic reply to e-mail in your absence .

Deleting log images from emails

If you read the text mail, you may be disturbed by signatures or logos that appear as an attachment to HTML messages, even if it is not an attachment that you should pay attention to. For always repeating images, you can use our script to delete them.

The condition is that you receive mail on the Anxur server (can be verified in Faculty administration ).

To your .procmailrc add these lines:

| /usr/local/libexec/

Then you need to create a file ~/.image-attachment-filter.cfg where you place the SHA-256 hashes of the attachments you want to delete (there may be a comment after the hash), as follows:

$ cat ~/.image-attachment-filter.cfg
1373b8627155d238a9856e3342961f1946858932086f7a2565b483b1959e14d9 Logo firmy XY

Hash is the output of the program sha256sum (can be used to calculate the hashes of other attachments you want to delete).

Please note that deleting the attachment will violate any electronic signatures of the message.

Rules for coded headers

Headers are non-ASCII when characters occur coded which may make it difficult for you to apply procmail rules. While procmail sees the header

Subject: =?UTF-8?B?TcOhbWUgdsSbdMWhw60gcHJvYmzDqW0=?=

the decoded form you see in email clients is not available to him:

Subject: Máme větší problém

This can be solved by adding a new decoded version of the header (each must be added separately) before the other rules in .procmailrc who will use it. Example for header Subject which we will save to after decoding SUBJECT :

# extract the header if it's MIME-encoded
:0 h
* ^Subject:.*=\?
SUBJECT=| formail -cXSubject: | perl -MEncode=from_to -pe 'from_to $_, "MIME-Header", "utf-8"'

# if the header is not MIME, just extract it
:0 hE
SUBJECT=| formail -cXSubject

# make a decision based on the decoded header
* SUBJECT ?? ^Subject:.*větší

Source of inspiration .