My SpamAssassin Rule Hits report is messed up

General eFa discussion
Post Reply
ovizii
Posts: 463
Joined: 11 May 2016 08:08

My SpamAssassin Rule Hits report is messed up

Post 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 5906 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 5906 times
User avatar
pdwalker
Posts: 1583
Joined: 18 Mar 2015 09:16

Re: My SpamAssassin Rule Hits report is messed up

Post by pdwalker »

Oh, me too. I guess I haven't run that report in a while.
User avatar
pdwalker
Posts: 1583
Joined: 18 Mar 2015 09:16

Re: My SpamAssassin Rule Hits report is messed up

Post 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.
Last edited by pdwalker on 21 Jun 2017 06:13, edited 1 time in total.
ovizii
Posts: 463
Joined: 11 May 2016 08:08

Re: My SpamAssassin Rule Hits report is messed up

Post 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 ;-)
User avatar
pdwalker
Posts: 1583
Joined: 18 Mar 2015 09:16

Re: My SpamAssassin Rule Hits report is messed up

Post 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.
User avatar
pdwalker
Posts: 1583
Joined: 18 Mar 2015 09:16

Re: My SpamAssassin Rule Hits report is messed up

Post 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.
Last edited by pdwalker on 21 Jun 2017 08:13, edited 1 time in total.
User avatar
pdwalker
Posts: 1583
Joined: 18 Mar 2015 09:16

Re: My SpamAssassin Rule Hits report is messed up

Post 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.
Post Reply