Server-side spam filtering for Mac OS X Leopard

Posted by Christian Noack on 2008-02-28
Words 883 and Reading Time 5 Minutes
Viewed Times

Wer auf seinem Mac die Mail-Server-Software Mail Serve Pro einsetzt wird sich auch wünschen Spam-Mails direkt auf dem Server zuverlässsig heraus filtern zu können. Bislang war das ohne Mac OS X auf dem Server nur mühsam möglich. Mit etwas Recherche ist es mir nun gelungen, die Spam-Filtering-Software Spam Assasin auf dem Server so zu installieren und konfigurieren, dass sie mit MailServe Pro zusammenarbeitet und neben dem Server-seitigen Spam-Filtering auch die Client-seitige Filterung von Spams im Mail-Client Mail.app von Apple unterstützt. Wie das geht habe ich im folgenden Tutorial beschrieben:

Tutorial for enabling server-side spam filtering with MailServe Pro on Mac OS X Leopard (client version)

I decided to do spam filtering using procmail with spamassassin .On my server I installed the current version of MailServe Pro and the current version of SpamAssasin. The last one I installed with MacPorts.
There are some steps to do to make spammassassin work. In /opt/local/etc/mail/spamassassin/ (if installed with MacPorts) are some sample files. Just copy them to the same directory without the .sample-ending. Find out the version of spamassasin (spamassassin -V). Remove the vXXX.pre files that don’t match the version. Now for your users that should have spam filtering do spamassassin –lint -D. Procmail is already installed on OS X Leopard. You just have to configure it. You need a systemwide procmail configuration file. This is my /etc/procmailrc (on the server)

1
2
3
4
5
6
SHELL=/bin/sh
MAILDIR=$HOME/Mail/Dovecot/
DEFAULT=$HOME/Mail/Dovecot/
LOGFILE=$HOME/Mail/procmail_log
VERBOSE=on
INCLUDERC=$HOME/.procmailrc:0 w$DEFAULT/

It does no spam filtering. It just delivers your e-mail to your inbox in Maildir format as DoveCot uses it. Every user that wants spam filtering must have it’s own procmail configuration file .procmailrc in his home directory. This is what mine looks like:

1
2
3
4
5
6
7
SHELL=/bin/sh
MAILDIR=$HOME/Mail/Dovecot/
DEFAULT=$HOME/Mail/Dovecot/
LOGFILE=$HOME/Mail/procmail_log
VERBOSE=on
ASSASSINLOCK=$HOME/Mail/assassin.lock
LOCKFILE=$HOME/Mail/lockfile.lock:0fw: $ASSASSINLOCK* < 256000|/opt/local/bin/spamassassin:0H:* ^X-Spam-Level: \*\*\*\*\*\*\*\*\*\*.Junk/:0H:* ^X-Spam-Status: Yes.Junk/

Every incoming mail is scanned and if it’s spam it is put into the Junk-Folder. If in some weeks you’re shure it works, you may replace the first .Junk with /dev/null. This makes procmail removing e-mail which is 100% classified as spam completely from your mail server.Now you have to enable MailServe to use procmail for delivery. Modify the file /usr/local/cutedge/postfix/etc/main.cf.default on your server. Remove the #-sign at the beginning ot the following line:

1
mailbox_command = /usr/bin/procmail -a “$EXTENSION”

Do not modify /usr/local/cutedge/postfix/etc/main.cf,because this is overwritten everytime Postfix restarts.To check whether it works restart Postfix from the MailServe application and aftwards send yourself e-mails and have a look at your procmail_log configured in your .procmailrc. To send yourself spam mail take the body from this location: http://spamassassin.apache.org/gtube/. If anything went wrong quickly comment out the mailbox_command line mentioned above and restart postfix. Then search for errors.If everything works spamassasin can and should be trained. Therefore I put two entries in my user’s crontab (do crontab -e). Yours should look similar to theese:

1
2
30      1       *       *       *        date >> $HOME/Mail/spam.log; /opt/local/bin/sa-learn –no-sync –spam $HOME//Mail/Dovecot/.Junk/{cur,new} >> $HOME/Mail/spam.log
35 1 * * * date >> $HOME/Mail/ham.log; /opt/local/bin/sa-learn –no-sync –ham $HOME//Mail/Dovecot/{cur,new} >> $HOME/Mail/ham.log

Everything in your inbox is good (ham), everything in the Junk-folder is bad (spam). This is trained once a night at 1:30 am.Now you have to tell Mail.app to store spam on the server. You can do this in the account configuration. Mail.app put’s recognized spam into the Junk-folder on the IMAP-Server (MailServe Pro with DoveCot). So you have two-side filtering. If in Mail.app you decide a mail classified as spam is not spam, just mark it as being no spam with Mail.app. It will be moved to the inbox then. Spamassassin will learn the following night, that this is no spam.The huge advantage is that I can use my mobile phone and my mail web client (squirrelmail on the same server) to read mails when I’m on the road and still have spam filtering wich you do not have if you filter only on client side. The other advantage is that your personal classification of what is spam and what is not can still be done in Mail.app as before.