[Dovecot] purge maildir folder after sa-learn

Eric Shubert ejs at shubes.net
Tue May 25 22:59:07 EEST 2010


Florian Effenberger wrote:
> Hello,
> 
> I am looking for a command-line utility to automatically purge one
> Maildir folder. I want to periodically run sa-learn from cron, and
> after the spam learning folder has been added to the Bayes database,
> its contents should be deleted. I've searched a bit, but only found a
> few old utilities or some telnet+expect scripts, which both didn't
> look too reliable.
> 
> Is there any command-line utility to delete all contents of a Maildir
> folder, or is there any other solution?
> 
> Thanks,
> Florian
> 

I would write a script that cron executes, and have the script do the 
sa-learn, then delete the file.

I run qmail-toaster, which uses vpopmail for virtual domains/accounts. 
My maildirs for learning ham/spam are shared, and are named sa-learn/Ham 
and sa-learn/Spam.

Here's the script that I run in cron.daily to execute sa-learn:

#!/bin/sh
#####################################################################
# learn and remove spam and ham in shared folders
#####################################################################
# shubes 3/26/08 - created
#####################################################################

learndir="/home/vpopmail/domains/shubes.net/sa-learn"
hambox=.Ham
spambox=.Spam

do_the_learning(){

learnas=$1
maildir=$2

shopt -s extglob
for spamfile in `find $maildir/+(cur|new)/* 2>/dev/null`; do
   sudo -u vpopmail -H sa-learn --$learnas $spamfile
   rc=$?
   if [ $? != "0" ]; then
     echo "sa-learn failed, rc=$rc, spamfile=$spamfile"
     exit $rc
   fi
   rm $spamfile
done
}

do_the_learning ham  "$learndir/$hambox"
do_the_learning spam "$learndir/$spambox"

exit 0
# end of script

HTH.
-- 
-Eric 'shubes'



More information about the dovecot mailing list