Training SpamAssassin for Effective Spam Removal

Intro

SpamAssassin is a tool to remove Spam from incoming email. The following describes a way of training Spam Assassin to be more effective.

Background

Email is stored within Cyrus, and mail that gets through SpamAssassin into a user's inbox is then moved to the "put_spam_here" folder by the user.

This script is run hourly, empties the "put_spam_here" folder, and hopefully trains spamassassin to catch more spam.

The Script

#!/bin/bash
PATH=/bin:/usr/bin:/usr/sbin:/sbin
export PATH
  
set -e #set -x

if [ -d /tmp/assassin ]; then
    echo "erk.. /tmp/assassin exists"
    exit 2
fi

trap "/bin/rm -Rf /tmp/assassin" EXIT SIGKILL SIGTERM SIGQUIT

mkdir -p /tmp/assassin

found=no

for f in /var/spool/cyrus/mail/p/put_spam_here/*
do
    if echo $f | grep "[0-9]" > /dev/null
    then
        # echo "Spam to fry"
        found=yes
    fi
done

if [ $found != "yes" ]
then
    # echo "nothing to fry"  
    exit 0
fi

for f in /var/spool/cyrus/mail/p/put_spam_here/[0-9]*
do
    mv $f /tmp/assassin/
done

su - cyrus -c "/usr/sbin/cyrreconstruct put_spam_here >/dev/null"

for f in /tmp/assassin/* 
do 
    /usr/bin/sa-learn --spam $f >/dev/null
done

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
We don't take kindly to automated nonsensible adverts around here.