Having trouble with sa-learn

You know that sa-learn is set to a minimal email about 100? dont know for sure but there is a minimal spam messages that it needs to learn before blocking them.
 
Hello,

To find out reasons you should learn RFC headers of an email and read exim/sa logs. There is no way to guess an answer. Recently I had an issue when exim could not connect to SA and therefore it accepted all the incoming emails without filtering. You might or not have the same issue...
 
Not sure what I am doing wrong as I set up sa-learn according to this, http://help.directadmin.com/item.php?id=358

Afterwards if client send a spam email from a spammer to the teach-isspam like they are supposed to but they are still getting bombarded with spam from the same spammers.

Any idea what I am doing wrong?

As written, that script worked fine from the command line for me, but it did not run effectively from cron. I traced the problem down to there is no path or search path to sa-learn, so it never ran when it was croned. I modified the script to fix that problem and made several other modifications as well. The script can now be located centrally and called from anywhere, no parameters need to be edited in the script, and you can specify to delete the messages from the teach directories by simply passing 1 as a parameter. It also writes a log of the last run in the user's .spamassassin directory named sa-learn.log. Unless someone can find something wrong with this script, I would think DA would want to use it to replace the one in the help. This is the adjusted script
Code:
#!/bin/sh

#***** Initialize Variables *****
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/$USER/bin
# Passing a 1 deletes the messages in teach-isspam and teach-isnotspam after teaching completes
DELETE_TEACH_DATA="$1"

# Set home path
DA_HOME=/home/${USER}

# Set working directory
cd $DA_HOME/.spamassassin

# Send output to log file
exec > sa-learn.log                                                                      
exec 2>&1

#***** Main *****
learn_Maildir()
{
            FILESPAM=${1}/.INBOX.teach-isspam
            FILEHAM=${1}/.INBOX.teach-isnotspam

            if [ -e ${FILESPAM}/new ] || [ -e ${FILESPAM}/cur ]; then
                        echo "learning spam via ${FILESPAM}...";
                        sa-learn --no-sync --spam  ${FILESPAM}/{cur,new}
            fi

            if [ -e ${FILEHAM}/new ] || [ -e ${FILEHAM}/cur ]; then
                        echo "";
                        echo "learning ham via $FILEHAM...";
                        sa-learn --no-sync --ham ${FILEHAM}/{cur,new}
            fi

			# Delete teach messages if requested
     		if [ "$DELETE_TEACH_DATA" -eq 1 ]; then
     		    rm -f ${FILESPAM}/new/* ${FILESPAM}/cur/*
     		    rm -f ${FILEHAM}/new/* ${FILEHAM}/cur/*
     		fi
}

# Learn from user mailbox
if [ -e $DA_HOME/Maildir ]; then
     learn_Maildir $DA_HOME/Maildir
fi

# Learn from virtual user mailboxes
for d in `ls $DA_HOME/imap`; do
{
            DOMAIN_DIR=${DA_HOME}/imap/${d}
            if [ -h $DOMAIN_DIR ]; then
                        continue;
            fi

            for maildir in `ls -d ${DOMAIN_DIR}/*/Maildir 2>/dev/null`; do
            {
                learn_Maildir ${maildir}
            };
            done;
};
done;

# Commit learning to database
echo "";
echo "syncing...";
sa-learn --sync

# Show stats after commit
echo "";
echo "current status:"
sa-learn --dump magic

echo "Generated $(date)"

#***** End Script *****

The following illustrates how to call it in cron, with the 1 appended to trigger the clearing of the learn folders after sa-learn runs. Simply leave off the 1 if you don't want the messages in the learn folders to be deleted:
Code:
/home/<user name>/.spamassassin/teach.sh 1
 
Last edited:
Back
Top