[Important note to readers: before trying any of the tips or tools listed on this website, make sure you have a full backup of all data on your computer. These tips have all been tested, but there's always a chance that you'll lose data in the process, so be safe and backup!]
Setting up SpamAssassin and razor in Mac OS X Tiger server. (posted: 2-15-06 10:52 PM)
The SpamAssassin software that comes bundled with Mac OS Server 10.4 (Tiger) server can be very powerful and accurate. However, it needs a little tweaking from its out of the box configuration to unleash its full power. Here's what I hope is a simple step-by-step how-to, to enable SpamAssasin with Razor in Tiger server (be sure to backup your system, or at least make copies of any files you're modifying before starting!):
sudo -s
cd /var/amavis
mv .spamassassin .spamassassin.old
su clamav
ln -s /var/clamav/.spamassassin /var/amavis/.spamassassin
When you've done this, do 'ls -la' and you should see a line like this:
lrwxr-xr-x 1 clamav clamav 25 Feb 8 21:51 .spamassassin -> /var/clamav/.spamassassin
spamassassin --lint
If you're running 10.4.2 - 10.4.4, you might see output similar to:
config: SpamAssassin failed to parse line, skipping: auto_learn 1
config: SpamAssassin failed to parse line, skipping: safe_reporting 0
config: SpamAssassin failed to parse line, skipping: use_terse_report 0
config: SpamAssassin failed to parse line, skipping: subject_tag *** Warning: Junk Mail ***
config: SpamAssassin failed to parse line, skipping: rewrite_subject 0
lint: 5 issues detected. please rerun with debug enabled for more information.
To fix this, first backup your '/etc/mail/spamassassin/local.cf' file, then open the file and change any of the above output, as follows:
change 'auto_learn' to 'bayes_auto_learn'
change 'safe_reporting' to 'safe_report'
comment out 'use_terse_report 0'
comment out 'subject_tag' and 'rewrite_subject'
Now issuing 'spamassassin --lint' should just kick you back to your terminal prompt without any feedback. If so, you're all set.
$sa_local_tests_only = 0;
I like to set this to 0 (disable), in order to enable network tests by tools such as razor, which can dramatically improve SpamAssassin's accuracy. See below for more details on using Razor.
$sa_tag_level_deflt = -999;
This low threshold causes SpamAssassin to add X-Spam headers to all local messages scoring above -999, which should be all of them.
$sa_tag2_level_deflt = 5;
This is the SpamAssassin score at which to consider a message spam and tag it as such (by modifying the subject line), a good starting point is about 5
$sa_kill_level_deflt = 10;
If a message's SpamAssassin score reaches this level, then the 'final_spam_destiny' action is taken. I like to set this to around 10, depending on what 'final_spam_destiny' is. Remember, if 'final_spam_destiny' is set to reject mail, this is the score at which the mail will be rejected. I like to start out with the 'D_PASS' setting for starters, which delivers the mail even if this score is reached (see below for more info on the 'final_spam_destiny' setting).
$sa_spam_subject_tag = '*** Junk Mail ***';
When a message's SpamAssassin score reaches the '$sa_tag2_level_deflt' score (above), then the text here is added to the beginning of the email subject line.
$final_spam_destiny = [D_DISCARD,D_BOUNCE,D_PASS];
This tells SpamAssassin what to do with a message that reaches the '$sa_kill_level_deflt' score. It can be set to one of the three values above (so, for example, to deliver all mail, the line would be $final_spam_destiny = D_PASS;).
@local_domains_acl = [acl]
This line tells SpamAssassin which email domains are hosted by the local system, and thus which ones to take action on. Make sure all possible local domains that will be handled by your mail server are listed here. An example would be:
@local_domains_acl = ( '.myDomain1.com', '.myDomain2.com', '.myDomain3.com' );
OK: next, if you run virtual domains, make sure this line is uncommented (i.e. no '#' sign at the beginning of the line):
@local_domains_maps = ( 1 );
If the line doesn't exist and you need it, add it after the '@local_domains_acl = ...' line.
If you want to use razor (see below), make sure to add the following lines, if they don't already exist:
use_razor2 1
razor_timeout 10
score RAZOR2_CF_RANGE_51_100 4.0
Whew! OK we're done with the '/etc/amavisd.conf' file.
After you've set up these accounts, you need to redirect (be sure not to forward!!) around 200 junk and non-junk messages (around 400 total) to each mailbox. This is crucial, and if there aren't enough messages in there, SpamAssassin will be pretty inaccurate. One way to make it easier to feed the boxes is to setup the two IMAP accounts in your mail program. Then you can just drag and drop junk mail from your real account into the inbox for the 'junkmail' account (and likewise for the 'notjunkmail' account). This is a lot easier than the mass redirects. If appropriate, do the same for other users on your system.
Improving SpamAssasin's accuracy with Razor:
There are many add-ons that can be enabled which really beef up SpamAssassin's accuracy, and one I like to use is Vipul's Razor. In order to install this, you'll need the Xcode 2.2 developer tools installed on your system. To get Xcode visit the Apple Developer's site, register for a free account, then download and install the tools. Once you've done that, download razor-agents and the razor-agents sdk here. Once downloaded, unpack them like so:
tar -xvjf razor-agents-2.77.tar.bz2
tar -xvjf razor-agents-sdk-2.07.tar.bz2
cd razor-agents-sdk-2.07
perl Makefile.PL
make
make test
make install
cd ../razor-agents-2.77
perl Makefile.PL
make
make test
make install
OK - now to set up Razor: if you're still in a root shell (i.e. you see a '#' sign at the end of your shell prompt), then type 'exit' and hit enter to return to your regular user shell (if you're not sure, just open a new terminal window, or ssh session if you're doing this over ssh). Then run:
razor-admin -create
which creates a config file in your user home directory. Then choose an email address with which to register razor, and do the registration:razor-admin -register -user=user@domain.com
That's it! After you've finished this setup, you should see a pretty drastic increase in SpamAssassin's accuracy.