On 26.12.2011 16:44, Christoph Pleger wrote:
> Hello,
Hello Christoph,

>>   what is that magic you are writing about and what is that cron job? Can
>>   you post more info about it?
> On my mail server, every user's email is stored in a subdirectory of
> /mailhome/vmail/$USER directory, which also has a subdirectory spam and a
> subdirectory ham. The "magic" is an imap server (dovecot) plugin, which
> creates a copy of an email in the user's spam or in the ham subdirectory
> every time when a user moves an email to or from the Spam folder.
hmmm.... I don't think that 'magic' plugin is just doing a copy of the 
mail. It does more than just that. What plugin is that? Is it something 
you made yourself?

> The cron job runs every 15 minutes and executes the following script:
>
> #!/bin/bash
>
> for dir in /mailhome/vmail/*; do
>    USERNAME=$(basename "$dir")
>    USERNAME="${USERNAME}@plmail.de"
>    dspam_train "$USERNAME" "${dir}/spam" "${dir}/ham">  /dev/null
>    rm -f "${dir}/spam"/* "${dir}/ham"/*
> done
>
> exit 0
The script should IMHO have locks to prevent multiple run of the same 
script. Or to say it in other words: What do you do if the whole script 
takes more than 15 minutes to train spam/ham? You will have multiple 
scripts trying to do the same. This is IMHO not good. Maybe something 
like this?

#!/bin/bash

LOCKFILE="/var/run/$(basename $0 .sh).pid"
VMAILROOT="/mailhome/vmail"

if [ ! -d "${VMAILROOT}" ]; then
   echo "Missing ${VMAILROOT}"
   exit 2
fi

if [ -f "${LOCKFILE}" ]; then
   echo "$0 is already running"
   exit 2
fi

if ( set -o noclobber; echo "$$" > "${LOCKFILE}" ) 2>/dev/null; then
   trap 'rm -f "${LOCKFILE}"; exit ${?}' INT TERM EXIT
   for dir in "${VMAILROOT}"/*; do
     if [ ! -d "${dir}/spam" -o ! -d "${dir}/ham" ]; then
       echo "Missing ${dir}/spam or ${dir}/ham"
       continue
     fi
     USERNAME=$(basename "${dir}")"@plmail.de"
     dspam_train "${USERNAME}" "${dir}/spam" "${dir}/ham" >/dev/null 2>&1
     rm -f "${dir}/spam"/* "${dir}/ham"/* >/dev/null 2>&1
   done
   rm -f "${LOCKFILE}" >/dev/null 2>&1
   trap - INT TERM EXIT
exit 0



> Kind regards
>    Christoph


-- 
Kind Regards from Switzerland,

Stevan Bajić


------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Dspam-user mailing list
Dspam-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dspam-user

Reply via email to