translated by Google

Machine-translated page for increased accessibility for English questioners.

What is procmail?

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

.procmailrc

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:

:0
* ^From.*adam
adambox

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 , which searches FI for mailboxes in the directory ~/mail/ , add to the beginning of the file .procmailrc line

MAILDIR=$HOME/mail

The rule always starts with a line where the first character is ":" followed by a list of flags that describe the processing of the message, ie whether the message body should be checked in addition to headers, whether the message should be forwarded to other rules and so on after processing actions (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 must be left there.) Failure to specify any flags means that we expect default functionality (most importantly, only message headers are checked, not the body ). The second line is a condition that describes to which messages the rule applies. Each condition is located on one line, starting with a "*" and everything after it is interpreted as a regular expression (POSIX 1003.2 RE) compatible with the extended regular expressions of the egrep program (see the manual 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 rule for procmail, which stores all incoming mail in the mailbox myspool :

:0
myspool

A more complicated example:

:0 c
* ^From.*peter
* ^Subject:.*compilers
! william@example.com
    
:0
* ^Subject:.*perl compilers
perlcomp

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 forwarding the message to the address william@example.com . 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 a file .forward , that is, preserving the sender's envelope address. See below for an example of the setting. Note: there are always two white characters in the square brackets: a space and a tab. String Xuzivatel replace with your login, e.g. Xnovak29 .

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

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

    :0
    ! ${env+-f "$env"} honza.uzivatel@example.com
}

In the faculty environment, the main difference 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're reading a text version of your mail, you may be disturbed by signatures or logos that appear as attachments to HTML messages, even if it's not an attachment that you should pay attention to. For repetitive 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:

:0fW
| /usr/local/libexec/image-attachment-filter.pl

Then you need to create a file ~/.image-attachment-filter.cfg where you place the SHA-256 hash 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 count the hashes of other attachments you want to delete).

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

Rules for coded headers

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

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

the decoded form that you see in e-mail clients is not available to it:

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 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
:0:
* SUBJECT ?? ^Subject:.*větší
bigger

Source of inspiration .