Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Training Bogofilter with virtual imap users
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment