Dealing with Unsolicited Commercial Email

Just ignoring UCE is not going to make it go away and address munging in usenet postings is for lusers. What you really need to do is complain. There are a couple of perl scripts here to make this easier and more automated.

Spam

Spam is a perl script designed to be invoked from by procmail when it encounters a UCE. It requires Andrew Gierth's News::Article perl module (available from CPAN) to work. You need to set a few variables at the top of the script to customise it for your installation. You also need to change the regular expression that matches whatever machine initially receives your mail. (This should match your MX records essentially). In the example (which should work with Demon Internet) the line you need to change is line 51. Which looks like:


if ($by =~ /punt-\d+\.mail\.demon\.net/) { 

You need to change punt-\d+\.mail\.demon\.net to something suitable for however mail arrives at your machine. If you're not a regular expression person you should just be able to look up the domain portion of your email address and look for any MX records. Then just OR them together; ie /(mx.address.one|mx.address.two|mx.address.three)/.

Spam should be invoked from procmail something like this (I have several procmail recipes that tag email with the header X-Spam: some reason so anything with this header gets sent through the script):


:0
* ^X-Spam:
{
        :0 c:
        junk-`date +%b-%Y`.spool
        
        :0 
        | /home/smd/bin/spam
}

Here all the UCE my filters catch gets put in a junk folder and piped to the script. The script parses the received lines to find out the hostname of the machine that passed the email to your MX receiver, and then looks the hostname up in abuse.net's whois server to find the right address to complain to. You can also pipe emails through it by hand (ie just do cat email | spam) but you need to be connected to the internet at the time so it can look up IP addresses and abuse addresses.

It is possible if your MX runs some weird software it might not be able to parse the received lines correctly. I've only been able to test it with sendmail and exim. If it fails with your UCE you're welcome to send me an example or two of the sort of headers used and I'll try to adapt it to cope.

If your home directory is NFS mounted onto the machine you run the script on then you could find the spool area getting corrupted due to a small race condition. If you find this is a problem then you need to replace the flock() calls with something more NFS safe.

Complain

Spam is only half the story. It simply spools UCE complaints in whatever directory you chose. Complain allows you to check the complaint and view/edit/send or forget it. Again there's a couple of variables you need to edit at the top of the script to reflect your local installation.

If spam has generated reports simply type complain and it will cycle through the reports asking you if you want to edit, view, send or forget the complaint. If you decide to send or forget the complaint then the spooled version is deleted.

The idea behind this is to at least make a cursory check that your filters have actually got it right before mailing off complaints to various people.


Home