Advertisment

Spam Busting on Linux

author-image
PCQ Bureau
New Update

Two commonly used mail clients on Linux are Kmail and Ximian’s evolution. However, they have very rudimentary filtering techniques built in, such as test matching the subject, header, and body. These are not very effective in blocking spam, and their accuracy levels wouldn’t be more than 70%. To improve this accuracy you need more sophisticated filters, which have an in-bulit learning system. One such popular system is SpamAssassin. Another system called Razor is loosely based on RBL or real-time black hole lists to identify the origins of spam. Such systems use distributed databases of the identified spam and act accordingly. We’ll discuss how to use SpamAssassin on a mail client.

Advertisment

Installing 



SpamAssassin 



Untar the SpamAssassin tar file provided in the Linux section of this month’s DVD as follows:

tar -xvf Mail-Spamassassin-2.53.tar 



Perl Makefile.pl 


make 


make install 

Once you’ve installed it, SpamAssassin runs from the shell prompt as follows: 

Advertisment

spamassassin < mbox > mbox_spam 

Where mbox is your mailbox file maintained by evolution or Kmail. For evolution you can find your mailbox file in /home/user/evolution/local/Inbox/ and for Kmail, it’s in /home/User/Mail/inbox 

SpamAssassin actually identifies a particular mail as spam and outputs a corresponding mail with body and subject changed indicating this is a Spam. So if the new mbox_spam is imported again to your mail client, the spam mails will be identified with an appropriate subject heading. This behavior is especially important when SpamAssassin is used on the server side and in fact is exploited by

Kmail.

Advertisment

Using Kmail 



l Install SpamAssassin as mentioned above.

l Go to Settings->Configure filters. Add a new filter, with the filter criteria set to size less than 250 kb. This is important as SpamAssassin is only able to handle mails of less than 250 kB size.

l After setting the criteria, set the action as ‘pipe through’ and put SpamAssassin in the text box. Once this set Kmail pipes every message the output will be directed to inbox. “Piping” here, relates to the pipe in the real world. Spamassassin forms the pipe and data (unprocessed mail) is fed in to get the processed mail. This mail will have its body and subject header modified if SpamAssassin thinks that the mail in question is spam. Once this is set you can add more filters that catch the word SPAM in the mail body and delete or move the mail in some other folder (a more safer way as there can be some genuine mails marked as spam sometimes).

Advertisment

If you think a mail is not SPAM and is incorrectly marked as Spam then this behavior can be edited by the following command on the shell prompt.

Spamassassin -k < mail 

Similarly, if you think that a particular mail is spam and is not marked, then you can use the following command to update the database.

Advertisment

Spamassassin -r < mail 

Mail file in both cases is the complete mail(s), (including headers) stored in a single file. This can be done from the save as option (go to

file>saveas). 

Integration with Evolution



Evolution 1.0.8, which was given with PCQLinux 8.0 part 1 (March 2003)does not support external programs to be used for filtering. However the latest version Evolution 1.2 does support it. PCQlinux 8.0 users will have to be upgraded to Evolution 1.2, and steps for the same are given below:

Advertisment

1. Copy evolution-1.2.4-0.ximian. 1.i386.rpm from the DVD’s Linux section to your home directory.

2. Copy the redcarpet.tar file to root i.e. / directory and untar using the following command:

Tar -xvf redcarpet.tar 

Advertisment

This creates and copies all the required dependencies for Evolution 1.2. 

3. Then install redcarpet (an installation/package manger program form Ximian) using the following command:

rpm -Uvh red-carpet-1.4.3-1.ximian.4.i386.rpm 

4. Once installed go to file>install from the local directory and select the evolution-1.2 rpm. Click next and continue. Once installed your Evolution should be updated to version 1.2.

5. Now create a text file using any text editor like vi or joe and add: 

spamassassin -e 

6. Save this file as spam.sh and change the execute permission by using chmod +x spam.sh.

This program when fed a mail responds with an exit status of 0, if the mail is not spam. If spam is detected, the program exits with non-zero return value. This behavior is used by Evolution to filter out spam. Start Evolution, select tools, then click Add.

Select “pipe message to Shell command” as the first portion of the criterion. Enter the file you have just created as the shell command, select “Does not return” and 0, in the remaining 2 items. Action to be taken can be set to your taste e.g. color the mail or simply move the mail to some other folder (other than inbox).

Once set up SpamAssassin should satisfy all your spam filtering needs.

Ankit Khare

Advertisment