Most electronic mail clients support storing mail in folders; all of these which I used support filtering new mails into appropriate folders. When mail is divided into several folders, e.g. for some mailing lists to which I’m subscribed or for some automatically sent messages, it is easier to manage it. I prefer to read more important mail before the less important one (or less important first?) and these folders make it nicer.
It’s fine with one computer running a mail client, but the situation becomes more complicated with two computers. Then IMAP is necessary (excluding the use of webmails, but they usually use only a single computer). It is the protocol which stores mail on the server, is fast and allows realtime notifications for new messages (this feature is not currently supported by Kmail, but is planned).
I use IMAP since I first configured my mail server. Initially because most free software webmails require IMAP, but about a year later I began to access my mail from two computers. The filters were done by only one of the mail clients, so they became less useful. I could have configured them on both of my client computers, but it would require sharing the settings.
I have only one mail server, so I decided to filter the mail on the server. Quickly I found the well-known Procmail program used for that. Since I use Gentoo GNU/Linux operating system, I installed the mail-filter/procmail package. To my Postfix SMTP server configuration file /etc/postfix/main.cf I added
mailbox_command = /usr/bin/procmail
just as the comment in the file shows (as stated by the comment, I forward root’s mail to my normal user). Then the command /etc/init.d/postfix reload requested Postfix to reload the configuration file.
In my home directory I put a file .procmailrc instructing Procmail what to do with my mail. It begins with
MAILDIR=$HOME/.maildir/ LOGFILE=$HOME/.procmaillog LOGABSTRACT=no VERBOSE=off
which contains generic parameters used by Procmail. I use maildirs with the default Gentoo path of $HOME/.maildir. For all maildirs the trailing slash should be used in Procmail configuration, since it specifies the file format. I learned it by finding an mbox file when the slash was omitted.
Then specific recipes are stated. One of the ones which I use is
:0 * ^From: *forum-mods@gentoo\.org$ $MAILDIR/.gentoo-forums/
The first line begins with :0 and may contain specific flags which I don’t use in this recipe. The lines beginning with an asterisk contain an extended regular expression which is by default matched in the mail headers (in this case the sender address). If all conditions are satisfied, then the action specified in the last line is performed. Here it moves the mail to the gentoo-forums folder in my mailbox.
I don’t use more complicated recipes in my .procmailrc file. See the procmailrc(5) man page for the complete syntax of these files. Features explicitly stated in the man page look similar to filtering features of the Kmail mail client, but there are much larger possibilities.
