Sun Java System Messaging Server 6.3 Administration Guide

14.4.5 SpamAssassin Configuration Examples

This section describes some common SpamAssassin configuration examples:


Note –

These examples use a number of options and keywords. Refer to 12.12.5 Spam Filter Keywords and Table 14–1.


ProcedureTo File Spam to a Separate Folder

This example tests messages arriving at the local message store and files spam into a folder called spam. The first three steps can be done in any order.

  1. Create the SpamAssassin configuration file.

    The name and location of this file is specified in Step 2. A good name is spamassassin.opt. This file contains the following lines:


    host=127.0.0.1
    port=2000
    mode=0
    verdict=spam
    debug=1
                      

    host and port specify the name of the system where spamd is running and the port on which spamd listens for incoming requests. mode=0 specifies that a string, specified by verdict, is returned if the message is perceived as spam. debug=1 turns on debugging in the SpamAssassin library. See Table 14–3

  2. Add the following lines to the option.dat file:


    ! for Spamassassin
    spamfilter1_config_file=/opt/SUNWmsgsr/config/spamassassin.opt
    spamfilter1_library=/opt/SUNWmsgsr/lib/libspamass.so
    spamfilter1_optional=1
    spamfilter1_string_action=data:,require "fileinto"; fileinto "$U";
                      

    spamfilter1_config_file specifies the SpamAssassin configuration file.

    spamfilter1_library specifies the SpamAssassin shared library.

    spamfilter1_optional=1 specifies that the MTA continue operation if there is a failure by spamd.

    spamfilter1_string_action specifies the Sieve action to take for a spam messages.

    In this example, spamfilter1_string_action is not necessary because the default value already is data:,require "fileinto"; fileinto "$U";. This line specifies that spam messages are sent to a folder. The name of the folder is the spam verdict value returned by SpamAssassin. The value returned by SpamAssassin is specified by the verdict option in spamassassin.opt. (See Step 1.) In this case, the folder name is spam.

  3. Specify the messages to be filtered.

    To filter all messages coming into the local message store, change the imta.cnf file by adding the destinationspamfilterXoptin spam keywords on the ims-ms channel:


    !
    ! ims-ms
    ims-ms defragment subdirs 20 notices 1 7 14 21 28 backoff "pt5m" "pt10m" 
    "pt30m" "pt1h"  "pt2h" "pt4h" maxjobs 4 pool IMS_POOL fileinto
    $U+$S@$D destinationspamfilter1optin spam
    ims-ms-daemon
  4. Recompile the configuration and restart the server. Only the MTA needs to be restarted. You do not need to execute stop-msg.


    # imsimta cnbuild
    # imsimta restart
    
  5. Start the spamd daemon. This is normally done with a command of the form:

    spamd -d

    spamd defaults to only accepting connections from the local system. If SpamAssassin and Messaging Server are running on different systems, this syntax is required:

    spamd -d -i listen_ip_address -A allowed_hosts

    where listen_ip_address is the address on which to listen and allowed_hosts is a list of authorized hosts or networks (using IP addresses) which can connect to this spamd instance.


    Note –

    0.0.0.0 can be used with -i listen_ip_address to have spamd listen on all addresses. Listening on all addresses is preferable because it spamfilterX_verdict_n avoids having to change command scripts when changing a system’s IP address.


ProcedureTo Add a Header Containing SpamAssassin Score to Spam Messages

This example adds the header Spam-test: result string to messages determined to be spam by SpamAssassin. An example header might be:

Spam-test: True ; 7.3 / 5.0

where Spam-test: is a literal and everything after that is the result string. True means that it is spam (false would be not spam). 7.3 is the SpamAssassin score. 5.0 is the threshold. This result is useful for setting up a Sieve filter that can file or discard mail above or between a certain score.

In addition, setting USE_CHECK to 0 returns the list of SpamAssassin tests that matched along with the verdict string. See USE_CHECK in Table 14–3.

  1. Specify the messages to be filtered. This is described in Step 3 in To File Spam to a Separate Folder

  2. Create the SpamAssassin configuration file.

    The name and location of this file is specified with spamfilter_configX_file (see next step). It consists of the following lines:


    host=127.0.0.1
    port=2000
    mode=1
    field=
    debug=1
                      

    host and port specify the name of the system where spamd is running and the port on which spamd listens for incoming requests. mode=1 specifies that the SpamAssassin result string is returned if the message is found to be spam. field= specifies a string prefix for the SpamAssassin result string. In this example, a prefix is not desired because we are specifying it in the Sieve script. debug=1 turns on debugging in the SpamAssassin library.

  3. Add the following lines to the option.dat file:


    !for Spamassassin
    spamfilter1_config_file=/opt/SUNWmsgsr/config/spamassassin.opt
    spamfilter1_library=/opt/SUNWmsgsr/lib/libspamass.so
    spamfilter1_optional=1
    spamfilter1_string_action=data:,require ["addheader"];addheader "Spam-test: $U";
    

    As in previous examples, the first three options specify the SpamAssassin configuration file, shared library, and to continue MTA operation if there is a failure by the shared library. The following line:

    spamfilter1_string_action=data:,require ["addheader"];addheader "Spam-test: $U";

    specifies that a header is added to spam messages. The header has the literal prefix Spam-text: followed by the string returned by SpamAssassin. Because mode=1 was specified in the previous step, the SpamAssassin result string is returned. For example: True; 7.3/5.0

  4. Recompile the configuration, restart the server and start the spamd daemon.

    See 14.4.5 SpamAssassin Configuration Examples.

ProcedureTo Add the SpamAssassin Result String to the Subject Line

By adding the SpamAssassin result string to the Subject line, users can determine whether they wish to read a message with a SpamAssassin score. For example:

Subject: [SPAM True ; 99.3 / 5.0] Free Money At Home with Prescription Xanirex!

Note that setting USE_CHECK to 0 returns the list of SpamAssassin tests that matched along with the verdict string (see 14.4.7 SpamAssassin Options in 14.4.7 SpamAssassin Options). This list can be very long, so it is best to set USE_CHECK to 1.

  1. Specify the messages to be filtered.

    See Step 3 in To File Spam to a Separate Folder

  2. Create the SpamAssassin configuration file.

    This step is described in To File Spam to a Separate Folder. mode=1 specifies that the SpamAssassin result string is returned if the message is found to be spam.


    host=127.0.0.1
    port=2000
    mode=1
    debug=1
                      

    host and port specify the name of the system where spamd is running and the port on which spamd listens for incoming requests. mode=1 specifies that the SpamAssassin result string is returned if the message is spam. debug=1 turns on debugging in the SpamAssassin library.

  3. Add the following lines to the option.dat file:


    !for Spamassassin
    spamfilter1_config_file=/opt/SUNWmsgsr/config/spamassassin.opt
    spamfilter1_library=/opt/SUNWmsgsr/lib/libspamass.so
    spamfilter1_optional=1
    spamfilter1_string_action=data:,addtag “[SPAM detected: $U]”;
                      
    

    As in previous examples, the first three options specify the SpamAssassin configuration file, shared library, and to continue MTA operation if there is a failure by the shared library. The following line

    spamfilter1_string_action=data:,addtag “[SPAM detected $U]”;

    specifies that a tag be added to the Subject: line. It has the literal prefix SPAM detected followed by the field string (default: Spam-Test) followed by “[result string]” returned by SpamAssassin. Because mode=1 was specified in 14.4.5 SpamAssassin Configuration Examples, the SpamAssassin result string is returned. Thus, a subject line looks something like this:

    Subject: [SPAM detected Spam-Test: True ; 11.3 / 5.0] Make Money!

    You can also use addheader and addtag together:

    spamfilter1_string_action=data:,require ["addheader"];addtag "[SPAM detected $U]";addheader "Spamscore: $U";

    to get a message like this:

    Subject: [SPAM detected Spam-Test: True ; 12.3 / 5.0] Vigaro Now!Spamscore: Spam-Test: True ; 12.3 / 5.0

    Set field= in spamassassin.opt to remove the default value of Spam-Test. A cleaner message is returned:

    Subject: [SPAM True ; 91.3 / 5.0] Vigaro Now!Spamscore: True ; 91.3 / 5.0

  4. Recompile the configuration, restart the server and start the spamd daemon.

    See To File Spam to a Separate Folder.

ProcedureTo Filter Messages Based on SpamAssassin Score

This example shows how to filter messages based on a SpamAssassin score. It uses the spamadjust and spamtest Sieve filter actions. In this example, a header containing the SpamAssassin score is added to all messages. This header can be used by the SpamAssassin software administrator to tune SpamAssassin for improved spam email detection. If the message has a SpamAssassin score between 5 and 10, the message is filtered to a spam folder within the user's account. If the message has a SpamAssassin score greater then 10, the message is discarded. Note that by default SpamAssassin considers messages with a score of 5 and greater to be spam.

  1. Specify the messages to be filtered.

    This is described in Step 3 of To File Spam to a Separate Folder.

  2. Create the SpamAssassin configuration file.

    The name and location of this file is specified with spamfilter_configX_file (see next step). It consists of the following lines:


    debug=1
    host=127.0.0.1 
    port=783 
    mode=2 
    field=  

    host and port specify the name of the system where spamd is running and the port on which spamd listens for incoming requests. mode=2 specifies that the SpamAssassin result string is always returned regardless of the score. field= specifies a string prefix for the SpamAssassin result string. In this example, a prefix is not desired because we are specifying it in the Sieve script. debug=1 turns on debugging in the SpamAssassin library.

  3. Add the following lines to the option.dat file


    ! For SpamAssassin
    spamfilter1_config_file=/opt/SUNWmsgsr/config/spamassassin.opt
    spamfilter1_library=/opt/SUNWmsgsr/lib/libspamass.so
    spamfilter1_optional=1
    spamfilter1_string_action=data:, require ["addheader","spamtest"]; \
    spamadjust "$U"; addheader "Spam-test: $U"

    As in previous examples, the first three lines specify the SpamAssassin configuration file, shared library, and to continue MTA operation if there is a failure by the shared library. The last two lines specify that the SpamAssassin score should be extracted from the return string from SpamAssassin ($U), which is used in the spamtest operation, and a spam score header should be added to all messages (for example, Spam-test: True; 7.3/5.0)

  4. Create a channel level filter to process the email based on the spam score.

    Refer to To Create a Channel-level Filter. Add the following rule to that file:


    require ["spamtest","relational","comparator-i;ascii-numeric","fileinto"];
    if spamtest :value "ge" :comparator "i;ascii-numeric" "10" {discard;}
    elsif spamtest :value "ge" :comparator "i;ascii-numeric" "5" {fileinto "spam";}
    else {keep;}

    The second line discards the spam email if the SpamAssassin score is greater or equal to 10. The third line files the email to the users "spam" folder if the score is greater or equal to 5. The last line else {keep;} keeps all messages which received a score less then 5.

  5. Recompile the configuration, restart the server and start the spamd daemon

    See the final steps in To File Spam to a Separate Folder.