User Tools

Site Tools


userdoc:ece_email:filtering_with_procmail

Why Use Procmail

Many people who have to deal with large amounts of email find it useful to automatically filter incoming messages. This can include saving messages to separate folders, redirecting email elsewhere, or doing even fancier preprocessing, all without starting up any email client program such as Thunderbird or Alpine. The Usermin web interface makes it easy to create a procmail script to filter incoming email, but filtering rules must take into account the conventions used by the IMAP server which delivers the messages to email client programs.

Server User Settings using Usermin web interface

Procmail Compatibility

The ECE Dovecot IMAP server uses several directory name conventions, particularly with respect to the period (“.”) character: first, the names of all directories containing email messages must begin with “.”, and second, that any other “.” character in a directory name marks a subfolder separation. Thus, for example, a *nix directory named “.CourseWork” will be presented as a folder named “CourseWork” when viewed by a client email program, while a directory named “.CourseWork.2014” (note that this is just an oddly-named directory, NOT an actual subdirectory) will be presented as a message-containing subfolder named “2014” within a folder named “CourseWork”. The procmail filtering program has no intrinsic knowledge of this convention, though the Usermin web interface to procmail can help somewhat, and any procmail rules as written must be compatible or else it will be inconvenient or impossible to access the filtered messages.

Setting Up Procmail via Usermin

The Usermin web page offers two different means of editing procmail rules. The “Mail” option in the upper-left, when expanded, offers “Filter and Forward Mail” and “Procmail Mail Filter” options, both of which allow you to modify your procmail rules. “Filter and Forward Mail” is more straightforward, and will not allow a malformed rules file, while “Procmail Mail Filter” is intended for more complex processing, such as checking for a set of matches in different header lines, and even allows procmail experts to have direct editor access to the rules file, with all the power and possibility for disaster which this implies. The “SpamAssassin Mail Filter” option is not directly related to procmail, and will be described elsewhere.

Filter and Forward Mail

“Filter and Forward Mail” initially starts with a mostly-blank page (since there are initially no filtering rules) except for the links which take you to the set-up pages for “Quick automatic reply setup” (e.g. for a vacation message), “Quick forwarding setup” (to forward EVERYTHING to another account), and the more interesting “Add a new email filter”. Once rules have been added, they will be displayed here and it will be possible to adjust the order in which the conditions are checked. But note that only “simple” rules will be displayed here: more complex ones, entered via the “Procmail Mail Filter” page menus or manually, will not be shown.

Add a new email filter

On the “Add a new email filter” page, ignore the misleading indentation and choose one bullet each from the Condition and Action sections. Most filtering will be based on the content of a particular line in the message header, and both the specific header line and the required contents can be either chosen with simple matching or by providing a full regular expression. The choice of Actions includes regular delivery, spam classification and message deletion, forwarding, saving the message to a particular folder, or sending an automatic reply. For Actions which save the message, existing folders can be selected from the drop-down menu, and email client programs such as Thunderbird may have already created some folders. A new destination folder must be entered carefully, for the naming reasons described above: be sure to include the leading “.” in the name, and don't use any additional “.” characters unless specifying a subfolder. Finally, be aware of the selection box in the lower left, labelled “Continue with other filter rules, even after applying this action”: if this box is empty, no further action will be taken with any message which has matched this Condition, and this is usually what is desired when filtering messages to different folders. On the other hand, you should tick this box when testing new Conditions, and it can also allow “teeing”: multiple rules with a duplicated Condition section can trigger muliple Actions for the same message, such as saving in a folder AND triggering an autoreply.

Procmail Mail Filter

It's not a big step from simple filters to using some of the options available here, such as setting Conditions which depend on multiple different mail header lines. The editing page is somewhat perversely laid out, with the Actions section at the top and the Condition(s) at the bottom.

At the bottom of this page is the “Manually Edit Configuration” button. Be Careful.

userdoc/ece_email/filtering_with_procmail.txt · Last modified: 2014/01/22 21:33 by peterp

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki