Bogofilter Training on a per user level

create the environment

  • create the directory for bogofilter User Databases
    • mkdir -p /var/lib/mail/user1/bogodb /var/lib/mail/user2/bogodb …
  • set the permissions
    • find /var/lib/mail/ -type d -exec chmod 770 {} \;
    • find /var/lib/mail/ -type f -exec chmod 660 {} \;
    • chown dbmail:root /var/lib/mail/

create the scripts

  • create the bogofilter training script
    • /usr/sbin/bogolearn.sh
#!/bin/bash
USER=$1
WORKDIR="/var/lib/mail/$USER"
EXP_SPAM="$WORKDIR/SPAM"
EXP_HAM="$WORKDIR/HAM"
BOGODB="$WORKDIR/bogodb"
MBX_SPAM="INBOX/Spamtraining/add2spam"
MBX_HAM="INBOX/Spamtraining/add2ham"

echo delete the exported Mailbox...
rm -fv $EXP_SPAM
rm -fv $EXP_HAM

echo export Mailbox and delete exported mails...
/usr/sbin/dbmail-export -u $USER -m $MBX_HAM -o $EXP_HAM -d
/usr/sbin/dbmail-export -u $USER -m $MBX_SPAM -o $EXP_SPAM -d

echo backup wordlist...
bogoutil -d $BOGODB/wordlist.db |bogoutil -l $BOGODB/wordlist.db.backup

echo train Bogofilter...
bogofilter -M -I $EXP_SPAM -d $BOGODB -e -v -s
bogofilter -M -I $EXP_HAM -d $BOGODB -e -v -n

echo delete the exported Mailbox...
rm -fv $EXP_SPAM
rm -fv $EXP_HAM
  • set the permissions
    • chown dbmail:root /usr/sbin/bogolearn.sh
    • chmod 570 /usr/sbin/bogolearn.sh
  • add a cron schedule
    • /etc/cron.d/bogofilter_learn
1 2 * * * dbmail /usr/sbin/bogolearn.sh user1
3 2 * * * dbmail /usr/sbin/bogolearn.sh user2
 
bogofilter.txt · Last modified: 2012/02/27 21:33 by bas
 
DBMail is developed by Paul J Stevens together with developers world-wide