How To Filter Out Spam

From ECE Information Technology Services
Jump to navigationJump to search


Why doesn't the mail server filter out spam?

No filtering mechanism, algorithm or tool is perfect. A global solution to the spam problem will, invariably, cause some users' legitimate email to be deleted. Therefore, we leave the decision as to whether to filter email to each individual user. To help users filter their email, we have deployed Spam Assassin.

What is Spam Assassin?

Spam Assassin is a classifier. Its only purpose is to classify email as potential spam. It does NOT filter in and of itself. You need to use procmail to do the actual filtering.

Spam Assassin uses a combination of heuristics, realtime black-hole list (RBL) lookups, and a per-user Bayesian filters to classify email. Each rule that is matched adds to the points of a particular email. The default threshold is 5.0: emails with a score of more than 5.0 points are classified as spam.

How do I filter my email?

First, you need to read and understand How Received Email Is Processed. Second, you need need to add the following procmail recipes to your .procmailrc file (see How To Sort Email Using Procmail). These recipes will cause your received email to be (stage 1) classified by Spam Assassin and (stage 2) filtered.

Stage 1 - Classification

  ### Stage 1: classification
  # send the email to Spam Assassin for classification
  :0fw:spam.lock
* < 256000
  | spamc -f

  # handle errors from Spam Assassin gracefully
  :0e
  {
    EXITCODE=$?
  }

The above procmail recipe pipes your received email to Spam Assassin for classification. Spam Assassin will add headers containing the results of the classification to the email. For example,

  X-Spam-Flag: YES
  X-Spam-Status: Yes, hits=6.1 required=5.0
  X-Spam-Level: ******

Stage 2 - Filtering

  ### Stage 2: filtering (IMAP)
  # example: put spam email into a subfolder named 'spam'
  :0
* ^X-Spam-Flag: YES
  ${MAILDIR}/.spam/

The above procmail recipe is useful for IMAP (Maildir) users. It filters based on the X-Spam-Flag header. Email classified as spam is placed into the Maildir-format mail folder: ~/Maildir/.spam/.


Mail that is not caught by the Spam Assassin processing is stored in the default location, ~/Maildir/.

Remember that your ~/.forward file gets processed before ~/.procmailrc (see How Received Email Is Processed); therefore, if you fail to delete your ~/.forward file, then your mail will simply be forwarded, bypassing the procmail and Spam Assassin processing.

Important Note:

Some Windows text editors automatically append DOS EOL=characters to lines in text files. If your .procmailrc file contains DOS EOL characters (^M), then spamc will fail and you will lose mail!