You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@spamassassin.apache.org by bu...@spamassassin.apache.org on 2023/02/07 09:37:58 UTC

[Bug 8116] New: Perl-Module: Rules fired using $status->got_hit () are not listed in get_report() with 4.0.0

https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8116

            Bug ID: 8116
           Summary: Perl-Module: Rules fired using $status->got_hit () are
                    not listed in get_report() with 4.0.0
           Product: Spamassassin
           Version: 4.0.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: spamassassin
          Assignee: dev@spamassassin.apache.org
          Reporter: erhard@wor.net
  Target Milestone: Undefined

While testing the new 4.0.0 Release, we found the following mis-behaviour when
using SA via the Perl module.

We have some special-rules that are fired externally using the Perl interface
of SA. However with 4.0.0 the checks which have been fired using got_hit() are
not showing up in the report output produced by get_report(). Besides that the
checks are correctly listed in $status->get_names_of_tests_hit_with_scores().
So it seems as SA is half-aware of those got_hit() fired checks somehow.

Additionally we found the score displayed in the report output was sometimes
variing. In some cases the score of the got_hit() rules were included in the
get_report() score sum, sometimes not. We don't see this behaviour with SA
3.4.x, but we haven't managed to built a clean reproduction code snippet yet.

Here is a short sample code to reproduce the got_hit() bug:

<--- CODE --->

require Mail::SpamAssassin;
my $spamtest = Mail::SpamAssassin->new();

open(my $message, '<', "test-mail.txt")
  or die "Could not open file '$filename' $!";

my $mail = $spamtest->parse($message);
my $status = $spamtest->check($mail);

$status->got_hit("MY_TEST_CHECK", "This is a test", score => 100);

print("\$status->get_report()\n");
print($status->get_report());

$status->finish();
$mail->finish();
$spamtest->finish();

<--- END-OF-CODE --->


Thanks in advance for looking into this!
Let me know if you have any questions or need more information.

Cheers,
Andreas

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 8116] 流浪地球2-电影-高清视频在线观看-未经审查720p

Posted by bu...@spamassassin.apache.org.
https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8116

whyxtcd <wh...@triots.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |whyxtcd@triots.com
           Keywords|                            |asf-project

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 8116] Perl-Module: Rules fired using $status->got_hit () are not listed in get_report() with 4.0.0

Posted by bu...@spamassassin.apache.org.
https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8116

--- Comment #2 from Henrik Krohns <ap...@hege.li> ---
Hasty code above, even though it worked, this should be the proper syntax..

my $mail = $spamtest->parse($message, 0,
  {
    rule_hits => [
      { rule => 'MY_TEST_CHECK', descr => "This is a test", score => 100 },
    ]
  }
);

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 8116] Perl-Module: Rules fired using $status->got_hit () are not listed in get_report() with 4.0.0

Posted by bu...@spamassassin.apache.org.
https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8116

--- Comment #4 from Henrik Krohns <ap...@hege.li> ---
(In reply to Andreas Erhard from comment #3)
> Thanks for showing a possible workaround.
> 
> I do understand your argumentation, but to me it sounds wrong, that you
> can't call got_hit() on PerMsgStatus after running $spamtest->check(). I
> thought, I have to run check(), in order to get the PerMsgStatus object?

The code is what it is. Does the documentation imply that you can do anything
you want with PerMsgStatus object when you have it?

> Additionally: could you please test my sample code on a 3.4 SA environment?
> I've just checked and the got_hit() after check() seems to be working there.

It makes no difference how your "incorrect" code behaves between 3.4 or 4.0.
The basic logic of PerMsgStatus->check() has been the same atleast since 3.3,
check() for all purposes finishes the scan and you should only read the
results. It makes no sense to start changing this logic. Even if 3.4 registers
the got_hit(), internal state will be left inconsistent.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 8116] Perl-Module: Rules fired using $status->got_hit () are not listed in get_report() with 4.0.0

Posted by bu...@spamassassin.apache.org.
https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8116

--- Comment #5 from Andreas Erhard <er...@wor.net> ---
Thank you for the detailed response.

Since this behaviour seems not to be intended, SpamAssassin should simply
ignore got_hit() calls once the check() method has been finished. Currently it
leads to some strange results and lots of confusion, if someone is using
got_hit() at a too late stage.

Additionally as you already pointed out it would be nice to have slightly more
information in the documentation about this situation.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 8116] Perl-Module: Rules fired using $status->got_hit () are not listed in get_report() with 4.0.0

Posted by bu...@spamassassin.apache.org.
https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8116

Henrik Krohns <ap...@hege.li> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |apache@hege.li

--- Comment #1 from Henrik Krohns <ap...@hege.li> ---

If you look at the code of PerMsgStatus->check(), it's pretty clear that you
are not supposed to call got_hit() anymore, as check() already calculated score
and spam status and called "check_end" to plugins. The code looks the same on
3.4 and 4.0.

Admittedly the documentation is bad in this regard.

To feed hits to the parser before message scan is started, you can use the
poorly documented suppl_attrib to parse(), this is the API that amavisd uses
too to register hits.

If you need to register hits during SA scan, then the correct option is simply
to create normal SA plugin for this purpose.

Leaving this bug open if someone wants to document that check() for all
purposes finishes the scan and got_hit() etc should not be called after that.

--------------

require Mail::SpamAssassin;
my $spamtest = Mail::SpamAssassin->new();

open(my $message, '<', "testmsg.small")
  or die "Could not open file '$filename' $!";

my $mail = $spamtest->parse($message,
  suppl_attrib => {
    rule_hits => [
      { rule => 'MY_TEST_CHECK', descr => "This is a test", score => 100 },
    ]
  }
);
my $status = $spamtest->check($mail);

print("\$status->get_report()\n");
print($status->get_report());

$status->finish();
$mail->finish();
$spamtest->finish();

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 8116] 流浪地球2-电影-高清视频在线观看-未经审查720p

Posted by bu...@spamassassin.apache.org.
https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8116

John Hardin <jh...@impsec.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|Translations and Languages  |BZSpam
             Status|NEW                         |RESOLVED
           Assignee|dev@spamassassin.apache.org |jhardin@impsec.org
         Resolution|---                         |INVALID

--- Comment #1 from John Hardin <jh...@impsec.org> ---
Deleting BZ spam

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 8116] Perl-Module: Rules fired using $status->got_hit () are not listed in get_report() with 4.0.0

Posted by bu...@spamassassin.apache.org.
https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8116

Andreas Erhard <er...@wor.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |erhard@wor.net

--- Comment #3 from Andreas Erhard <er...@wor.net> ---
Thanks for showing a possible workaround.

I do understand your argumentation, but to me it sounds wrong, that you can't
call got_hit() on PerMsgStatus after running $spamtest->check(). I thought, I
have to run check(), in order to get the PerMsgStatus object?

Additionally: could you please test my sample code on a 3.4 SA environment?
I've just checked and the got_hit() after check() seems to be working there.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 8116] Perl-Module: Rules fired using $status->got_hit () are not listed in get_report() with 4.0.0

Posted by bu...@spamassassin.apache.org.
https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8116

Giovanni Bechis <gi...@paclan.it> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
                 CC|                            |giovanni@paclan.it
             Status|NEW                         |RESOLVED

--- Comment #6 from Giovanni Bechis <gi...@paclan.it> ---
documentation updated in r1937151.

-- 
You are receiving this mail because:
You are the assignee for the bug.