From spamassassin.apache.org/full/3.1.x/doc/Mail_SpamAssassin_Conf.html
Most likely created from perldoc Mail::SpamAssassin::Conf

Additional Spamassassin links


sample Mail::SpamAssassin::Conf - SpamAssassin configuration file:

# a comment, might describe what the following statment does
rewrite_header Subject          *****SPAM*****
blacklist_from thespammer@anyWhere.com
whitelist_from MyFriend@nicedomain.org

report_contact Postmaster@Real-World-Systems.com
report_hostname Real-World-Systems,com

#content based:
score SUBJ_DOLLARS      2.7 # was 1.4 Subject starts with dollar amount 
score ADVANCE_FEE_1     1.7 # was 0.0  Appears to be advance fee fraud (Nigerian 419)
#from a black list
score RCVD_IN_SORBS_DUL 1.7 # was 0.9  RBL: SORBS: sent directly from dynamic IP address 

full     PARA_A_2_C_OF_1618         /Paragraph .a.{0,10}2.{0,10}C. of S. 1618/i
describe PARA_A_2_C_OF_1618     Claims compliance with senate bill 1618
header   FROM_HAS_MIXED_NUMS      From =~ /\d+[a-z]+\d+\S*@/i
describe FROM_HAS_MIXED_NUMS    From: contains numbers mixed in with letters
lang es describe FROM_FORGED_HOTMAIL Forzado From: simula ser de hotmail.com
lang pt_BR report O programa detetor de Spam ZOE […]

User Preferences

SpamAssassin is configured using traditional UNIX-style configuration files, loaded from

  1. /usr/share/spamassassin
  2. /etc/mail/spamassassin
  3. ~/.spamassassin/user_perfs

# starts a comment.
 If # is part of a rule or configuration option, it must be escaped with a backslash. i.e.: \#

Whitespace in the files is not significant.
Do not begin a line with whitespace as future versions will use this to indicate a multi-line rule definitions.

Each rule or configuration setting must fit on one-line (as of 3.1.x).

File and directory paths can use ~ to refer to the user's home directory.
No other shell-style path extensions such as globing or ~user/ are supported.

The following are permitted for site-wide (local.cf) and user-specific (user_prefs) files

It is important to consider the result of the SpamAssasin evaluation of a message.
If SA evaluates a message as spam it will modify the email, this may affect wether the email is delivered, held, rejected or discarded by a follow-on process.

If spam is only modified by SA and delivered, false positives (i.e. defining a nice message (ham) as spam ) has minor impact.
If a follow-on process moves spam to a holding directory, a false positive is more of a problem.
If a follow-on process rejects or discards spam without notifying the receipient, a false positive is a bad thing!
This type of processing is not recommended (previously known as required_hits )

A false negative (i.e. failure to declare a message as spam) can have detrimental effects if the message is an attack.

Scoring Options

required_score n.nn Default:5.0
Threshold total score to be exceeded for an email to be considered spam.
The default setting quite aggressive, i.e. it doesn't take much for an email to be classified as spam. It would be suitable for a single-user setup, espically if the message is then delivered or held.
An ISP should probably set the default to be more conservative, like 8.0 or 10.0.

The distributed score values heve been defined with the default in mind.

More information regarding how the scores were established is at wiki.

score test n.nn [ n.nn n.nn n.nn ]
Assign scores (the number of points for a hit) to a given test. Scores can be positive or negative real numbers or integers. test is the symbolic name used by SpamAssassin for that test; for example, 'FROM_ENDS_IN_NUMS'.

If only one valid score is listed, then that score is always used for a test.

If four valid scores are listed, then the score that is used depends on how SpamAssassin is being used.

  1. The first score is used when both Bayes and network tests are disabled (score set 0).
  2. The second score is used when Bayes is disabled, but network tests are enabled (score set 1).
  3. The third score is used when Bayes is enabled and network tests are disabled (score set 2).

Setting a rule's score to 0 will disable that rule from running.

If any of the score values are surrounded by parenthesis '()', then all of the scores in the line are considered to be relative to the already set score. ie: '(3)' means increase the score for this rule by 3 points in all score sets. '(3) (0) (3) (0)' means increase the score for this rule by 3 in score sets 0 and 2 only.

If no score is given for a test by the end of the configuration, a default score is assigned: a score of 1.0 is used for all tests, except those who names begin with 'T_' (this is used to indicate a rule in testing) which receive 0.01.

To get spamassassin to check the user_prefs scores:
spamassassin -D bayes
type any junk here then ^D
[pid] info: config: score: requires a symbolic rule name and 1 or 4 scores
[pid] info: config: SpamAssassin failed to parse line, no value provided for "score", skipping: score HELO_DYNAMIC_DHCP x x2.7

Test names which begin with '__' are indirect rules used to compose meta-match rules and can also act as prerequisites to other rules. They are not scored or listed in the 'tests hit' reports, but assigning a score of 0 to an indirect rule will disable it from running.

next section.

Whitelist and Blacklist options

whitelist_from uname@domain.com
Specifies addresses from which mail is often tagged (incorrectly) as spam.
If you whitelist your domain, be aware that spammers often impersonate the domain of the recipient.
The recommended solution is to use whitelist_from_rcvd

Whitelist and blacklist addresses Only and ? metacharacters are allowed. friend@somewhere.com, ∗@isp.com, or ∗.domain.net are valid.
(Regular expressions are not used for security reasons.

Multiple addresses per line, separated by spaces and multiple whitelist_from lines are permitted.

The headers checked for whitelist addresses are:

Examples:
whitelist_from joe@example.com fred@example.com
whitelist_from @example.com
unwhitelist_from uname@domain.com
Overrides a default whitelist_from entry, for example a distribution whitelist_from can be overridden in local.cf or for an individual user user_prefs.
The address has to match exactly the address previously used in a whitelist_from line. Examples:
unwhitelist_from joe@example.com fred@example.com
unwhitelist_from example.com

whitelist_from_rcvd addr@lists.sourceforge.net sourceforge.net
Use this to supplement the whitelist_from addresses with a check against the Received headers.
The first parameter is the address to whitelist, and the second is a string to match the relay's rDNS.

This string is matched against the reverse DNS lookup used during the handoff to your internal network's Mail Exchangers.
It can be the full hostname or the domain name .
If the host that connected to your MX had an IP address that mapped to 'sendinghost.spamassassin.org', specify sendinghost.spamassassin.org or spamassassin.org.
This requires that internal_networks be correct.
For a complex network, or running with DNS checks off or with -L, you may get better results by setting that parameter.
Examples:

whitelist_from_rcvd joe@example.com example.com
whitelist_from_rcvd ∗@axkit.org sergeant.org

def_whitelist_from_rcvd addr@lists.sourceforge.net sourceforge.net
Same as whitelist_from_rcvd, but for the default whitelist entries in the SpamAssassin distribution with a lower score which are often targets for spammer spoofing.

whitelist_allows_relays uname@domain.com
Specify addresses which are in whitelist_from_rcvd that sometimes send through a mail relay other than the listed ones.
By default mail with a From address that is in whitelist_from_rcvd that does not match the relay will will be prevent from trigger a forgery rule.

The address does not have to match exactly the address previously used in a whitelist_from_rcvd line as it is compared to the address in the header.
Examples:

whitelist_allows_relays joe@example.com fred@example.com whitelist_allows_relays @example.com

unwhitelist_from_rcvd joe@example.com
Overrides a default whitelist_from_rcvd entry.

The address must exactly match a previously whitelist_from_rcvd address .
Examples:

unwhitelist_from_rcvd joe@example.com fred@example.com unwhitelist_from_rcvd @NotSureANyMore.org

blacklist_from joe@ress.com
Specifies addresses which send mail that is often tagged (incorrectly) as non-spam,
Same format as whitelist_from.

unblacklist_from joe@ress.com
Used to override a default blacklist_from entry, so for example a


The levels of To whitelisting:

For deploying SpamAssassin system-wide where some users don't want their mail filtered. as whitelist_from. Users in the whitelist_to level may still get some spammish mails blocked, users in all_spam_to should never get mail blocked.

The headers checked for whitelist addresses are :

 Resent-To and  Resent-Cc if present;
otherwise all addresses are checked from
 To             CC      Apparently-To            Delivered-To    Envelope-To     
 X-Real-To              Apparently-Resent-To     X-Delivered-To  Envelope-Recipients      X-Envelope-To 
 X-Original-To  X-Rcpt-To       
whitelist_to joe@example.com
If the given address appears as a recipient in the message headers
(Resent-To, To, CC, obvious envelope recipient, etc.)
the mail will be whitelisted.

more_spam_to example.com
.

all_spam_to example.com
.

blacklist_to joe@example.com
If the address appears as a recipient in the headers
(Resent-To, To, CC, obvious envelope recipient, etc.)
the mail will be blacklisted. Same format as blacklist_from.

Basic Message Tagging Options

clear_headers
Clears all headers.
Use before add_header to prevent the default headers from being added.
X-Spam-Checker-Version is not removable.
rewrite_header {subject|from|to} string


The header will be tagged with string.
A null value for string removes any existing rewrite.
Use \n for newline, \t for and tab and \\ for backslash. Other escaped chars will be removed.
Headers will be folded if fold_headers is set to 1.
Manually adding newlines via \n disables any further automatic wrapping (ie: long header lines are possible). The lines will still be properly folded and marked as continuing . string may contain TEMPLATE TAGS .

From or To headers (as per RFC 2822) have string (in parantheses) appended to the address.
Parentheses in string of From or To headers will be converted to square brackets.

Subject header will have string prepended to the original subject. A Subject header will be created if necessary.
Only use the _REQD_ and _SCORE_ tags when rewriting the Subject header if report_safe is 0. Or you may not be able to remove the SpamAssassin markup via the normal methods.

Customize existing headers with add_header (only the subset of messages will be changed).

Use clear_headers for removing headers.

add_header {spam|ham|all} header_name string


Generated headers begin with X-Spam- For example
   add_header spam spammie Looks like spam to me.
will insert X-Spam-Looks like spam to me..
header_name is restricted to the character set [A-Za-z0-9_-].

Examples (these are the defaults, Checker-Version can not be changed or removed):

  add_header spam Flag _YESNOCAPS_
  add_header all Status _YESNO_, score=_SCORE_ required=_REQD_ tests=_TESTS_ autolearn=_AUTOLEARN_ 
  add_header all Level _STARS(*)_
  add_header all Checker-Version SpamAssassin _VERSION_ (_SUBVERSION_) on _HOSTNAME_

remove_header { spam |ham|all} header_name

Headers can be removed.
All headers begin with X-Spam- (so header_name will be appended to X-Spam-).
clear_headers removes all headers.
X-Spam-Checker-Version is not removable.

report_safe (0|1|2)Default:1
When spam is detected Spamassasin will:

  1. add X-Spam-headers. A header named X-Spam-Report is added, remove_header can remove that header .
    No changes will be made to the body (may not be the best idea!).
              -or-
  2. create a report message and attach the original spam as a message/rfc822 MIME part.
    The original message is completely preserved, not easily opened, and easier to recover.
              -or-
  3. attached the original message with a content type of text/plain .
    This is suggested for safety reasons on mail clients that automatically load attachments without any action by the user.
    The original message is somewhat more difficult to extract or view .

See report_safe_copy_headers if you want to copy headers from the original mail into tagged messages.

fold_headers (0|1) Default:1

1 Headers will be whitespace folded, i.e. broken up into multiple lines
0 Headers not folded.
report_contact contact_address

Set _CONTACTADDRESS_. Default: 'the administrator of that system'

report_hostname hostname

Set _HOSTNAME_ . Default, determined dynamically

clear_report_template



report report_messages

Define the report template which is attached to spam mail messages.
Keep each under 78 columns.
Lines are append to the template, tags can be included. From:/usr/share/spamassassin/10_default_prefs.cf .
        report Spam detection software, running on the system "_HOSTNAME_", has
        report identified this incoming email as possible spam.  The original message
        report has been attached to this so you can view it (if it isn't spam) or label
        report similar future email.  If you have any questions, see
        report _CONTACTADDRESS_ for details.
        report
        report Content preview:  _PREVIEW_
        report
        report Content analysis details:   (_SCORE_ points*, _REQD_ required)*
        report
        report " pts rule name              description"
        report  ---- ---------------------- --------------------------------------------------
        report _SUMMARY_ 
If as per ?????? the message is not going to be returned, the is unnecessary.

report_safe_copy_headers header_name

If report_safe, headers from the original message are copied into the wrapper header (From, To, Cc, Subject, Date, etc.)
To have other headers copied, add them using this option.
Specify multiple headers on the same line, separated by spaces, or use multiple lines.

unsafe_report message

Define the report template which is attached to spam mail messages which contain a non-text/plain part.
Example from configuration file /usr/share/spamassassin/10_default_prefs.cf
        unsafe_report The original message was not completely plain text, and may be unsafe to
        unsafe_report open with some email clients; in particular, it may contain a virus,
        unsafe_report or confirm that your address can receive spam.  If you wish to view
        unsafe_report it, it may be safer to save it to a file and open it with an editor.
Each unsafe-report line appends to the template.
Tags can be used .

clear_unsafe_report_template



report_charset CHARSETs Default:unset

Set the MIME Content-Type charset used for the text/plain report which is attached to spam mail messages.

Language Options

ok_locales xx [ yy zz … ] Default:all
Used to specify which locales are considered OK for incoming mail. Mail using the character sets that are allowed by this option will not be marked as possibly being spam in a foreign language.

Examples:

If you receive lots of spam in foreign languages, and never get any non-spam in these languages, this may help. Note that all ISO-8859-* character sets, and Windows code page character sets, are always permitted by default.

Set this to all to allow all character sets. This is the default.

The rules CHARSET_FARAWAY, CHARSET_FARAWAY_BODY, and CHARSET_FARAWAY_HEADERS are triggered based on how this is set.

Examples:

ok_locales all (allow all locales)
ok_locales en (only allow English)
ok_locales en ja zh (allow English, Japanese, and Chinese)

Note: if there are multiple ok_locales lines, only the last one is used.

Select the locales to allow from the list :

en - Western character sets in general
ja - Japanese
ko - Korean
ru - Cyrillic
th - Thai
zh - Chinese (both simplified and traditional) character sets

Network Test Options

trusted_networks ddd.ddd.ddd.ddd[/mask]Default:none


Trusted means that relay hosts on these networks are considered to not be operated by spammers, open relays, or open proxies. A trusted host could conceivably relay spam, but will not originate it, and will not forge header data. DNS blacklist checks will never query for hosts on these networks.

MXes for your domain(s) and internal relays should be specified using the internal_networks setting. When there are 'trusted' hosts that are not MXes or internal relays for your domain(s) they should only be specified in trusted_networks.

A mask is a CIDR-style 'netmask', specified in bits.
An ip address with less than 4 octets with a trailing dot implies a mask for those octets.

If a network or host address is prefaced by a ! the network or host will be excluded (or included) in a first listed match fashion.

Examples:


    trusted_networks 192.168/16 127/8           # all in 192.168.*.* and 127.*.*.*
    trusted_networks 212.17.35.15               # just that host
    trusted_networks 127.                       # all in 127.*.*.*

Inclusion/Exclusion examples:
 # include all of 10.0.1/24 except for 10.0.1.5
    trusted_networks !10.0.1.5 10.0.1/24

    # include all of 10.0.1/24, the !10.0.1.5 has no effect
    trusted_networks 10.0.1/24 !10.0.1.5

    # include all RFC1918 address space except subnet 172.16.3/24 but
    # including host 172.16.3.3 within the excluded 172.16.3/24
    trusted_networks 172.16.3.3 !172.16.3/24 172.16/12 10/8 192.168/16

This operates additively, so a trusted_networks line after another one will result in all those networks becoming trusted. To clear out the existing entries, use clear_trusted_networks.

If trusted_networks is not set and internal_networks is, the value of internal_networks will be used for this parameter.

If DNS checks are enabled, SpamAssassin includes code to infer your trusted networks on the fly, so this may not be necessary. (Thanks to Scott Banister and Andrew Flury for the inspiration for this algorithm.) This inference works as follows:

clear_trusted_networks
 

internal_networks ddd.ddd.ddd.ddd[/mask]Default:none

What networks or hosts are 'internal' in your setup. Internal means that relay hosts on these networks are considered to be MXes for your domain(s), or internal relays. This uses the same format as trusted_networks, above.

This value is used when checking 'dial-up' or dynamic IP address blocklists, in order to detect direct-to-MX spamming. Trusted relays that accept mail directly from dial-up connections should not be listed in internal_networks. List them only in trusted_networks.

If trusted_networks is set and internal_networks is not, the value of trusted_networks will be used for this parameter.

If neither trusted_networks or internal_networks is set, no addresses will be considered local; in other words, any relays past the machine where SpamAssassin is running will be considered external.

clear_internal_networks
 

always_trust_envelope_sender (0|1) Default:0

Trust the envelope sender even if the message has been passed through one or more trusted relays.

skip_rbl_checks (0|1) Default:0
By default, SpamAssassin will run RBL checks. If your ISP already does this for you, set this to 1.

rbl_timeout n Default:15
All DNS queries are made at the beginning of a check and we try to read the results at the end. This value specifies the maximum period of time to wait for an DNS query. If most of the DNS queries have succeeded for a particular message, then SpamAssassin will not wait for the full period to avoid wasting time on unresponsive server(s). For the default 15 second timeout, here is a chart of queries remaining versus the effective timeout in seconds:

  queries left    100%  90%  80%  70%  60%  50%  40%  30%  20%  10%  0%
  timeout          15   15   14   14   13   11   10    8    5    3   0

In addition, whenever the effective timeout is lowered due to additional query results returning, the remaining queries are always given at least one more second before timing out, but the wait time will never exceed rbl_timeout.

For example, if 20 queries are made at the beginning of a message check and 16 queries have returned (leaving 20%), the remaining 4 queries must finish within 5 seconds of the beginning of the check or they will be timed out.

dns_available { yes | test[: name1 name2…] | no } Default:test

By default, of 13 external DNS servers, 3 are randomly quired for NS records to check if DNS is available .
If your network connection is down this causes significant delay , and will wrongly determine DNS is unavailable
Use dns_available to specify a custom list

  dns_available test: domain1.tld domain2.tld domain3.tld

Skip to Rules section

Learning Options

bayes_min_ham_num Default:200
bayes_min_spam_num Default:200

To be accurate, the Bayes system does not activate until a certain number of ham (non-spam) and spam have been learned. The default is 200 of each ham and spam, tune these up or down with these settings.

use_bayes (0|1) Default:1

Whether to use the naive-Bayesian-style classifier built into SpamAssassin. This is a master on/off switch for all Bayes-related operations.

use_bayes_rules (0|1) Default:1

Whether to use rules using the naive-Bayesian-style classifier built into SpamAssassin. This allows you to disable the rules while leaving auto and manual learning enabled.

bayes_auto_learn (0|1) Default:1

Whether SpamAssassin should automatically feed high-scoring mails (or low-scoring mails, for non-spam) into its learning systems.
The learning system supported is a naive-Bayesian-style classifier.

See the documentation for the Mail::SpamAssassin::Plugin::AutoLearnThreshold plugin module

bayes_ignore_header header_name

If you receive mail filtered by upstream mail systems, like a spam-filtering ISP or mailing list, and that service adds new headers (as most of them do), these headers may provide inappropriate cues to the Bayesian classifier, allowing it to take a ``short cut''. To avoid this, list the headers using this setting. Example:

        bayes_ignore_header X-Upstream-Spamfilter
        bayes_ignore_header X-Upstream-SomethingElse

bayes_ignore_from uname@domain.com
bayes_ignore_to uname@domain.com

sa-learn will ignore the listed addresses if it is invoked using the --use-ignores option.
One or more addresses can be listed, see whitelist_from.

Spam messages from certain senders may contain many words that frequently occur in ham. For example, one might read messages from a preferred bookstore but also get unwanted spam messages from other bookstores. If the unwanted messages are learned as spam then any messages discussing books, including the preferred bookstore and antiquarian messages would be in danger of being marked as spam. The addresses of the annoying bookstores would be listed. (Assuming they were halfway legitimate and didn't send you mail through myriad affiliates.)

Those who have pieces of spam in legitimate messages or otherwise receive ham messages containing potentially spammy words might fear that some spam messages might be in danger of being marked as ham. The addresses of the spam mailing lists, correspondents, etc. would be listed.

bayes_learn_during_report Default:1

Default: learn any reported messages (spamassassin -r) as spam.
Set this option to 0 to inhibit .

bayes_sql_override_username

Used by BayesStore::SQL storage implementation.

If this options is set the BayesStore::SQL module will override the set username with the value given. Useful for implementing global or group bayes databases.

bayes_use_hapaxes Default:1

hapaxes (words/tokens that occur only once) when classifying?
This produces significantly better hit-rates, but increases database size by about a factor of 8 to 10!

bayes_journal_max_size Default:102400 bytes

SpamAssassin will opportunistically sync the journal and the database once a day
but will sync more often if the journal file size goes above this setting.
If 0, opportunistic syncing will not occur.

bayes_expiry_max_db_size Default:150000

When expiry occurs, keep either 75% of the maximum value, or 100,000 tokens, whichever has a larger value. ( 150,000 tokens requires about an 8Mb database).

bayes_auto_expire Default:1

If enabled, expire old tokens from the database when the number of tokens in the database surpasses bayes_expiry_max_db_size.

bayes_learn_to_journal Default:0

Information is stored to the journal instead of directly into the database. This reduces contention for locking the database for updates, but causes more access to the journal and a delay before the updates are actually committed.


skip to Admin settings

Rule Definitions

These are considered 'privileged'.
Only users running spamassassin from their procmailrc's or forward files, or sysadmins editing a file in /etc/mail/spamassassin, can use them.

If you add or modify a test, please be sure to run a sanity check afterwards by running spamassassin --lint. This will avoid confusing error messages, or other tests being skipped as a side-effect. spamd users cannot use them in their user_prefs files, for security and efficiency reasons, unless allow_user_rules is enabled.

allow_user_rules (0|1) Default:0

Allows users to create rules in their user_prefs .

Causes spamassassin to recompile all the tests each time it processes a message for a user with a rule in their user_prefs , which effects performance.
It is not recommended.

allow_user_rules will not modify an existing system rule .

describe test description

Describes a test in the detailed report. Limit description to 50 characters.

test names which begin with __ are reserved for meta-match sub-rules, and are not scored or listed in the 'tests hit' reports.

test names must not start with a number, contain only alphanumerics and underscores and be less than 22 characters. Lower-case characters should not be used, sub-rules, and are not scored or listed in the 'tests hit' reports.
test names which begin with T_ are reserved for tests which are undergoing QA, and these are given a very low score.

test name example: FROM_ENDS_IN_NUMS.

header test exists:name_of_header

Defines a header existence test. Simplest of the header tests.

header test header op /pattern/modifiers [if-unset: string]

Define a test which evaluates the header.

header is the name of a mail header Subject, To, etc.

Appending :raw to the header name will inhibit decoding of quoted-printable or base-64 encoded strings.

Appending :addr to the header name will cause everything except the first email address to be removed from the header.

For example, all of the following will result in
example@foo:

example@foo
example@foo (Foo Blah)
example@foo, example@bar
display: example@foo (Foo Blah), example@bar ;
Foo Blah <example@foo>
``Foo Blah'' <example@foo>
``'Foo Blah''' <example@foo>

Appending :name to the header name will cause everything except the first real name to be removed from the header.

For example, all of the following will result in
Foo Blah

example@foo (Foo Blah)
example@foo (Foo Blah), example@bar
display: example@foo (Foo Blah), example@bar ;
Foo Blah <example@foo>
``Foo Blah'' <example@foo>
``'Foo Blah''' <example@foo>

pseudo-headers

ALL refers to the text of all the message's headers.
ToCc refers to the contents of both the 'To' and 'Cc' headers.
EnvelopeFrom is the address used in the 'MAIL FROM:' phase of the SMTP transaction that delivered this message.
MESSAGEID is a symbol meaning all Message-Id's found in the message; some mailing list software moves the real 'Message-Id' to 'Resent-Message-Id' or 'X-Message-Id', then uses its own one in the 'Message-Id' header. The value returned for this symbol is the text from all 3 headers, separated by newlines.

op is either =~ (contains regular expression) or !~ (does not contain regular expression),

pattern is a valid Perl regular expression, with modifiers as regexp modifiers.

Multi-line rules are not supported.
The # character must be escaped (\#) or else it will be considered to be the start of a comment and not part of the regexp.

[if-unset: string] string will be used if the header is not found in the mail message.

header test eval:name_of_eval_method([arguments])

Defines a header eval test.

name_of_eval_method is the name of a method on the Mail::SpamAssassin::EvalTests object.
Found in lib/Mail/SpamAssassin/Plugin
Bayes.pm, BodyEval.pm, DNSEval.pm, HTMLEval.pm, HeaderEval.pm, MIMEEval.pm, RelayEval.pm, URIEval.pm, WLBLEval

header test eval:check_rbl(set, zone [, sub-test])

Check a DNSBL (BlackList or whitelist).
This

Duplicated IPs are only queried once
Private IPs, listed in: IANA 10,172.16,192.168, duccw privip , ducw autoipi APIPA169.254, or rfc3330
are not queried.

set
This is used as a 'zone ID'. to look up a multiple-meaning zone like NJABL or SORBS, you can then query the results from that zone using it; but all check_rbl_sub() calls must use that zone ID.

If more than one IP address gets a DNSBL hit for a particular rule, it does not affect the score because rules are only triggered once per message.

zone
root zone of the DNSBL, ending in a period.

sub-test
argument behaves the same as the sub-test argument in check_rbl_sub() .

header test eval:check_rbl_txt('set', 'zone')

Same as check_rbl, except querying using IN TXT instead of IN A records. If the zone supports it, it will result in a line of text describing why the IP is listed, typically a hyperlink to a database entry.

header test eval:check_rbl_sub('set', 'sub-test')

Create a sub-test for 'set'. If you want to look up a multi-meaning zone like relays.osirusoft.com, you can then query the results from that zone using the zone ID from the original query. The sub-test may either be an IPv4 dotted address for RBLs that return multiple A records or a non-negative decimal number to specify a bitmask for RBLs that return a single A record containing a bitmask of results, a SenderBase test beginning with ``sb:'', or (if none of the preceding options seem to fit) a regular expression.

Note: the set name must be exactly the same for as the main query rule, including selections like '-notfirsthop' appearing at the end of the set name.

body test eval:name_of_eval_method([args])

Define a body eval test.

body test /pattern/modifiers

pattern is a Perl regular expression.
The 'body' in this case is the textual parts of the message body; any non-text MIME parts are stripped, and the message decoded from Quoted-Printable or Base-64-encoded format if necessary.
The message Subject header is considered part of the body and becomes the first paragraph when running the rules.
All HTML tags and line breaks are removed before matching.

uri test /pattern/modifiers

The 'uri' is a list of all the URIs in the body of the email, and the test will be run on each of those URIs, adjusting the score if a match is found. Use this test instead of one of the body tests when you need to match a URI, as it is more accurately bound to the start/end points of the URI, and will also be faster.

rawbody test /pattern/modifiers

The 'raw body' of a message is the raw data inside all textual parts.
The text will be decoded from base64 or quoted-printable encoding, but HTML tags and line breaks will still be present.
The pattern will be applied line-by-line.

rawbody test eval:name_of_eval_method([args])
full test /pattern/modifiers

Define a full message pattern test.

The full message is the pristine message headers plus the pristine message body, including all MIME data such as images, other attachments, MIME boundaries, etc.

full test eval:name_of_eval_method([args])

Define a full message eval test.

meta test boolean expression

Define a boolean expression test in terms of other tests that have been hit or not hit. For example:

meta META1 TEST1 && !(TEST2 || TEST3)

English language operators (and, or) will be treated as rule names. There is no XOR operator.

meta test boolean arithmetic expression

Can also define a boolean arithmetic expression in terms of other tests, with a hit test having the value ``1'' and an unhit test having the value ``0''. For example:

meta META2 (3 * TEST1 - 2 * TEST2) > 0

Note that Perl builtins and functions, like abs(), can't be used, and will be treated as rule names.

If you want to define a meta-rule, but do not want its individual sub-rules to count towards the final score unless the entire meta-rule matches, give the sub-rules names that start with '__' (two underscores). SpamAssassin will ignore these for scoring.

tflags test [ {net|nice|learn|userconf|noautolearn} ]

set flags on a test used in the score-determination back end system for details of the test's behaviour. See bayes_auto_learn

net
network test, and not run in the mass checking system or if -L is used, therefore its score should not be modified.
nice
Intended to compensate for common false positives, and should be assigned a negative score.
userconf
requires user configuration before it can be used (like language- specific tests).
learn
requires training before it can be used.
noautolearn
explicitly ignored when calculating the score for learning systems.
priority test n

Assign a specific priority to a test. All tests, except for DNS and Meta tests, are run in increasing priority value order (negative priority values are run before positive priority values). The default test priority is 0 (zero).


ADMINISTRATOR SETTINGS

These settings considered 'more privileged' than the ones in the PRIVILEGED SETTINGS section. These can not be set from user_prefs when spamc/spamd is used.
However, all settings can be used by local programs run directly by the user.

version_tag string
Appended to the SA version in the X-Spam-Status header.
You should include it when modify your ruleset, especially if you plan to distribute it. string is your last name or your initials followed by a number which increases with each change.

The version_tag will be lowercased, and any non-alphanumeric or period character will be replaced by an underscore.
example:

  version_tag myrules1    # version=2.41-myrules1

test test (ok|fail) Some string to test against

Define a regression testing string. Multiple strings per symbolic test name are permitted.

These tests are only run as part of the test suite.

bayes_path /path/filename Default:~/.spamassassin/bayes

directory and filename for Bayes databases. Several databases will be created, with this as the base directory and filename, with _toks, _seen, etc. appended to the base. The default setting results in files called ~/.spamassassin/bayes_seen, ~/.spamassassin/bayes_toks, etc.

By default, each user has their own in their ~/.spamassassin directory with mode 700/600.
For system-wide SpamAssassin use, and to reduce disk space usage share this across all users.
Bayes is more effective with individual user databases.

bayes_file_mode Default:700
Permissions for files and directories, include eXecute mode bits. Files will not have any execute bits set

bayes_store_module Name::Of::BayesStore::Module

Alternate storage mechanism. It must be a published storage specification (see Mail::SpamAssassin::BayesStore). For example, Mail::SpamAssassin::BayesStore::SQL to use the generic SQL storage module.

bayes_sql_dsn DBI::databasetype:databasename:hostname:port

Connect string used for SQL based storage.

bayes_sql_username
 
bayes_sql_password
 

bayes_sql_username_authorized (0|1) Default:0

to call the services_authorized_for_username plugin hook in BayesSQL. If the hook does not determine that the user is allowed to use bayes or is invalid then then database will not be initialized.

By default the user is considered invalid until a plugin returns a true value.
If enabled without a proper plugin loaded, all users denied

The username passed into the plugin can be affected by bayes_sql_override_username.

user_scores_dsn DBI:databasetype:databasename:hostname:port

To load user scores from a SQL database, this will set the DSN used to connect. Example: DBI:mysql:spamassassin:localhost

To load user scores from an LDAP directory, this will set the DSN used to connect.
Write the DSN as an LDAP URL, the components being the host and port to connect to, the base DN for the seasrch, the scope of the search (base, one or sub), the single attribute being the multivalued attribute used to hold the configuration data (space separated pairs of key and value, just as in a file) and finally the filter being the expression used to filter out the wanted username.
The filter expression is being used in a sprintf statement with the username as the only parameter, thus is can hold a single __USERNAME__ expression. This will be replaced with the username.

Example: ldap://localhost:389/dc=koehntopp,dc=de?spamassassinconfig?uid=__USERNAME__

user_scores_sql_username username
 

user_scores_sql_password password
 

user_scores_sql_custom_query query
Create a custom SQL query to retrieve user scores and preferences.
Query should return two values, the preference name and value, in that order.
variables can be used as part of the query, which will be substituted for the values before the query is run:
_TABLE_
table where user scores and preferences are stored. Default: userpref
_USERNAME_
The current user's username.
_MAILBOX_
The portion before the @ from the current username.
_DOMAIN_
The portion after the @ from the current username, may be null.

The query must be contained on one line.
Default query:
SELECT preference, value FROM _TABLE_ WHERE username = _USERNAME_ OR username = '@GLOBAL' ORDER BY username ASC

Use global and then domain level defaults:
SELECT preference, value FROM _TABLE_ WHERE username = _USERNAME_ OR username = '@GLOBAL' OR username = '@~'||_DOMAIN_ ORDER BY username ASC

If global prefs should override user prefs:
SELECT preference, value FROM _TABLE_ WHERE username = _USERNAME_ OR username = '@GLOBAL' ORDER BY username DESC

user_scores_ldap_username
This is the Bind DN used to connect to the LDAP server.

Example: cn=master,dc=koehntopp,dc=de

user_scores_ldap_password
 

loadplugin PluginModuleName [/path/module.pm]

Load a perl module with the name used to create the plugin object itself.

/path/to/module.pm is the file to load, containing the module's perl code; if specified as a relative path, it is relative to the current configuration file.
If omitted, the module will be loaded using perl's search path (the @INC array).

See Mail::SpamAssassin::Plugin.



PREPROCESSING OPTIONS

include filename
Relative paths are from the current configuration file or user preferences file.
if (conditional perl expression)
Lines between this and a corresponding endif line will be processed if the conditional expression evaluates as true (in the perl sense: defined and non-0).

The conditional accepts a limited subset of perl for security; enough to perform basic arithmetic comparisons. The following input is accepted:

numbers, whitespace, arithmetic operations and grouping
( ) - + * / _ . , < = > ! ~ 0-9 whitespace

version
The internal version format is x.yyyzzz, where x is major version, y is minor version, and z is maintenance version. So 3.0.0 is 3.000000, and 3.4.80 is 3.004080.

plugin(Name::Of::Plugin)
Returns 1 if the plugin is loaded, or undef otherwise.

If the end of a configuration file is reached while still inside a if scope, a warning will be issued, parsing will restart on the next file.

For example:

 if (version > 3.000000)
          header MY_FOO …
      endif

        loadplugin MyPlugin plugintest.pm

        if plugin (MyPlugin)
          header MY_PLUGIN_FOO  eval:check_for_foo()
          score  MY_PLUGIN_FOO  0.1
        endif
ifplugin PluginModuleName
Alias for if plugin(PluginModuleName).

require_version n.nnnnnn
Indicates that the entire file, from this line on, requires a certain version. If a different (older or newer) version reads the configuration, it will output a warning and ignore it.

TEMPLATE TAGS

The following tags can be used in certain options. They will be replaced by the corresponding value when they are used.

Some tags can take an argument (in parentheses). The argument is optional, and the default is shown below.

 _YESNOCAPS_       "YES"/"NO" is/isn't spam
 _YESNO_           "Yes"/"No" is/isn't spam
 _SCORE(PAD)_      message score, if PAD is either spaces or zeroes, 
                   pad scores with the number of pad characters, default:none)  
                   examples:
                   _SCORE(0)_ makes 2.4 become 02.4,
                   _SCORE(00)_ is 002.4.  12.3 would be 12.3 and 012.3
 _REQD_            message threshold
 _VERSION_         eg. 3.0.0 or 3.1.0-r26142-foo1
 _SUBVERSION_      sub-version/code revision date (eg. 2004-01-10)
 _HOSTNAME_        hostname of processing system
 _REMOTEHOSTNAME_  hostname of the machine the mail was from, only available with spamd
 _REMOTEHOSTADDR_  ip address of the machine the mail was from, only available with spamd
 _BAYES_           bayes score
 _TOKENSUMMARY_    number of new, neutral, spammy, and hammy tokens found
 _BAYESTC_         number of new tokens found
 _BAYESTCLEARNED_  number of seen tokens found
 _BAYESTCSPAMMY_   number of spammy tokens found
 _BAYESTCHAMMY_    number of hammy tokens found
 _HAMMYTOKENS(N)_  N most significant hammy tokens (default, 5)
 _SPAMMYTOKENS(N)_ N most significant spammy tokens (default, 5)
 _DATE_            rfc-2822 date of scan
 _STARS(*)_        one "*" (any character) for each full score point, max 50 
            Relays used and 
 _RELAYSTRUSTED_   trusted
 _RELAYSUNTRUSTED_ not be trusted
 _RELAYSINTERNAL_  internal
 _RELAYSEXTERNAL_  external
 _AUTOLEARN_       autolearn status ("ham", "no", "spam", "disabled", "failed", "unavailable")
 _TESTS(,)_        tests hit separated by "," (or other separator)
 _TESTSSCORES(,)_  as above, except with scores appended (eg. AWL=-3.0,…)
 _DCCB_            DCC's "Brand" ?
 _DCCR_            DCC's 
 _PYZOR_           Pyzor Razor
 _RBL_             full results for positive RBL queries in DNS URI format
 _LANGUAGES_       possible languages of mail
 _PREVIEW_         content preview
 _REPORT_          terse report of tests hit (for header reports)
 _SUMMARY_         summary of tests hit for standard report (for body reports)
 _CONTACTADDRESS_  for 'report_contact' 
 

If a tag is undefined it will be unchanged.

HAMMYTOKENS and SPAMMYTOKENS optional second argument specifies a format. See HAMMYTOKENS/SPAMMYTOKENS TAG FORMAT section.

HAMMYTOKENS/SPAMMYTOKENS TAG FORMAT

The HAMMYTOKENS and SPAMMYTOKENS tags have an optional second argument which specifies a format: _SPAMMYTOKENS(N,FMT)_, _HAMMYTOKENS(N,FMT)_ The following formats are available:

short
tokens are listed. For example:

add_header all Spammy _SPAMMYTOKENS(2,short)_
Results in message header:
X-Spam-Spammy: remove.php, UD:jpg
Indicating that the top 2 spammy tokens found are remove.php and UD:jpg. (token follows the last colon, the text before the colon indicates something about the token).
UD means the token looks like it might be part of a domain name.)

compact
token probability- abbreviated declassification distance-- token

For example:

add_header all Spammy _SPAMMYTOKENS(2,compact)_ Results in message header:
X-Spam-Spammy: 0.989-6--remove.php, 0.988-+--UD:jpg

Indicating that the probabilities of the top two tokens are 0.989 and 0.988, respectively.
The first token has a declassification distance of 6, meaning that if the token had appeared in at least 6 more ham messages it would not be considered spammy.
The + for the second token indicates a declassification distance greater than 9.

long
token probability - declassification distance-- number of times seen in ham -- number of times seen in spam -- age-- token

For example:

add_header all Spammy _SPAMMYTOKENS(2,long)_ Results in message header:
X-Spam-Spammy: 0.989-6--0h-4s--4d--remove.php, 0.988-33--2h-25s--1d--UD:jpg

In addition to the information provided by the compact option, the long option shows that
the first token appeared in zero ham messages and four spam messages, and that it was last seen four days ago.
The second token appeared in two ham messages, 25 spam messages and was last seen one day ago.

long includes declassification distances that are greater than 9.


lock_method type
Select the file-locking method used to protect database files on-disk. By default, SpamAssassin uses an NFS-safe locking method on UNIX; however, if you are sure that the database files you'll be using for Bayes and AWL storage will never be accessed over NFS, a non-NFS-safe locking system can be selected.

This will be quite a bit faster, but may risk file corruption if the files are ever accessed by multiple clients at once, and one or more of them is accessing them through an NFS filesystem.

Note that different platforms require different locking systems.

The supported locking systems for type are as follows:

nfssafe and flock are only available on UNIX, and win32 is only available on Windows. By default, SpamAssassin will choose either nfssafe or win32 depending on the platform in use.

redirector_pattern /pattern/modifiers
A regex pattern that matches both the redirector site portion, and the target site portion of a URI.

The target URI portion must be surrounded with parentheses and no other part of the pattern may create a backreference.

Example: http://chkpt.zdnet.com/chkpt/whatever/spammer.domain/yo/dude

  redirector_pattern    /^https?:\/\/(?:opt\.)?chkpt\.zdnet\.com\/chkpt\/\w+\/(.*)$/i

envelope_sender_header Name-Of-Header
SpamAssassin will attempt to discover the address used in the 'MAIL FROM:' phase of the SMTP transaction that delivered this message, if made available by the SMTP server. This is used in the EnvelopeFrom pseudo-header, and for various rules such as SPF checking.

By default, various MTAs will use different headers, such as:

    X-Envelope-From
    Envelope-Sender
    X-Sender
    Return-Path

SpamAssassin will attempt to use these, if some heuristics (such as the header placement in the message, or the absence of fetchmail signatures) appear to indicate that they are safe to use. However, it may choose the wrong headers in some mailserver configurations. (More discussion of this can be found in bug 2142 in the SpamAssassin BugZilla.)


To avoid this failure, the envelope_sender_header setting may be helpful. Name the header that your MTA adds to messages containing the address used at the MAIL FROM step of the SMTP transaction.

< and > characters at the start and end of the email address in the right-hand side, as in the SMTP transaction are removed.

If the header is not found in a message, or if does not contain @ , SpamAssassin will fall back to its default heuristics.


(Note for MTA developers: we would prefer if the use of a single header be avoided in future, since that precludes 'downstream' spam scanning. http://wiki.apache.org/spamassassin/EnvelopeSenderInReceived details a better proposal using the Received headers.)

example:

    envelope_sender_header X-SA-Exim-Mail-From


Localization

A line starting with the text lang xx will only be interpreted if the user is in that locale, allowing test descriptions and templates to be set for that language.

The locales string should specify either both the language and country, e.g. lang pt_BR, or just the language, e.g. lang de.


see Mail::SpamAssassin spamassassin spamd

SpamAssassin's network rules are run in parallel. This can cause overhead in terms of the number of file descriptors required; it is recommended that the minimum limit on file descriptors be raised to at least 256 for safety. wiki.apache.org/spamAssassin

How are scores assigned

Rule Quality Assuarance displays info about rules from the QA process.
report from this link is VERY slow, just wait!
Example: CORRUPT_FROM_LINE_IN_HDRS
Detailed results for rule CORRUPT_FROM_LINE_IN_HDRS, from source file rulesrc/sandbox/jm/20_basic.cf, tflags userconf publish. Source file was last modified on 2008-02-13 15:15:24 UTC.
Locating the in the 20_basic.cf file:

27  # define an informational rule, which detects when a message has become
28  # corrupt with a header prepended before the From line:
29  #
30  #   Header: blah
31  #   From address@example.com  Mon Jun 19 14:15:23 2006
32  #   Header2: blah
33  
34  body __BODY_STARTS_WITH_FROM_LINE /^From \S+ \S\S\S \S\S\S .. ..:..:.. \S+\s+\S+\: /s
35  meta CORRUPT_FROM_LINE_IN_HDRS (MISSING_HEADERS && __BODY_STARTS_WITH_FROM_LINE &&MISSING_DATE &&NO_RELAYS)
36  describe CORRUPT_FROM_LINE_IN_HDRS Informational: message is corrupt, with a From line in its headers
37  
38  # informational rules don't have to hit spam
39  tflags CORRUPT_FROM_LINE_IN_HDRS userconf publish
40  score CORRUPT_FROM_LINE_IN_HDRS 0.001

phrase tests

Bayes processing util: sa-learn

shortcircuit

spamc client, spamd daemon

sa-update, Spam Assassin Bayes Learn


AWL is a score averager, the points it applies are based on the historical scoring from that sender.
Setting score AWL 0 in user_prefs disables not only the application of the rule, but also disables updates to the AWL database!
The score will vary by who the sender is and when the message is processed (i.e. their history to-date).

AWL info

Perhaps:
AutomaticWhiteList should be renamed (HEAT Heuristic Email Address Tracking)
The important point is not that it's automatically applied, but that it's _A_veraging...
It retains the number of messages from an address ( and the most significant portion of the IP address) and sum of the scores for those messages. Seperate entries are retained if the same email address is different.

 average   total/count  
-10.7      -203.0/19 users-help@spamassassin.apache.org   98.109

spamassassin Mailing List


SPF is a DNS record used by some (many) MailTransferAgents. When an email is received from fine fellow by way of evil mailer the MTA can retrieve the DNS TXT record for fine fellow to check if fine fellow ever users evil mailer to send out messages.
fine fellow's DNS records could include
TXT "v=spf1 +a +mx -all"
This means that only the A or MX hosts send messages and -all others should fail the test ( as indicated by the - prefix to all) and those messsages should be rejected.
Detailed definition is at www.openspf.org/SPF_Record_Syntax

spamassassin "Spam detector and markup engine"

Which hosts are blacklistedmxtoolbox.com. Here you can see if YOUR host is blacklisted!

sa-heatu Heuristic Email Address Tracking Utility.


Perl method Description