#!/bin/sh
SA_LEARN_PATH="/usr/bin/sa-learn"
JUNK_MAIL_USER="user/junkmail"
NOT_JUNK_MAIL_USER="user/notjunkmail"
MAIL_STORE_PATH=`cat /etc/imapd.conf | grep partition-default | sed 's/^.* / /'`
if [ `whoami` != "root" ]
then
echo "You must be root to execute this script"
exit 0;
fi
if [ ! -d $MAIL_STORE_PATH ]
then
echo "Database path: $MAIL_STORE_PATH does not exist"
exit 1
fi
if [ ! -e $SA_LEARN_PATH ]
then
echo "Mail tool: $SA_LEARN_PATH does not exist"
exit 2
fi
if [ -d $MAIL_STORE_PATH/$JUNK_MAIL_USER ]
then
echo "Learning what is junk mail"
cd $MAIL_STORE_PATH/$JUNK_MAIL_USER
for file in *. ; do
if [ -f $file ]; then
cat $file | su - clamav -c "sa-learn --spam --no-sync >> /dev/null";
fi
done
fi
if [ -d $MAIL_STORE_PATH/$NOT_JUNK_MAIL_USER ]
then
echo "Learning what is not junk mail"
cd $MAIL_STORE_PATH/$NOT_JUNK_MAIL_USER
for file in *. ; do
if [ -f $file ]; then
cat $file | su - clamav -c "sa-learn --ham --no-sync >> /dev/null";
fi
done
fi
su - clamav -c "sa-learn --sync >> /dev/null"