#!/bin/sh # # Iterate through user mail folders, learning from the spam in the Junk folders # and ham from the NotJunk folders. # # Check for root user if [ `whoami` != "root" ] then echo "You must be root to execute this script" exit 0; fi JUNK_FOLDER="Junk" NOT_JUNK_FOLDER="NotJunk" MAIL_STORE_PATH=`cat /etc/imapd.conf | grep partition-default | sed 's/^.* / /'` SADB="/var/amavis/.spamassassin" SA_LEARN="/usr/bin/sa-learn" LEARN_CMD="$SA_LEARN -u _amavisd --showdots --dbpath $SADB --no-sync" DATE=`date` echo "Learning Spam at ${DATE}..." if [ ! -d $MAIL_STORE_PATH ] then echo "Database path: $MAIL_STORE_PATH does not exist" exit 1 fi if [ ! -e $SA_LEARN ] then echo "Mail tool: $SA_LEARN does not exist" exit 2 fi if [ ! -e $SADB ] then echo "SA database: $SADB does not exist" exit 2 fi # Do the work! for user in `ls -1 $MAIL_STORE_PATH/user/` do JUNK_PATH=$MAIL_STORE_PATH/user/$user/$JUNK_FOLDER NOT_JUNK_PATH=$MAIL_STORE_PATH/user/$user/$NOT_JUNK_FOLDER # Learn user's SPAM if [ -d $JUNK_PATH ] then echo "Learning spam from $user" cd $JUNK_PATH for file in *. ; do if [ -f $file ]; then cat $file | su -l _amavisd $LEARN_CMD --spam fi done fi # Learn user's HAM if [ -d $NOT_JUNK_PATH ] then echo "Learning ham from $user" cd $NOT_JUNK_PATH for file in *. ; do if [ -f $file ]; then cat $file | su -l _amavisd $LEARN_CMD --ham fi done fi done # Force a database sync su -l _amavisd $SA_LEARN -u _amavisd --dbpath $SADB --sync DATE=`date` echo "Done at ${DATE}."