Server Side Mail Filtering with Dovecot and Procmail
Dovecot and Procmail Filtering
Ever wanted to do server side mail filtering without adding a bunch of extra programs to the server? With Dovecot deliver and a .procmailrc you can. This does depend on the environment you are using, clearly you must be using Dovecot for IMAP or POP3 and procmail as you LDA (Local Delivery Agent). If you are not using these you should probably try googleing your LDA and Dovecot.
I'm not going into the details of installing these apps and I'm only talking about my setup, well, the setup that works on my server (which also has spamassassin installed) so lets just get on with it.
EDITOR = your favourite editor, emacs, vi, nano.
First create a .procmailrc and setup some basic assignments:
DELIVER="/usr/libexec/dovecot/deliver" (should point to your copy of the deliver program!)
Once that is done we can pipe stuff to $DELIVER. Now we need to add some recipies. Recipies require an knowledge of regular expression, again, I'm not going into the details of this here. If you are here you probable already know enough about REGEXP to get by! So lets add a recipe to send all mails less than 25600 bytes to spamassassin.
* < 256000
Now all messages less than 25600 bytes will go through spamassassin! I trust spamassassin completely having monitored its performance for weeks so I dump eveyting its marked as spam to the null device:
* ^X-Spam-Flag: YES
* ^Subject: \*\*\*SPAM\*\*\*
To filter messages into POP3 or IMAP folders use a recipe like this:
* ^From: .*steve.*
| $DELIVER -m Steve (Steve is a case sensitive name of a mail folder)
As you can see its actually quite easy to setup providing you have the right software installed!
That easy eh?