Bob's Spam Filter
rc.spam
[ Skip directly to file ]

Finally we get to the good stuff. Time to nail those spammers! Here's the heart of the whole process. Before we actually kill the mail, however, we put in a few safeguards.
First, we provide a backdoor for some messages to get through. Any mail sent with the subject "spam error" will be treated as a normal message. This is in case we somehow kill a legitimate message by mistake. The information in the reply to what we thought was spam describes this method of making sure the message gets through. You can change "spam error" to whatever you like.
Second, we catch bounced messages. Many of the replies we sent back to spammers will bounce, since they often use faked addresses. To catch these, we first look for messages that didn't make it through the sending process. On the Taylor system, checking for a message from "Mail Delivery Subsystem" works. You may have to check to see what a bounced e-mail message looks like on your system. Once we have a bounced message, we then search the body for the field "X-Mailer", and see if the message was sent from our spam canceller. If it was, then we save the file to /dev/null. /dev/null points into oblivion, and the file winds up being deleted.
Finally, with all those safeguards in place, we are ready to process the spam message. To verify that the message is spam, I check to see if the message is not addressed to me. Rarely does a spam message actually list the real e-mail address in the "To" or "CC" field. Here I check to see if the message is (not) addressed to "bell". The reason is that I have a number of e-mail address that forward to this one account, but all have the word "bell" (my last name) in them. Replace "bell" with part or all of your e-mail address.
The next part processes the e-mail. You may want to change this line to save mail in a special folder until you are sure you have it set up correctly. As it stands, the command first sends the message through the program formail, part of the procmail distribution. It changes the headers of the message so it is addressed to whoever sent it, and removes the body of the message. It adds the "X-Mailer" field, which helps when we check for bounced messages. It adds the "From" field to read my name, but doesn't give an e-mail address (see how easy it is to fake these things?). It also updates the subject to make sense to anyone who actually reads the message, saving the old subject as "Old-Subject", in case it ever needs to be tracked.
The resulting message is sent through the standard Un*x program cat. This simply adds a body to the message. See my message here. Lastly, the whole things is processed by sendmail, another common Uni*x program. Note that you may have to specify the full pathnames of these programs, but I didn't.
I've included a sample file below for you to look at. Download it here.


Page URL:
Author: Bob Bell
Last modified:
Written in the vi editor