#!/bin/bash # # Script to learn spam using sa-learn and delete it if it's # older than 14 days. Just edit the default names of your # spam folder and deleted items folders using the variables # below. # SPAM_FOLDER=spam DELETED_FOLDER=trash # # ######################################## DOMAIN_LIST=`ls /home/vpopmail/domains/` SALEARN=`which sa-learn` LEARN_SPAM="$SALEARN --no-sync --spam" LEARN_HAM="$SALEARN --no-sync --ham" VPOPMAIL_HOME=/home/vpopmail/domains for DOMAIN in $DOMAIN_LIST; do DOMAIN_USERS="`ls /home/vpopmail/domains/$DOMAIN/ --ignore=vpasswd --ignore=vpasswd.cdb --ignore=postmaster`" for USER in $DOMAIN_USERS; do HAM_FOLDERS="`ls $VPOPMAIL_HOME/$DOMAIN/$USER/Maildir/ -A --ignore=courier* --ignore=$SPAM_FOLDER --ignore=$DELETED_FOLDER --ignore=cur --ignore=new --ignore=tmp`" $LEARN_SPAM $VPOPMAIL_HOME/$DOMAIN/$USER/Maildir/$SPAM_FOLDER/cur find $VPOPMAIL_HOME/$DOMAIN/$USER/Maildir/$SPAM_FOLDER/cur -mtime +14 -exec rm -f "{}" ";" find $VPOPMAIL_HOME/$DOMAIN/$USER/Maildir/cur -mtime +14 -exec $LEARN_HAM "{}" ";" for HAM in $HAM_FOLDERS; do $LEARN_HAM $VPOPMAIL_HOME/$DOMAIN/$USER/Maildir/$HAM/cur done done done $SALEARN --sync