User Tools

Site Tools


Sidebar

documentation:systemes:services:mail:spamassassin:sa-learn

Table of Contents

SA-Learn

Introduction

SpamAssassin c'est très bien pour détecter les Spams, encore faut il qu'il sache à quoi ressemble un spam…

Le code

Le script :

vim /usr/local/sbin/sa-virtual-user-learn
#!/bin/bash
 
# Script, which allows per-user bayes db's for a dovecot virtual user
# setup. sa-learn parses a set amount of folders (.Junk.Spam and .Junk.Ham) for
# Ham/Spam and adds it to the per-user db.
 
MAIL_DIR=/var/mail
SPAMASS_DIR=/var/lib/spamassassin
SPAM_FOLDER=".Junk.Spam"
HAM_FOLDER=".Junk.Ham"
 
# get all mail accounts
for domain in $MAIL_DIR/*; do
        for user in $MAIL_DIR/${domain##*/}/*; do
                mailaccount=${user##*/}
                dbpath=$SPAMASS_DIR/${domain##*/}/$mailaccount
                spamfolder=${domain}/${mailaccount}/Maildir/$SPAM_FOLDER
                hamfolder=${domain}/${mailaccount}/Maildir/$HAM_FOLDER
 
                if [ -d $spamfolder ] ; then
                        [ ! -d $dbpath ] && mkdir -p ${dbpath}
                        echo "Learning Spam from ${spamfolder} for user ${mailaccount}"
                        nice sa-learn --spam --dbpath ${dbpath}/bayes
                                --no-sync ${spamfolder}
                fi
 
                if [ -d $hamfolder ] ; then
                        echo "Learning Ham from ${hamfolder} for user ${mailaccount}"
                        nice sa-learn --ham --dbpath ${dbpath}/bayes
                                --no-sync ${hamfolder}
                fi
 
                if [ -d $spamfolder -o -d $hamfolder ] ; then
                        nice sa-learn --sync --dbpath $dbpath
 
                        # Fix dbpath permissions
                        chown -R mail.mail ${dbpath}
                        chmod 700 ${dbpath}
                fi
        done
done
chmod +x /usr/local/sbin/sa-virtual-user-learn

Puis on rajoute une ligne dans crontab :

crontab -e
0 0 * * * /usr/local/sbin/sa-virtual-user-learn

Chaque utilisateur peut alors créer 2 dossiers dans son arborescence mail :

Junk/Spam
Junk/Ham

Source

documentation/systemes/services/mail/spamassassin/sa-learn.txt · Last modified: 2017/07/14 19:45 (external edit)