• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Spamassasin learn (sa-learn)

F

fdomartin

Guest
Hi,

I'm using sa-learn for update rules of spamassassin.

I make a cron job for 'popuser' like this:

/usr/bin/sa-learn --spam /var/qmail/mailnames/tecneca.net/admin/Maildir/.spam/cur/ -C /etc/mail/spamassassin

and

/usr/bin/sa-learn --han /var/qmail/mailnames/tecneca.net/admin/Maildir/.no-spam/cur/ -C /etc/mail/spamassassin

Is that correct?

This learn if for all users ?

How do I'm sure SA is learing?

How can I restart SA from a shell ?
 
that would only do it for the user you're running sa-learn as, in this case root. I kind of hacked something together to do sa-learn on a per-user basis. In my case, I store all my spamassassin settings in mysql, so the following probably wont help anyone that isnt using mysql, and spamassassin 3.0

step 1) make a directory, call it users/ this directory will contain subdirectories for each user you want to enable this for. Use username@domainname for the format

step 2) create a local.cf in the username@domainname dir

step 3) copy your /etc/mail/spamassassin/local.cf to that dir

step 4) add this line to it:
bayes_sql_override_username username@domainname

step 5) I use this script to automate spam learning, the last line is what youd use. The template stuff is how I automate building the local.cf files.

#!/bin/sh

SALEARN="/usr/bin/sa-learn"
CONFDIR="/usr/share/atomic-mail-scanner/users"

USER=$1

echo "Updating: $1"

if [ ! -d $CONFDIR/$USER ]; then
mkdir $CONFDIR/$USER
fi

if [ ! -f $USER/local.cf ]; then
sed s/CHANGEME/$USER/ $CONFDIR/template.cf > $CONFDIR/$USER/local.cf
fi

$SALEARN --siteconfigpath=$CONFDIR/$USER/ --showdots --spam "$2"


step 6) Same thing, but for ham
#!/bin/sh

SALEARN="/usr/bin/sa-learn"
CONFDIR="/usr/share/atomic-mail-scanner/users"

USER=$1

echo "learning ham for: $1"
if [ ! -d $CONFDIR/$USER ]; then
mkdir $CONFDIR/$USER
fi

if [ ! -f $USER/local.cf ]; then
sed s/CHANGEME/$USER/ $CONFDIR/template.cf > $CONFDIR/$USER/local.cf
fi

$SALEARN --siteconfigpath=$CONFDIR/$USER/ --showdots --ham "$2"


step 7) write a wrapper to run this for all your users. Heres mine, YMMV, since I use spamtraps, and archive spam for research purposes.

#!/bin/sh
# bulk ham importer
# v 0.1

SALEARN="/usr/share/atomic-mail-scanner/users/ham-learner.sh"
SPAMTRAP1="/var/qmail/mailnames/atomicrocketturtle.com/spamtrap/Maildir/cur"
SPAMTRAP2="/var/qmail/mailnames/atomicrocketturtle.com/spamtrap/Maildir/new"
ARCHIVE="/root/spam/archive/"

if [ -f /tmp/atomic-bulk ]; then
echo "scan is running"
exit 0
fi

# create lock file
touch /tmp/atomic-bulk

for i in `find /var/qmail/mailnames/ -name .Learn\ FP -type d |sed s/Learn\ FP/Learn_FP/ `; do
USER=`echo "$i"| awk -F\/ '{print $6"@"$5}' |grep -v ^@`
DIR=`echo $i | sed s/Learn_FP/Learn\ FP/`
echo "Processing HAM for $USER"
#echo "$DIR/cur"
#ls -la "$DIR/cur"
echo "Deleting mail from $DIR/cur/"
$SALEARN $USER "$DIR/cur"
rm -f $DIR/cur/*
done



SALEARN="/usr/share/atomic-mail-scanner/users/spam-learner.sh"
for i in `find /var/qmail/mailnames/ -name .Learn\ Spam -type d |sed s/Learn\ Spam/Learn_Spam/ `; do
USER=`echo "$i"| awk -F\/ '{print $6"@"$5}' |grep -v ^@`
DIR=`echo $i | sed s/Learn_Spam/Learn\ Spam/`
echo "Processing SPAM for $USER"
#echo "$DIR/cur"
#ls -la "$DIR/cur"
$SALEARN $USER "$DIR/cur"
echo "Deleting mail from $DIR/cur/"
rm -f $DIR/cur/*
#exit
done

if [ ! -d $ARCHIVE ]; then
mkdir -p $ARCHIVE
fi


Note: sa-learn can just kill a box in terms of resource usage. My next kooky idea is to modify this so it does it over imap, that way it can run on remote folders and offload some of the processessing to another box.
 
I read Plesk only is not compatible with SA 3.0.

SA 2.63 can work with rules on mysql ?

I'm running cron job under 'popuser' he is the owner of ALL maildirs. And I'm using imap folder to copy the spam mails for check.

[root@servidor Maildir]# ls -al
total 36
drwx------ 8 popuser popuser 4096 Jan 15 04:34 .
drwx------ 5 popuser popuser 4096 Jan 15 20:11 ..
drwx------ 2 popuser popuser 4096 Jan 16 22:46 courierimapkeywords
-rw-r--r-- 1 popuser popuser 95 Jan 16 22:31 courierimapuiddb
drwx------ 2 popuser popuser 4096 Jan 16 22:31 cur
drwx------ 2 popuser popuser 4096 Jan 15 20:11 new
drwx------ 6 popuser popuser 4096 Jan 15 04:49 .no-spam
drwx------ 6 popuser popuser 4096 Jan 15 04:49 .spam
drwx------ 2 popuser popuser 4096 Jan 19 17:23 tmp
[root@servidor Maildir]# pwd
/var/qmail/mailnames/tecneca.net/admin/Maildir
 
Back
Top