Return to Manual Contents Astronomy Computer Manual

Spam Filtering

Overview
How is mail modified?
Running SpamAssassin
Customizing SpamAssassin
Disabling SpamAssassin
Filtering incoming messages
  • Netscape and Mozilla
  • PINE
  • mail/mailx and others
  • Trashing SPAM automatically with procmail
    Receiving mail on another server
    SpamAssassin and Vacation

    Overview

    Current spam filtering uses SpamAssassin to analyze an incoming mail message and determine whether it is spam. The heuristic tests used by SpamAssassin allow for fairly accurate diagnosis of incoming messages. Furthermore, the behaviour of SpamAssassin can be customized by the user.

    Top of Page

    How is mail modified?

    The default system action on successful spam check is to append "SPAM:" to the beginning of the message subject line as well as to add "X-Spam-Flag: YES" to the message headers (which most of the e-mail viewers do not display until requested). The combination of the two makes spam easy to notice by the user as well as by a mail filtering program. A complete list of tests conducted on a message, message score and other SpamAssassin-related information is contained in the message headers (note that a user could remove this funtionality if he/she so desires).

    Top of Page

    Running SpamAssassin

    SpamAssassin is invoked through procmail before a new mail message is supposed to go to user's mailbox. However, if a non-empty .forward file is present in user's home directory neither procmail nor SpamAssassin will run.

    To use SpamAssassin despite the presence of .forward, your home directory must contain both .forward and .procmailrc with the following contents:

    -------------------------------- .procmailrc -----------------------------------
    #use :0c to keep a copy of the message on the server
    :0c
    # OR use :0 to simply forward the message
    #:0
    #space separated list of addresses to forward to (list must start with!)
    !user@server1.com user@server2.com
    -------------------------------- .procmailrc -----------------------------------
    
    --------------------------------- .forward -------------------------------------
    #The following line must remain or spam filter will not work
    "|procmail",
    #UNFILTERED mail will be forwarded to the following addresses (comma-separated)
    #(modify .procmailrc if you wish to forward FILTERED mail)
    user@server3.com, user@server4.com
    --------------------------------- .forward -------------------------------------
    

    Both of the above files forward incoming messages. However, addresses listed in .procmailrc will receive mail after it is scanned while addresses in .forward file will receive untouched messages.

    Top of Page

    Customizing SpamAssassin

    If addition of new preferences or modification of the defaults is desired, each user can store his/her own preferences in ${HOME}/.spamassassin/user_prefs. The most important of user options are required_hits (the higher the score, the less likely it is for mail to get tagged) and whitelist_from (a list of addresses which will NEVER be a source of spam - this option should be used for newsletters if they are incorrectly tagged).

    Top of Page

    Disabling SpamAssassin

    There are at least three distinct ways in which a user can opt-out of spam tagging:

    1. Create a .forward file with the line /var/spool/mail/your_username or an e-mail address where to receive mail (or both) and no "|procmail"
    *NOTE: This will disable any user's existing procmail filters as well*
    2. Add "all_spam_to your_username" to ${HOME}/.spamassassin/user_prefs
    3. Notify the System Administrator so that the username could be added to the all_spam_to line in global settings.

    Top of Page

    Filtering incoming messages

    Netscape and Mozilla


    - Open main Netscape Mail (or Mozilla Mail) window
    - Go to Tools->Message Filters
    - Click on New
    - Give filter a name (at the top of the window)
    - Check "Match all of the following"
    - The first line of the filter should read Subject contains SPAM:
    - Click on More and then choose Customize for the second line (fig. 1)

    Mozilla - Filter configuration (fig. 1)

    - Add a X-Spam-Flag as a new header (fig. 2)

    Mozilla - Filter configuration (fig. 2)

    - Click on OK and make the second line read X-Spam-Flag is YES
    - Choose a folder that incoming spam will be moved to (fig. 3)
    - If the folder does not exist, click on New folder button and create it.

    Mozilla - Filter configuration (fig. 3)

    - The filter is now setup.


    PINE


    - From PINE's main menu go to (S)etup-(R)ules-(F)ilters-(A)dd
    - Type C to change the name of the rule (Enter when done)
    - Scroll down to "Current Folder Type =" and use Enter to select Email
    - Scroll down to "Subject pattern =", press C and enter "SPAM:"
    - Scroll down to "AllText pattern =", press C and enter "X-Spam-Flag: YES"
    - Scroll down to "Filter action = Move", press C and enter folder for spam
    (if the folder does not exist, pine will prompt you to create it).
    - When done, press E to exit. Answer Yes when pine asks you to save.
    - Press E again and answer Yes.

    mail/mailx and others

    Mail filtering can also be done using procmail. The following is a .procmailrc file that sends all potential spam to ~/mail/SPAM while forwarding tagged mail to two other machines:

    -------------------------------- .procmailrc -----------------------------------
    #use :0c to keep a copy of the message on the server
    :0c
    # OR use :0 to simply forward the message
    #:0
    #space separated list of addresses to forward to (list must start with!)
    !user@server1.com user@server2.com
    
    # all potential spam is stored in ~/mail/SPAM
    :0:
    * ^X-Spam-Flag: YES
    ${HOME}/mail/SPAM
    -------------------------------- .procmailrc -----------------------------------
    
    To access ~/mail/SPAM from mail, simply use command folder ~/mail/SPAM.
    In general, one could use procmail for all mail filtering and add spam folder to the mail viewer.

    Top of Page

    Trashing SPAM automatically with procmail

    If you wish to dump SPAM tagged messages automatically then add the following to the beginning of your .procmailrc file:

    -------------------------------- .procmailrc -----------------------------------
    :0:
    * ^X-Spam-Flag: YES
    /dev/null
    
    ...... the rest of .procmailrc goes here....
    -------------------------------- .procmailrc -----------------------------------
    

    Top of Page

    Receiving mail on another server

    If your mail is currently forwarded from lepus to another machine using an alias and you would like to have lepus scan your mail for spam, please contact system administrators so that the alias could be disabled and appropriate .forward and .procmailrc files created.
    However, if your mail is currently forwarded using .forward file, please refer to Running SpamAssassin.

    Top of Page

    SpamAssassin and Vacation

    If you are away and need to use the vacation program but you do not want to send vacation replies to the spammers please modify .procmailrc as indicated below:

    -------------------------------- .procmailrc -----------------------------------
    #use :0c to keep a copy of the message on the server
    :0c
    # OR use :0 to simply forward the message
    #:0
    #space separated list of addresses to forward to (list must start with!)
    !user@server1.com user@server2.com
    
    # all potential spam is stored in ~/mail/SPAM
    :0:
    * ^X-Spam-Flag: YES
    ${HOME}/mail/SPAM
    
    # vacation handles the remaining messages
    # if you use aliases run vacation with -a flag and a list of aliases following it
    #  (see vacation manpage)
    :0c
    |/usr/bin/vacation $LOGNAME
    -------------------------------- .procmailrc -----------------------------------
    
    Please keep in mind that .vacation.db in your home directory has to be initialized with
    vacation -I
    before using vacation. Finally, appropriate .vacation.msg file needs to be created (please consult vacation manpage for further details on this).

    NOTE: If you accidently run vacation with no arguments vacation will create a .forward file and move your old .forward to .forward.old. You will need to overwrite the new file with .forward.old. In this situation vacation will also create .vacation.msg.

    Top of Page