Jaguar Compatibility

September 2002 -- Unfortunately as of the 10.2 release, Apple has seen fit to remove from Mail.app the capacity to read UNIX-style mail spools. The fetchmail/procmail regimen probably still works as descibed below (haven't checked) but you won't be able to read the results of your filtered mail in Mail.app anymore. This is probably not a good reason to avoid upgrading to Jaguar, but you'll have to make your own choice. Note that Mail.app now has niftier anti-spam features on its own. Below is the original procmail/fetchmail documentation for OS 10.1.X, maintained here for historical reasons.

-----------------

Why you might want to do this

Email filtering. Spammers suck. The filtering tools deployed with OS X Mail.app and Entourage X are quite flaccid. By contrast, there are filtering tools available in the subsystem of OS X that are incredibly powerful. What we're going to do here is learn to take advantage of those tools.

Software you must install

None whatsoever. All the sw referenced in this article is included in the standard distribution of OS X as of the 10.1 release, though it cannot be accessed through the Finder. Also, we won't be turning on sendmail or any other network services.

There is a certain skill level. I hate UNIX snobbery, and I'll try hard not to condescend to you, but if you are an absolute virgin this is not the best place to start. You need to be able to move around in UNIX directories, and edit text files with pico, and set permissions. You need to know what a daemon is. And of course if you don't have a basic understanding of procmail recipes, the whole exercise is somewhat pointless. =^ )

What we're going to do

Instead of using Mail or Entourage to download and (barely) filter your email, we're going to use UNIX fetchmail to pull the mail down, and filter it with procmail. Unlike OS X Mail, Microsoft Entourage cannot read a standard UNIX mail spool, so if you do it this way, you can't use Entourage to read email.

What is fetchmail?

All fetchmail does is poll your ISP and download your mail, then deliver it to the first mail agent it can detect on your system. In OS X, the first mail agent fetchmail will detect is procmail. That's perfect.

What is procmail?

Oh, my, let's talk. =^ ) What procmail does is filter email, that's all it does, and it is incredibly powerful. It can do pattern matching, weighted scoring, blacklist lookups, re-write headers, and pipe its output to other programs for further processing. There are effective spam protection services written entirely in procmail and updated on a regular basis (i.e. www.spambouncer.org). If that's not enough, when configured just so, procmail can do fun email bouncing tricks. Nothing like it exists in the Windoze or Macintosh world. You need it. Let's get started.

STEP ONE

Create a mail spool: Just create a file /var/mail/localuserid (where localuserid is your username). Set the permissions to 0700.

touch /var/mail/localuserid
chmod 0700 /var/mail/localuserid

Note that this file might foul up sendmail if you choose to turn it on later; delete the file if you want to turn sendmail on. If you don't know what sendmail is or why you might want to turn it on, don't worry about it, just proceed.

STEP TWO

Get procmail working. Fetchmail cannot do anything with the mail by itself, it has to hand it off to a mail agent, so let's make a .procmailrc file in your home directory that will deliver the mail to the right place.

# sample .procmailrc file

SHELL=/bin/sh
DEFAULT=/var/mail/localuserid
LOGFILE=/Users/localuserid/procmail.log
:0:

$DEFAULT

Obviously, replace localuserid with your username on the OS X box. Note that it is not necessary to make a .forward file the way we're doing things, so don't make one if you read about it in other procmail documentation.

STEP THREE

Get fetchmail working. Construct a valid .fetchmailrc file in your home directory. In the example below, localuserid is your username on the OS X box, remoteuserid is your username at your ISP, password is your POP3 password at your ISP, and popmailserver is your ISP's POP server:

# sample .fetchmailrc

set postmaster localuserid

#
# set daemon 300        # poll every 300 seconds
#

poll popmailserver with proto pop3 user "remoteuserid" there with password "password" is "localuserid" here options stripcr

That last bit, options stripcr, is going to correct for a cross-platform line ending problem.

STEP FOUR

Set up a UNIX account in Mail.app: First, create a directory in ~/Library/Mail. Call it anything, but no spaces. Set the permissions to 0700:

mkdir /Users/localuserid/Library/Mail/somedir

chmod 700 /Users/localuserid/Library/Mail/somedir

Now, create a new account in Mail.app. Account type is "UNIX Account". Set the first pane of the dialog up like the one in your POP account. Click to the second pane, "Account Options". Leave the first field set to "/var/mail". In the second field, enter the path to the directory you created a minute ago:

/Users/localuserid/Library/Mail/somedir

Note that Mail.app won't let you edit this dialogue after you close it, so get it right the first time, or else you'll have to delete the account and start over.

How to use it

Run fetchmail from the command line. This should deposit your mail in /var/mail/localuserid. Then just "Get Mail" in Mail.app as usual.

If you're using a persistent connection (DSL, cable modem, LAN) you can uncomment the lines in .fetchmailrc that tell fetchmail to run in daemon mode; this way it will check for new mail every five minutes whenever you are logged in (you'll have to start fetchmail when you log in. Doing this automatically is left as an exercise for the reader).

You've already noticed that none of this does any email filtering at all. It doesn't! Well, key man procmailex, man procmailrc, and memorize everything linked from www.procmail.org. Have fun, and happy anti-spamming!

April 17 2002--See also the site of Mr. Charles Eicher, who expands upon these instructions and tells you how to install the Spambouncer too. Nice work.

Thanks to Greg Jorgensen for cleaning up my poor HTML.