Outils pour utilisateurs

Outils du site


linux:scripts_bash:checkspam

Pour parcourir les boîtes aux lettres de chaque utilisateur, et alimenter “l'apprentissage” de spamassassin.

#!/bin/bash
# Ce script parcours chaque BAL pour donner le contenu des dossiers $SPAM et $HAM à sa-learn
 
MBROOT=/home/mail
MBUSER=mailboxes
SPAM=.Junk.Spam-non-detecte
HAM=.Junk.Spam-detecte-a-tord
TMPD="$MBROOT/dirList.tmp"
TMPF="$MBROOT/fileList.tmp"
 
function checkDirExists() {
  # on créé les dossiers SPAM & HAM s'ils n'existent pas
  find -L "$MBROOT" -maxdepth 2 -mindepth 2 -type d|while read box
  do
    [ -d "$box/$SPAM" ] || (mkdir "$box/$SPAM"; chown $MBUSER:$MBUSER "$box/$SPAM";)
    [ -d "$box/$HAM" ] || (mkdir "$box/$HAM"; chown $MBUSER:$MBUSER "$box/$HAM";)
  done
}
 
function learnSpam() {
  # on liste les dossiers
  find -L "$MBROOT" -maxdepth 3 -mindepth 3 -name "$SPAM" -type d > "$TMPD"
  # init liste des spams
  >"$TMPF"
  # on liste les spam
  while read spamDir
  do
    find "$spamDir" -type f >> "$TMPF"
  done < "$TMPD"
  # on vire les fichiers dovecot du résultat
  sed -i -e '/dovecot/d' "$TMPF"
  # on les donne à sa-learn et on les efface
  while read spam
  do
    sa-learn --spam "$spam" > /dev/null && rm -f "$spam"
  done<"$TMPF"
}
 
function learnHam() {
  find -L "$MBROOT" -maxdepth 3 -mindepth 3 -name "$HAM" -type d > "$TMPD"
  # init liste des hams
  >"$TMPF"
  # on liste les spam
  while read hamDir
  do
    find "$hamDir" -type f >> "$TMPF"
  done < "$TMPD"
  # on vire les index du résultat
  sed -i -e '/dovecot/d' "$TMPF"
  # on les donne à sa-learn et on les mets dans inbox
  while read ham
  do
    new="`echo $ham|sed -e "s#$HAM/[a-z]*/#cur/#"`"
    sa-learn --ham "$ham" > /dev/null && mv "$ham" "$new"
  done<"$TMPF"
}
 
# main
checkDirExists
learnSpam
learnHam
linux/scripts_bash/checkspam.txt · Dernière modification : 27/11/2008 23:47 de daniel