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

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.

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

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

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


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: