Mailfilter is a very usable tool. It helps you to keep spam away from your mailbox. Contrary to the filtering with procmail, mailfilter filters the mail online. This means that mailfilter deletes unwanted spam directly from your POP3 account before fetchmail (or your favourite POP3 client) even sees it. This is different from procmail, which zaps the spam after it's been downloaded and is about to be put into your mailbox. (Examples of using procmail are in a recent Linux Gazette article, http://linuxgazette.net/issue62/okopnik.html.)
The benefit from that is that you won't download the spam anymore. This saves bandwidth and makes you a lot happier especially if you have a slow Internet link.
Mailfilter is a very good tool, easy to install and easy to maintain. You can add it to your .fetchmailrc as well, thus automating the procedure of deleting unwanted spam before downloading.
Installing mailfilter is very easy. Just download mailfilter as source (.tar.gz file) from http://mailfilter.sourceforge.net/ and follow the following steps.
To run mailfilter, just type mailfilter on the prompt. Watch out! Mailfilter needs a valid configuration file to work properly.
You can download a sample copy of this file from mailfilter.sourceforge.net, - but we will create this file from scratch here.
Each user who wants to use mailfilter, needs a configuration file. this file is called .mailfilterrc. It has to be located in the home directory of the user.
Follow these steps to create the file and make it (at least a little bit) secure.
Now we need to add some content to the configuration file. Mailfilter will refuse to work if the configuration file is missing.
Lines beginning with a # are comments and thus ignored by mailfilter. Empty lines are ignored as well.
The most important part of the configuration file contains information of your mail account. Just add the following lines to the mailfilterrc file. You may specify more than one account.
Currently, mailfilter only supports POP3 accounts.
It is important not to change the order of the lines.
Another important option is to specify a logfile using the following line.
Now, you'll have a very basic configuration file. Mailfilter now will run but it won't do anything useful on the mail.
This is the trickier part of the mailfilter configuration. We will now add commands to actually do something useful with our mail.
This is done by adding special command lines to the configuration file. Mailfilter uses regular expressions for the filtering.
To do this, add the following line to your configuration file.
Be careful! mailfilter will not try to interpret ``v i a g r a'' as viagra so blanks are not normalized.
This is easy. Add the following line to your configuration file.
This will become handy if you receive spam from the same address. Use the following syntax:
You may kill spam from entire domains as well. Use this syntax to achieve that:
As you can see, the way to tell mailfilter what to do follows an easy to use scheme. You may block mail by CC, BCC, TO as well.
This feature allows mailfilter to ignore mail sent by a specific person even if one of the other filters would apply.
You may apply this to specific subjects as well. If a spammer starts talking about mailfilter, for example.
Fetchmail has a feature to call filter programs before fetching the mail. Add the following to your .fetchmailrc to call mailfilter every time you download your mail.
preconnect mailfilterReplace mailfilter in the line above with the complete path and the name of the mailfilter binary. /usr/local/bin/mailfilter for example.
Be careful! If mailfilter fails (config file damaged, password wrong, etc.), fetchmail will not connect. So test your mailfilter configuration standalone each time you add a new directive.
Mailfilter is a very good tool. I wasn't able to force fetchmail to filter in the body of a mail. But at least, it allows working spam protection if the addresses of the spammers are valid.
This works very good and I can only emphasize: give mailfilter a try,
especially if your Internet link is slow and you receive a lot of spam.
I'm a Linux enthusiast from northern Germany.
I like plain old fifties rock'n'roll music, writing
stories and publishing in the Linux Gazette, of course.
Currently I'm studying computer science in conjunction with
Copyright © 2001, Matthias Arndt.
Copying license http://www.linuxgazette.net/copying.html
Published in Issue 67 of Linux Gazette, June 2001