What a SpamAssassin Spam Score Actually Is

A spam score is SpamAssassin's verdict, built from rule hits, welcomelists, and Bayes. Here is how to read it and where to safely adjust it.

A spam score is the number SpamAssassin gives a message after testing it against its rules. Each rule that hits adds or subtracts points. A high enough total means the message is treated as spam. The score is not a mystery or a vendor's secret. It is a sum you can read, trace back to individual rules, and adjust through configuration. This article walks through how the score is built and where you can safely change it. It cannot promise your mail lands in the inbox, because a spam score never guarantees that. It only says what SpamAssassin itself concluded about one message.

What a spam score is and where you see it

SpamAssassin scans a message, runs its rules, and produces a total. If the total passes the threshold, the message is flagged as spam. Where you see the result depends on your setup. The mail may be marked, moved, or rejected by whatever your mail system does with the flag. SpamAssassin also attaches a report to spam mail messages. The report_charset setting sets the MIME Content-Type charset for that text/plain report. So the score usually reaches you as a header or as the attached report, not as a dashboard.

How SpamAssassin assembles the score: rules, welcomelists, and Bayes

Three things feed the total. First, the rules. Each rule tests something in the message and carries a score of its own. The final number is the sum of the scores of every rule that hit.

Second, the welcomelists. A welcomelist entry subtracts from the score for mail that matches it. SpamAssassin's guide says welcomelist and blocklist addresses use file-glob-style patterns, so friend@somewhere.com, *@isp.com, or *.domain.net will all work. Welcomelist and blocklist addresses do not use regular expressions. The guide says this is for security. Matching is case-insensitive. You can put several addresses on one line, separated by spaces. You can also use several welcomelist_from lines.

Third, the Bayes system. It is a statistical classifier that learns from mail you have shown it and adds its own contribution to the score. More on tuning it below.

Reading the score: report templates and rule descriptions

The report SpamAssassin attaches to spam mail is built from a template. Each report line appends to the existing template, so clear_report_template is used to restart. The unsafe_report setting sets the report template attached to spam mail messages that contain a non-text/plain part.

When you write or edit rules, keep the descriptions short. SpamAssassin's guide says rule descriptions should by convention be limited to no more than 50 characters. The description is what shows up in the report, so a long one makes the report hard to read.

If you run spamd, be careful about user-level settings. SpamAssassin's guide says spamd users cannot use privileged settings in their user_prefs files for security and efficiency reasons, unless allow_user_rules is enabled. Even then, the guide says allow_user_rules cannot change an existing system rule from a user_prefs file with spamd. That is not possible today. So tuning a shared rule belongs in the system configuration, not in a user file.

Welcomelisting senders safely: welcomelist_from and welcomelist_from_rcvd

welcomelist_from matches the From address alone. That is easy to forge, so it is the weaker of the two. welcomelist_from_rcvd also checks that the mail really came through a relay belonging to that sender. SpamAssassin's guide says only the Received header fields inserted by trusted hosts are considered for welcomelist_from_rcvd matching. And the guide notes that reverse DNS lookup is done by an MTA, not by SpamAssassin.

There is a trap here. By default, mail with a From address in welcomelist_from_rcvd that does not match the relay will trigger a forgery rule. So a welcomelisted sender whose mail arrives through a different relay can still trip a rule. Some senders use a relay other than the listed ones. welcomelist_allows_relays names those addresses. Adding an address there stops the forgery rule from firing.

SpamAssassin comes with its own welcomelist entries. def_welcomelist_from_rcvd works like welcomelist_from_rcvd. The difference is that it covers the default entries that ship with SpamAssassin. Its score is lower, because these entries are often targets for spammer spoofing.

You can override a default entry. unwelcomelist_from removes a default welcomelist_from entry. Put it in a local.cf file to override one that shipped with the distribution. The address in unwelcomelist_from must match the one in the old welcomelist_from line. It must match exactly, but case does not matter. A wildcard in unwelcomelist_from matches only the same wildcard. It does not match any address. unwelcomelist_from_rcvd removes a default entry. It works on welcomelist_from_rcvd and def_welcomelist_from_rcvd.

The guide recommends welcomelist_auth, other authenticated welcomelisting methods, or welcomelist_from_rcvd. These are the safest picks. Authentication is harder to forge than a bare address match.

Trusted and internal networks: what they change about the score

A trusted network is one whose relay hosts are not thought to be run by spammers, open relays, or open proxies. A trusted host could relay spam but will not originate it or forge header data. Trust matters for scoring in a direct way: DNS blocklist checks never query for hosts on trusted networks. So listing your own relays as trusted stops pointless blocklist lookups against your own machines. If a bounce ever names a blocklist, read it before acting, and check the list still runs. SORBS is one list that no longer does.

An internal network is one whose relay hosts are seen as mail servers for your domains or as internal relays. Every entry in internal networks must also appear in trusted networks. Relays that take mail from dial-up users should be listed in trusted networks but not in internal networks. An MSA network's relays accept mail only from users who log in. Any relay after an MSA relay gets the same trusted and internal status as that MSA relay.

Tuning the Bayes system that feeds the score

The Bayes system does not activate until a certain number of ham and spam messages have been learned. Until then it adds nothing to the score. Once active, it learns any reported messages as spam by default, so reporting mail as spam builds the database over time.

Several settings shape it. Mail to an address in bayes_ignore_to skips Bayes classification and autolearning. This helps with mailing lists that would skew the data. bayes_sql_override_username can help you build a global or group Bayes database. The guide says using hapaxes, words that occur only once, gives the Bayesian classifier much better hit rates. With bayes_auto_expire on, old tokens leave the database on their own. bayes_seen_ttl deletes expired seen entries. Those are mail message digests with their status. With bayes_learn_to_journal on, Bayes learning data goes to the journal. It does not go straight into the database.

What a spam score does not tell the reader

A spam score is SpamAssassin's opinion of one message. It does not promise your mail lands in the inbox at Gmail or any other provider. It does not promise a deliverability rate either. Providers add their own rules on top of your filter. One example is the one-click unsubscribe headers Gmail asks bulk senders for. A low score also does not mean your mail is wanted. It means the rules that ran did not hit. Read the score as a diagnostic. Tune the configuration honestly. The number only tells you what SpamAssassin itself decided.

Sources

Filed