SpamAssassin and OS X

Well, I’ve been working on getting SpamAssassin working with Mac OS X, and have gotten it working pretty good. Either just to filter spam for the computer, or for an entire network.

Note: This to the best of my knowledge works correctly… But this is at your own risk. I have only tested this one one system. If there is a problem, removing the SAProxy directory from the StartupItems should resolve any issues. If it locks on startup, boot off of another disk (I perfer a Mac OS 9 CD), then remove that directory.. It will disable SpamAssassin, but allow you startup and use your computer as it was before.

The first thing to do is install SpamAssassin. Here is what needs to be done.

This guide assumes you have Developer Tools already install (that grey CD that came with Mac OS X). You can download it at:
http://connect.apple.com

First we need to install a few modules.

These modules are required for spamassassin to build:

  • ExtUtils::MakeMaker >= 5.45 (from CPAN, or included in Perl 5.6 and higher)
  • File::Spec >= 0.8 (from CPAN, or included in Perl 5.6 and higher)
  • Pod::Usage (from CPAN, or included in Perl 5.6 and higher)
  • HTML::Parser >= 3.0 (from CPAN)
  • Sys::Syslog (from CPAN)

Ben Trott’s article will show you how to install those quickly. Do only step 2, and only for the modules above. Ignore him for the rest, he is installing it a bit differently.

Now we need the latest SpamAssassin distribution. It can be found on the downloads page. Copy the URL of the latest version to the clipboard. Then open terminal and enter the following (note the URL syntax may be slightly different depending on the version. This is for 2.53):

curl -O http://www.spamassassin.org/released/Mail-SpamAssassin-2.53.tar.gz

The next step is to expand this download (again note the file name might be slightly different:

gnutar xzf SpamAssassin-2.53.tar.gz

Then cd to the directory (once again, the directory name may be slightly different, check that version number) and run the makefile script:

cd SpamAssassin-2.53perl Makefile.pl

This should be somewhat quick, a minute or two.

make

This will take a bit longer. Don’t worry about all the garbage on the screen. That’s because the authors love the matrix 😉 As long as there are no errors, your looking good.

sudo make install

You will need to enter your password, do so… then in a minute or so it will be complete.

That was the worst part…Not bad eh? You can now delete the SpamAssassin-x.xx directory, and the compressed archive you downloaded earlier… They are no longer needed.

Now to create the proxy.

Again, in terminal
Create a directory on the root of your hard drive, name it “saproxy”. Then open it:


cd /
mkdir saproxy
cd saproxy

Now we need to install the proxy script.


pico pop3proxy.pl

Now in your web browser, copy and paste the contents of this page into the terminal window

pop3proxy.pl

Control “O” to save the file, say yes to changes.
Control “X” to quit pico

Once again for the kill script:


pico kill_proxy.pl

And the source for this file can be found here:
killproxy.pl
Paste it in, save the file, and exit pico

Now we get to decide how to run it.

Create a directory named “SAProxy” in the StartupItems folder:


cd /Library/StartupItems
mkdir SAProxy
cd SAProxy

Now create a file named SAProxy

sudo pico SAProxy

Paste the following into it:


#!/bin/sh
#
# *********************************************************************
# ** /Library/StartupItems/SAProxy/SAProxy **
# *********************************************************************
# ** **
# ** This is the intialization script for SAProxy services on Mac OS **
# ** X. The permissions of this file need to be set to 0755. This **
# ** can be accomplished from the Terminal while in this directory **
# ** by typing: chmod 0755 Samba This will adjust the properties so **
# ** that it can be executed. **
# ** **
# ** To configure SAProxy to launch: as root, edit the file **
# ** /etc/hostconfig at the very end enter: **
# ** SAPROXY=-YES- You can easily change this entry to enable **
# ** or disable SAProxy whenever you like. **
# ** **
# ** **
# *********************************************************************
# Robert J. Accettura robert-at-accettura.com
# @ April 13, 2003
#

# ---------------------------------------------------------------------
# Include system wide configuration options
# ---------------------------------------------------------------------
. /etc/rc.common


# ---------------------------------------------------------------------
# Start SAProxy services
# ---------------------------------------------------------------------
if [ "${SAPROXY:=-NO-}" = "-YES-" ]; then

ConsoleMessage "Starting SpamAssassin"
#to use as server comment the line before (add a "#" to the beginning), and uncomment the one below (Remove the "#")
/usr/bin/perl /saproxy/pop3proxy.pl &
#/usr/bin/perl /saproxy/pop3proxy.pl -listenall &

fi

Note: If you want to use it as a server, that other computers on a network can connect and filter mail, read the file for the /usr/bin/perl line, and adjust accordingly

Save (control “O”), and exit pico (control “X”)

Now we need to set the correct permissions for the file:
sudo chmod 0755 SAProxy

Enter password if asked

Now for the StartupParameters.plist file

o StartupParameters.plist

Paste this in there:


{
Description = "SpamAssassin Proxy";
Provides = ("SpamAssasin");
Requires = ("Resolver");
OrderPreference = "None";
Messages =
{
start = "Starting SpamAssassin";
stop = "Stopping SpamAssassin";
};
}

Save and exit

Set the permissions for it:


sudo chmod 0644 StartupParameters.plist

Reboot

Now to configure a mail client, you need the following:

Username user:host.tld
[That is your username for your ISP’s email account, and the host server. For example “robert:mail.accettura.com”]

Your server is now “localhost”. If your running it on a different computer than the mail client, enter the appropriate IP address.

That’s it.

Sidenote: Hopefully we can get this packaged as a distribution soon, so these directions will be pointless.

Leave a Reply

Your email address will not be published. Required fields are marked *