Como instruir a SpamAssasin en Alojamientos basados en cPanel

Leyendo los foros de mi proveedor de alojamiento www.bluehost.com encontré un hilo muy interesante sobre como instruir SpamAssassin y después de darle unas cuantas vueltas hice este script para añadir la funcionalidad de que SpamAssasin aprenda de las preferencias de lo que los usuarios han marcado como SPAM o NO SPAM.

Esto significa que con un solo script se añade la funcionalidad de “Marcar como Spam”  o bien “No es Spam”  que tienen algunos de los mas famosos webmails gratuitos Gmail, Yahoo, etc . Y por supuesto que SpamAssasin aprenda de ello  para todas las cuentas de todos los dominios que tengamos alojados. Eso si, siempre que la empresa de alojamiento este basada en cPanel.

El script lo hice en la lengua de Benny Hill pero es auto explicativo:

#!/bin/sh
# InstruirSpamAssassin.sh
# TEACH YOUR SPAMASSASSIN script for cpanel (www.bluehost.com in this case) hosting accounts
# This script teach your SPAMASSASIN daemon with HAM and SPAMUNCAUGTH from all the emails accounts of all your domains

#"THE BEER-WARE LICENSE" (Revision 42):
#Juan Sierra Pons wrote this file. As long as you retain this notice you
#can do whatever you want with this stuff. If we meet some day, and you
#think this stuff is worth it, you can buy me a beer in return.
#Juan Sierra Pons - juan [at} elsotanillo {dot] net
#http://www.elsotanillo.net/
#Original beerware license is due to Poul-Henning Kamp.

#SPAMASSASSIN CONFIGURATION
#1.- Turn On Spamassasin: cPanel->Email Manager->Spam Assassin-> "Enable Spam Assassin"
#2.- Turn on Bayes (auto learning for SA) "Configure Spam Assassin" -> check the box for "use-bayes".

#HOW TO SET UP USERS' EMAIL ACCOUNT
#### always use the same name for HAM and UnCaughtSpam for all yours users
# 1.- Create one folder for SPAMHAM
# 2.- Create one folder for SPAMUNCAUGTH

#USERS' INSTRUCTIONS
# 1.- Move all your UnCaughtSpam messages to your UnCaughtSpam folder
# 2.- Move all your HAM messages to your HAM folder

#HOW TO USE THIS SCRIPT:
# 1.- Fill the LOGIN variable
# 2.- Fill the SPAMHAMDIRECTORY variable
# 3.- Fill the SPAMUNCAUGTH variable
# 4.- Run this script using the crontab daemon once a day for example
# 5.- After you check all is running ok for you, you can comment LOGSALEARN and LOGDEBUG lines

########################## Variables ###########################
LOGIN="logincpanel"
SPAMHAMDIRECTORY="SpamHam"
SPAMUNCAUGTH="SpamNoCogido"
### uncoment next line if you want to run sa-learn in verbose mode
#LOGSALEARN="-D"
### LOGDEBUG=0 if you wan to see which accounts are being checked - only for debugging pourposes
LOGDEBUG=0
### MOVESPAMHAMMESSAGES=0 if you want to move SPAMHAM messages to each INBOX directory after teach your spamassasin
MOVESPAMHAMMESSAGES=1
### CLEANSPAMUNCAUGTHMESSAGES=0 if you want clean SPAMUNCAUGTH directory after teach your spamassassin
CLEANSPAMUNCAUGTHMESSAGES=1
################################################## ##############
for i in /home/$LOGIN/mail/*/*
do
##### Teach SpamAssassin with HAM messages from SPAMHAM directory
if [ $LOGDEBUG = 0 ] ;then echo ===== Checking $i/.$SPAMHAMDIRECTORY ========================== ; fi
if test -d $i/.$SPAMHAMDIRECTORY/new; then nice -n 19 sa-learn $LOGSALEARN --ham --dir $i/.$SPAMHAMDIRECTORY/new; fi
if test -d $i/.$SPAMHAMDIRECTORY/cur; then nice -n 19 sa-learn $LOGSALEARN --ham --dir $i/.$SPAMHAMDIRECTORY/cur; fi
##### move SPAMHAM messages to each INBOX directory
if [ $MOVESPAMHAMMESSAGES = 0 ]
then mv $i/.$SPAMHAMDIRECTORY/new/* $i/new ;mv $i/.$SPAMHAMDIRECTORY/cur/* $i/cur
fi
##### Teach SpamAssassin from SPAMUNCAUGTH directory
if [ $LOGDEBUG = 0 ] ;then echo ===== Checking $i/.$SPAMUNCAUGTH ========================== ; fi
if test -d $i/.$SPAMUNCAUGTH/new; then nice -n 19 sa-learn $LOGSALEARN --spam --dir $i/.$SPAMUNCAUGTH/new; fi
if test -d $i/.$SPAMUNCAUGTH/cur; then nice -n 19 sa-learn $LOGSALEARN --spam --dir $i/.$SPAMUNCAUGTH/cur; fi
##### Clean SPAMUNCAUGTH directory
if [ $CLEANSPAMUNCAUGTHMESSAGES = 0 ]
then rm $i/.$SPAMUNCAUGTH/new/*;rm $i/.$SPAMUNCAUGTH/cur/*
fi
done

Si el LOGDEBUG esta activado, el script devolvera algo asi:

===== Checking /home/bluehostlogin/mail/elsotanillo.net/user1/.SpamHam ==========================
===== Checking /home/bluehostlogin/mail/elsotanillo.net/user1/.SpamNoCogido ==========================
===== Checking /home/bluehostlogin/mail/elsotanillo.net/user2/.SpamHam ==========================
Learned tokens from 0 message(s) (0 message(s) examined)
Learned tokens from 0 message(s) (0 message(s) examined)
===== Checking /home/bluehostlogin/mail/elsotanillo.net/user2/.SpamNoCogido ==========================
Learned tokens from 0 message(s) (0 message(s) examined)
Learned tokens from 3 message(s) (3 message(s) examined)
===== Checking /home/bluehostlogin/mail/elsotanillo.net/user3/.SpamHam ==========================
===== Checking /home/bluehostlogin/mail/elsotanillo.net/user3/.SpamNoCogido ==========================
===== Checking /home/bluehostlogin/mail/elsotanillo.net/user4/.SpamHam ==========================
===== Checking /home/bluehostlogin/mail/elsotanillo.net/user4/.SpamNoCogido ==========================
===== Checking /home/bluehostlogin/mail/the10thfloor.net/user1/.SpamHam ==========================
===== Checking /home/bluehostlogin/mail/the10thfloor.net/user1/.SpamNoCogido ==========================

Una vez que este todo funcionando ya puedes desactivar el modo DEBUG.

Recuerda el tipo de licencia! 🙂

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.