Page 1 of 1

My SpamAssassin Rule Hits report is messed up

Posted: 20 Jun 2017 10:54
by ovizii
going to EFA web interface => Search and reports => SpamAssassin Rule Hits all I see are rules which hit SPAM, not a single rule seems to have hit any HAM?
Going back to Search & Reports I double checked that I do not have any active filters set. This EFA has been updated step by step from 3.0.1.5 to the current release.

Any ideas?
2017-06-20 12_49_59-MailWatch for Mailscanner - Reports.png
2017-06-20 12_49_59-MailWatch for Mailscanner - Reports.png (36.63 KiB) Viewed 5910 times
2017-06-20 12_51_06-MailWatch Filter Report_ SpamAssassin Rule Hits.png
2017-06-20 12_51_06-MailWatch Filter Report_ SpamAssassin Rule Hits.png (77.88 KiB) Viewed 5910 times

Re: My SpamAssassin Rule Hits report is messed up

Posted: 21 Jun 2017 05:07
by pdwalker
Oh, me too. I guess I haven't run that report in a while.

Re: My SpamAssassin Rule Hits report is messed up

Posted: 21 Jun 2017 05:59
by pdwalker
It's due to a couple of problems in rep_sa_rule_hits.php.

The logic is, look for the string "spam" or "not-spam" and count them up. However, there is no "not-spam" string in the spam report pulled from the spam report in the database.

There is a "not spam" string, but that string is thrown away in the beginning of processing, so the counts cannot be made.

The logic for the spam report string processing needs to be rethought.

/edit/

no, that's not quite right, but the problem is definitely in this file. still debugging.

Re: My SpamAssassin Rule Hits report is messed up

Posted: 21 Jun 2017 06:11
by ovizii
thanks for checking, must have broken a few updates ago.
I often run that report to check stats and find out which rules I need to tweak ;-)

Re: My SpamAssassin Rule Hits report is messed up

Posted: 21 Jun 2017 06:35
by pdwalker
Ugh,

While the spam report handing is not perfect (autolearn=spam, required, autolearn=not showing up in the report when they should be stripped out), the fix is actually much simpler. Change:

Code: Select all

if ($row->isspam !== 0) {
to

Code: Select all

if ($row->isspam != 0) {
Search for it and it'll be the first line you find.

Re: My SpamAssassin Rule Hits report is messed up

Posted: 21 Jun 2017 07:43
by pdwalker
And just because those "funny" entries appear in the report have annoyed me enough, here is how to get rid of them:

Change

Code: Select all

      $junk = array_shift($sa_rules); // score=
      $junk = array_shift($sa_rules); // required
to

Code: Select all

      $junk = array_shift($sa_rules); // cached/not cached
      $junk = array_shift($sa_rules); // score=
      $junk = array_shift($sa_rules); // required
      if( stripos($sa_rules[0],"autolearn=") !== false ) {
          $junk = array_shift($sa_rules); // autolearn=spam or not spam, if present
      }
I've not tested it extensively and I might have missed a few cases, but it seems to work.

Re: My SpamAssassin Rule Hits report is messed up

Posted: 21 Jun 2017 08:11
by pdwalker
You know what would be nice? Sortable table columns for the reports to make it easier to focus on what you are interested in.

Well, you can!

First, go here and read up on the documentation.

Then download the javascript library from here and save it to the mailscanner html directory (var/www/html/mailscanner/)

For this report, the only changes needed are:
from this:

Code: Select all

echo '<TABLE BORDER="0" CELLPADDING="10" CELLSPACING="0" WIDTH="100%">';
to this:

Code: Select all

echo '<script src="sorttable.js"></script>';
echo '<style> table.sortable th:not(.sorttable_sorted):not(.sorttable_sorted_reverse):not(.sorttable_nosort):after { content: " \25B4\25BE" }</style>';
echo '<TABLE BORDER="0" CELLPADDING="10" CELLSPACING="0" WIDTH="100%">';
and this:

Code: Select all

echo '<TABLE CLASS="boxtable" ALIGN="CENTER" BORDER="0">' . "\n";
to this:

Code: Select all

echo '<TABLE CLASS="boxtable sortable" ALIGN="CENTER" BORDER="0">' . "\n";
You may also wish to enable "stable sorting" by editing the sorttable.js script. See the topmost link for the documentation on "Stable sorting"

Changing the reports this way is a quick kludge. If you actually wanted to do it properly, the sorttable.js should be given a proper home and included in the templates for the reports.

Re: My SpamAssassin Rule Hits report is messed up

Posted: 21 Jun 2017 08:46
by shawniverson