An AppleScript rule to check Mail against blackhole lists

May 27, '03 08:47:00AM

Contributed by: DaveCC

Do you use Apple's Mail program? Do you like it's junk filter, but wish it were just a bit better at catching spam? Well, this hint contains an AppleScript Mail filter (it's called SpamHolio, download (8KB)from macosxhints.com) that checks each new email's originating IP address against various real-time black hole lists (RBL) of known Spammers and Open Relays (ie. Spamcop, SPEWS, ORBS). If the sender's IP is listed in one of the checked against RBLs, the email is marked as junk and moved into the Junk mailbox for you.

This is a nice compliment to the built in Junk Filter which can occasionally miss new variants of spam that others have already discovered and reported to a RBL. You can think of this as a way of tapping into the insight of a larger pool of spam screeners beyond yourself. Just create a new filter that uses the following rules:

  If [All] of the conditions are met:
  [Sender is not in my Address Book]
  Perform the following actions:
  [Run Apple Script]
On the last step, you'll be asked to choose the location where you've saved the script. Ideally, you would prioritize this filter below the built in Junk filter in case it misses a spam that is otherwise known to the black lists (as defined in the AppleScript). For testing purposes (to make sure it is working well), you can put it above the built in Junk filter in the filter processing order to better keep tabs on what it is catching.

[robg adds: I've been running this script for a few hours now, and it's quite impressive. I usually receive anywhere from 150 to 200 spams a day, with Mail catching about 80% to 90% of them. Unfortunately, that means anywhere from 15 to 40 or so junk mails left in my inbox.

I've received about 20 since installing SpamHolio, and between it and Mail's junk filter, not a one has made it into my inbox! Read the rest of the article for some important information on customizing the filter. In addition, you'll have to edit the script if you have renamed you Junk Mail box (I have renamed mine to "zzz Junk," so it drops to the bottom of the list).]

User definable options (requires editing of the SpamHolio AppleScript):

This isn't very elegant AppleScript code, but it was my first AppleScript program and I hope others find it useful. I plan to add additional features in the future such as: a GUI preference configuration panel, more sophisticated and faster IP parsing, and more generalized and intelligent nslookup output parsing. Feel free to add to the code and improve it as you see fit; any suggestions or tips/code optimizations would be appreciated.

If you really like this AppleScript, please contribute some money to worthy organizations like SpamCop or C.A.U.S.E. or some of the other valiant anti-spam organizations out there.

Comments (44)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030523090008320