Bits and thoughts

#!/bin/bash is not rude

Adapt bayesian filters for spam on server

Written by ⓘⓓⓔⓝⓣⓛⓤⓓ - -

When the detection of spam is activated through spamassassin on the server it would be gold to have the spamassassin daemon to learn what is spam and what is not.

One way to do that is to write a simple script that could be run manually or through a crontab entry :

#!/usr/bin/env bash
basedir=Maildir
ls -d $basedir/.* |  while read dir
do
        processedPart=$(basename "$dir")
        if [ "$processedPart" != "." -a "$processedPart" != ".." ]
        then
                echo -n Processing $processedPart ...
                if [ "$processedPart" == ".Spam" -o "$processedPart" == ".Pourriels" ]
                then
                        echo as SPAM
                        sa-learn --spam "$basedir/$processedPart/{cur,new}"
                else
                        echo as ham
                        sa-learn --ham "$basedir/$processedPart/{cur,new}"
                fi
        fi
done

Of course ".Spam" and ".Pourriels" ara my own choices for IMAP folders to contain spam. Update this script with your own preferences.
I have placed this script in a "spam" file in ~/bin to run it manually.




Comments are closed.