You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by LuKreme <kr...@kreme.com> on 2007/06/01 09:31:01 UTC

Re: create script sa-learn

On 14-May-2007, at 05:46, Bruno Henrique de Oliveira wrote:
> Necessary of aid to create one script that it reads the
> folder .Trainings inside of the Maildir of the user and train as Spam.
> Soon after the trainings the same script has that to move this message
> for the Inbox of a called user Spam. One of the problems and use of  
> the
> vpopmail, the users of the same are not recorded in the /etc/shadow
> archive. Suggestions of as to mount this script are comings well.

This is what I use:
#/bin/sh
#
# Straightforward shell script to be run as root.  This parses the /home
# directory for mailboxes named sa-learn-sapm and sa-learn-ham and runs
# sa-learn against them as the user.

# sa-learn-script (sal) v1.0  Lewis Butler, released to the Public  
Domain 2007
#
# $PREFIX is the prefix for the mailbox name, the two SUFFIX variable  
for
# each type of mail, and the MAILP for the path from $HOME to the mboxes
# to learn, the default is:
#
# /home/<user>/Mail/sa-learn-ham
# /home/<user>/Mail/sa-learn-spam

PREFIX="sa-learn-";
SPAMSUFFIX="spam";
HAMSUFFIX="ham";
USERROOT="/home";
MAILP="Mail/$PREFIX";

MYDATE=`date '+%d-%b-%Y'`;
#echo "$MYDATE";
for i in `ls $USERROOT/` ; do
    S_PATH="$USERROOT/$i/${MAILP}$SPAMSUFFIX";
    H_PATH="$USERROOT/$i/${MAILP}$HAMSUFFIX";

    #echo "";
    #echo "Checking user: $i";

# Don't run sa-learn if there is no such mbox, or if the mbox is empty
if test -s $S_PATH; then
    # echo -n "$i Processing Spam: ";
    /usr/local/bin/sa-learn --spam --mbox -u $i $S_PATH
    /usr/local/bin/sudo -u $i sh -c "cat $S_PATH >> ${S_PATH}-$MYDATE  
&& \
    cat /dev/null >  $S_PATH";
fi

# Don't run sa-learn if there is no such mbox, or if the mbox is empty
if test -s $H_PATH; then
    # echo -n "$i Processing Ham : ";
    /usr/local/bin/sa-learn --ham --mbox -u $i $H_PATH
    /usr/local/bin/sudo -u $i sh -c "cat $H_PATH >> ${H_PATH}-$MYDATE  
&& \
    cat /dev/null >  $H_PATH";
fi

#echo "$i DONE";
done

This, however, works just as well for most purposes and is much much  
shorter (in fact, it works well as a one liner).

for i in `ls /home/`;
   do find /home/$i/Mail/sa-learn-spam | sa-learn --spam --mbox -u $i;
   sa-learn --ham --mbox -u $i /home/$i/Mail/sa-learn-ham;
   echo "$i DONE";
done

> Vpopmail

Ah... er... well, not familiar with vpopmail...

-- 
Rumour is information distilled so finely that it can filter through  
anything. It does not need doors and windows -- sometimes it does not  
need people. It can exist free and wild, running from ear to ear  
without ever touching lips.