Page 1 of 1

Script to see what your users are training for spam and ham

Posted: Sat Dec 08, 2018 12:30 am
by JDunphy
If you are curious to see how your spam rules are working with your users, this little bash script pulls their training emails.

Code: Select all

# su - zimbra
% zmcopyTrain
Pulling spamassassin data.
[] INFO: Total messages processed: 15
[] INFO: Total messages processed: 0
See /tmp/zmtrainsa.25864.spam.WA41r5 for spam
[zimbra@relay3 ~]$ ls /tmp/zmtrainsa.25864.spam.WA41r5
1678b15bf37-0  1678b15bf37-10  1678b15bf37-12  1678b15bf37-14  1678b15bf37-3  1678b15bf37-5  1678b15bf37-7  1678b15bf37-9
1678b15bf37-1  1678b15bf37-11  1678b15bf37-13  1678b15bf37-2   1678b15bf37-4  1678b15bf37-6  1678b15bf37-8
It will pull both the spam and ham emails provided there is email to be pulled. It is not destructive and only makes a copy so will not affect how zmtrainsa works.

It can be found here: https://github.com/JimDunphy/ZimbraScri ... mcopyTrain

Extra credit:

Code: Select all

# su - zimbra
% cd /tmp/zmtrainsa.25864.spam.WA41r5
% spamassassin -D < 1678b15bf37-0 > /dev/null 2> email.out
Look inside email.out to see why and what rules fired. Adjust your sauser.cf rules and scores and repeat running the email through until the system scores it as spam or ham.

Background Information:
If a user hits the junk button, that email is sent to a special spam user.
If you drag a message to the junk folder, it is sent to a special spam user.
If you move a message into a junk folder via a filter and action, it is sent to a special spam user.
Same is true for the ham case.
This script pulls those emails from both the ham and spam account so the admin can look at why the email wasn't properly classified.

Re: Script to see what your users are training for spam and ham

Posted: Sun Dec 09, 2018 6:32 pm
by JDunphy
My script is useless... In my rush to get the email saved before the nightly cleanup I used zmtrainsa as my starting point and pulled out code I didn't need. I just looked at zmspamextract to see how it worked and it does create the directories which completely eliminates the need for this script unless you read those files as another user since the default creation mode is 750 with zimbra:zimbra as the owner/group .... or do not want directories created if there is no email present in those accounts or need new random directories created to view over time... Really stretching now to find a use case. :-) It is much simpler to just do this should you have this need.

Code: Select all

# su - zimbra
% /opt/zimbra/libexec/zmspamextract -s -o /tmp/some_spam_directory_not_created_or_created
% /opt/zimbra/libexec/zmspamextract -n -o /tmp/some_ham_directory_not_created_or_created
Not necessary to create the directory as zmspamextract has code to do that:
Ref: https://github.com/jimedler/Zimbra-1/bl ... tract.java

Code: Select all

        String optDirectory = cl.getOptionValue('o');
        File outputDirectory = new File(optDirectory);
        if (!outputDirectory.exists()) {
            LOG.info("Creating directory: " + optDirectory);
            outputDirectory.mkdirs();
            if (!outputDirectory.exists()) {
                LOG.error("could not create directory " + optDirectory);
                System.exit(2);
            }
        }
Note: -n option to zmspamextract is 'not spam' as -h is needed for help. You can also use the admin console to view these accounts and associated email being trained but need to do this before the nightly cleanup or the data is gone. I wanted a copy to save save some time in building, testing, and updating rules in SA debug mode. I run this nightly before the /opt/zimbra/bin/zmtrainsa --cleanup executes to get a general understanding how well the system is performing. I go back and delete the directories later.