DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Training Bogofilter With Virtual Imap Users

03.29.2009
| 1581 views |
  • submit to reddit
        
#!/bin/sh

#retrain_bogofilter.sh
#Version 2.0
#jkv@unixcluster.dk - free for all
#kaerast at qvox - modifications, free for all
#Prerequisites:
# - formail
# - bogofilter

# Folders for training
RETRAIN_SPAM=".SPAM.TRAIN-SPAM"
RETRAIN_HAM=".SPAM.TRAIN-HAM"
BOGOFILTER_BIN="/usr/bin/bogofilter"
DOMAIN="qvox.org"
USERS="kaerast\@qvox.org"
SUDO="sudo -u vmail"
# loop every user
for USER in $USERS; do


# create folders used by bogofilter
        for folder in $RETRAIN_SPAM $RETRAIN_HAM; do
                if [ ! -d /home/vmail/domains/$DOMAIN/$USER ]; then
                        $SUDO mkdir /home/vmail/domains/$DOMAIN/$USER
                fi
                if [ ! -d /home/vmail/domains/$DOMAIN/$USER/$folder ]; then
                        $SUDO mkdir /home/vmail/domains/$DOMAIN/$USER/$folder
                fi
                if [ ! -d /home/vmail/domains/$DOMAIN/$USER/$folder/cur ]; then 
                        $SUDO mkdir /home/vmail/domains/$DOMAIN/$USER/$folder/cur
                fi
                if [ ! -d /home/vmail/domains/$DOMAIN/$USER/$folder/new ]; then
                        $SUDO mkdir /home/vmail/domains/$DOMAIN/$USER/$folder/new
                fi
                if [ ! -d /home/vmail/domains/$DOMAIN/$USER/$folder/tmp ]; then
                        $SUDO mkdir /home/vmail/domains/$DOMAIN/$USER/$folder/tmp
                fi
        done

# train and delete files afterwards 
        for folder in $RETRAIN_SPAM $RETRAIN_HAM; do
                if [ $folder = $RETRAIN_SPAM ] ; then
                        $SUDO $BOGOFILTER_BIN -d /home/bogofilter/.bogofilter/ -s -B /home/vmail/domains/$DOMAIN/$USER/$folder
                        $SUDO rm /home/vmail/domains/$DOMAIN/$USER/$folder/cur/* 2>/dev/null
                        $SUDO rm /home/vmail/domains/$DOMAIN/$USER/$folder/new/* 2>/dev/null
                fi
                if [ $folder = $RETRAIN_HAM ] ; then
                        $SUDO $BOGOFILTER_BIN -d /home/bogofilter/.bogofilter/  -n -B /home/vmail/domains/$DOMAIN/$USER/$folder
                        $SUDO rm /home/vmail/domains/$DOMAIN/$USER/$folder/cur/* 2>/dev/null
                        $SUDO rm /home/vmail/domains/$DOMAIN/$USER/$folder/new/* 2>/dev/null
                fi

        done
done
exit 0