Getmail and SpamAssassin

I use the SpamAssassin spam filter with my mail and it categorizes it pretty well

To get it to work with getmail I added the following to my getmail config files (I chose not to use the spamd).


[filter]
type = Filter_external
path = /usr/bin/spamassassin

Unfortunately getmail doesn’t appear to have the facility to filter messages based on their headers (SpamAsssassin, in the above configuration modifies the email header to include the line “X-Spam-Flag: YES” to indicate a message is spam), so I created a bash script which launches getmail and re-categorizes my mail if spam assassin marks it as spam. It works by grepping my maildir’s for this header and moving the file to a special spam directory if it is found.


#!/bin/bash
function spamdetect {
if [ ! -d "$1/spam/" ]
then
echo "You must create a spam direction $1/spam";
exit 1
fi

# strips out trailing slash if there is one
a=$1
if [ ${a:${#a}-1} = "/" ]
then
a=${a:0:${#a}-1}
fi

grep -H "X-Spam-Flag: YES" $a/new/* | sed "s/:.*//" | uniq | xargs -i mv '{}' $a/spam/
}

/usr/bin/getmail -r getmailrc-bob -r getmailrc-bingo

spamdetect ~/Mail/bob
spamdetect ~/Mail/bingo

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: