SpamAssassin

SpamAssassin identifies spam email with a set of rules and a combination of unique features to mark email as spam. Plug-ins can be added to extend the number of checks on the email. Spammers tune the content of their email to pass through anti-spam filters, so using as many different checks as possible is critical.

SpamAssassin processes both the email headers and the body. Be aware that when multiple features are enabled and a complex set of rules are used, SpamAssassin can require a lot of system resources. If you receive lots of emails, you can get a separate machine dedicated to filter email coming in your local network. You should also spend time tuning your rules to reduce their number without reducing the accuracy of your filtering.

SpamAssassin configuration files are found in three places:

The first step to configure SpamAssassin is to enable or disable features in /etc/mail/spamassassin/local.cf at the global system level. Some of the features are similar to what was done in procmailrc for SpamProbe:

require_scoren.m

The minimum score to classify an email as spam. The default score is 5.0. To avoid false positives, the minimum score can be set to 7.0 or 8.0. Most spam should have a score between 8 and 10 with the default rule. For exceptions, the score can get higher than 15.

rewrite_header HeaderString

If the email is classified as spam, SpamAssassin can rewrite the header subject, From and/or To. The rule rewrite_header subject[SPAM] will add [SPAM] at the beginning of the subject.

add_headerCase HeaderName String

A new header, X-Spam-HeaderName: String, can be added to spam, ham (good email), or all: add_header all Score _SCORE_ add X-Spam-Score: x.y can be added to all emails. _SCORE_ is a SpamAssassin variable explained in the next section.

report_safen

If SpamAssassin classifies an email as spam, the content of this email can be modified:

Tip

If spamassassin is used to train spamprobe (see Spam Filtering with Bayesian Filters), report_safe should be set to 0 in order to prevent artificial alteration of the body of spam email.

report

Adds a line to the new body of the email when report_safe is set to 1 or 2. The option clear_report_template can be used to remove the previous report lines. An example can be seen in /usr/share/spamassassin/10_misc.cf.

These options can also be used in other .cf files. For example, /usr/share/spamassassin/10_misc.cf defines the headers to add to an email, the required score, etc.

SpamAssassin provides several variables to be used with .cf files. The most frequently used are:

There are additional variables to get the score of the different SpamAssassin plug-ins installed on the server. These variables are very useful to help tune the rules and scores. Record the score of each test to all messages during the first few months of a new SpamAssassin installation to understand how SpamAssassin scored each email and to understand what needs to be improved:

add_header all Score _SCORE_
add_header all Bayes _BAYES_
add_header all Tests _TESTSCORES(,)_
add_header all Level _START(*)_

By default, SpamAssassin uses folded headers to avoid long lines.add_header all Tests _TESTSCORES_ will likely create a header split over several lines. To force all headers added by SpamAssassin to be on one line, use the option fold_headers 0.

All the configuration options available in /etc/mail/spamassassin/local.cf can be used in $HOME/.spamassassin/user_prefs, except for the administrator settings.

allow_user rules

If set to 1, this option allows users to add rules in user_prefs when spamd is used in place of spamassassin (see the section "SpamAssassin As a Daemon or Server" later in this chapter).

loadplugin Name Path

Additional plug-ins can be loaded. A plug-in is a Perl module. If the module cannot be located by Perl, an optional path to the module must be added.

Options for the Bayesian filter and the SpamAssassin plug-ins are only available in local.cf.