Sun Java System Messaging Server 6.3 Administration Guide

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:


    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_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.