You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@spamassassin.apache.org by Larry Nedry <sp...@bluestreak.net> on 2019/09/29 23:52:32 UTC
Creating a plugin with dynamic scoring
Hello,
I'm developing a plugin that adds a dynamic rule score to the SA
calculated score. It works well except when the SA calculated score is
less than the required_score and the final score is greater that the
required_score. In this case the X-Spam-Status header always shows "No,
score=4.9..." and the X-Spam-Report header doesn't get written. If the
_SCORE_ is displayed in the subject, it shows the correct score.
Here's the trimmed version of the relevant code:
sub check_end() {
my ( $self, $params ) = @_;
my $pms = $params->{permsgstatus};
my $sa_score = $pms->get_score();
$foo_score = sprintf("%0.3f", $sa_score * 0.10);
my $required_score = $pms->get_required_score();
if($sa_score > ($required_score - $foo_score)) {
$pms->got_hit('FOO', '', score => $foo_score);
}
return 0;
}
Is there a better way to update the SA score?
Regards,
Larry
Re: Creating a plugin with dynamic scoring
Posted by Henrik K <he...@hege.li>.
At check_end the check already ended, it's not really possible to make
changes (yes the documentation on these is bad, one really needs to look at
the code).
Do a normal eval rule like RW suggested, something like priority 999 or 1001
depending if you want before or after AWL/TxRep..
On Sun, Sep 29, 2019 at 07:52:32PM -0400, Larry Nedry wrote:
> Hello,
>
> I'm developing a plugin that adds a dynamic rule score to the SA calculated
> score. It works well except when the SA calculated score is less than the
> required_score and the final score is greater that the required_score. In
> this case the X-Spam-Status header always shows "No, score=4.9..." and the
> X-Spam-Report header doesn't get written. If the _SCORE_ is displayed in the
> subject, it shows the correct score.
>
> Here's the trimmed version of the relevant code:
>
> sub check_end() {
> my ( $self, $params ) = @_;
> my $pms = $params->{permsgstatus};
>
> my $sa_score = $pms->get_score();
> $foo_score = sprintf("%0.3f", $sa_score * 0.10);
>
> my $required_score = $pms->get_required_score();
> if($sa_score > ($required_score - $foo_score)) {
> $pms->got_hit('FOO', '', score => $foo_score);
> }
>
> return 0;
> }
>
> Is there a better way to update the SA score?
>
> Regards,
> Larry
Re: Creating a plugin with dynamic scoring
Posted by RW <rw...@googlemail.com>.
On Sun, 29 Sep 2019 19:52:32 -0400
Larry Nedry wrote:
> Hello,
>
> I'm developing a plugin that adds a dynamic rule score to the SA
> calculated score. It works well except when the SA calculated score
> is less than the required_score and the final score is greater that
> the required_score. In this case the X-Spam-Status header always
> shows "No, score=4.9..." and the X-Spam-Report header doesn't get
> written. If the _SCORE_ is displayed in the subject, it shows the
> correct score.
>
> Here's the trimmed version of the relevant code:
>
> sub check_end() {
> my ( $self, $params ) = @_;
> my $pms = $params->{permsgstatus};
>
> my $sa_score = $pms->get_score();
> $foo_score = sprintf("%0.3f", $sa_score * 0.10);
>
> my $required_score = $pms->get_required_score();
> if($sa_score > ($required_score - $foo_score)) {
> $pms->got_hit('FOO', '', score => $foo_score);
> }
>
> return 0;
> }
>
> Is there a better way to update the SA score?
Take a look at AWL/TxRep, these use a rule priority to run late in
the scan. Doing it that way would give the option for your plugin to
run before or after AWL/TxREP's score averaging just by changing its
priority.