patch-src::MandatoryLearn-3.4.0.patch by Victor Ustugov diff -urN lib.orig/Mail/SpamAssassin/PerMsgStatus.pm lib/Mail/SpamAssassin/PerMsgStatus.pm --- lib.orig/Mail/SpamAssassin/PerMsgStatus.pm 2014-02-07 10:36:28.000000000 +0200 +++ lib/Mail/SpamAssassin/PerMsgStatus.pm 2015-05-13 20:30:27.000000000 +0300 @@ -615,6 +615,52 @@ return $names; } +sub get_disable_learn_names { + my ($self) = @_; + my ($names); + + $self->_get_autolearn_points(); + $names = $self->{disable_learn_names}; + + if (defined $names) { + #remove trailing comma + $names =~ s/,$//; + } else { + $names = ""; + } + + return $names; +} + +sub get_mandatory_learn_names { + my ($self) = @_; + my ($names); + + $self->_get_autolearn_points(); + $names = $self->{mandatory_learn_names}; + + if (defined $names) { + #remove trailing comma + $names =~ s/,$//; + } else { + $names = ""; + } + + return $names; +} + +sub get_mandatory_learn { + my ($self) = @_; + $self->_get_autolearn_points(); + return $self->{mandatory_learn}; +} + +sub get_disable_learn { + my ($self) = @_; + $self->_get_autolearn_points(); + return $self->{disable_learn}; +} + sub _get_autolearn_points { my ($self) = @_; @@ -646,6 +692,8 @@ $self->{body_only_points} = 0; $self->{head_only_points} = 0; $self->{autolearn_force} = 0; + $self->{mandatory_learn} = 0; + $self->{disable_learn} = 0; foreach my $test (@{$self->{test_names_hit}}) { # According to the documentation, noautolearn, userconf, and learn @@ -654,6 +702,15 @@ next if $tflags->{$test} =~ /\bnoautolearn\b/; next if $tflags->{$test} =~ /\buserconf\b/; + if ($tflags->{$test} =~ /\bmandatory_learn\b/) { + $self->{mandatory_learn}++ ; + $self->{mandatory_learn_names}.="$test,"; + } + if ($tflags->{$test} =~ /\bdisable_learn\b/) { + $self->{disable_learn}++; + $self->{disable_learn_names}.="$test,"; + } + # Keep track of the learn points for an additional autolearn check. # Use the original scoreset since it'll be 0 in sets 0 and 1. if ($tflags->{$test} =~ /\blearn\b/) { diff -urN lib.orig/Mail/SpamAssassin/Plugin/AutoLearnThreshold.pm lib/Mail/SpamAssassin/Plugin/AutoLearnThreshold.pm --- lib.orig/Mail/SpamAssassin/Plugin/AutoLearnThreshold.pm 2014-02-07 10:36:27.000000000 +0200 +++ lib/Mail/SpamAssassin/Plugin/AutoLearnThreshold.pm 2015-05-13 20:31:21.000000000 +0300 @@ -163,6 +163,22 @@ my $head_only_points = $scan->get_head_only_points(); my $learned_points = $scan->get_learned_points(); + my $disable_learn = $scan->get_disable_learn(); + my $disable_learn_names = $scan->get_disable_learn_names(); + if ($disable_learn) { + dbg("learn: auto-learn? no, disable_learn"); + dbg("learn: auto-learn: disable_learn flagged because of rule(s): $disable_learn_names"); + return; + } + + my $mandatory_learn = $scan->get_mandatory_learn(); + my $mandatory_learn_names = $scan->get_mandatory_learn_names(); + if ($mandatory_learn) { + dbg("learn: auto-learn? yes, mandatory_learn"); + dbg("learn: auto-learn: mandatory_learn flagged because of rule(s): $mandatory_learn_names"); + return [1, $mandatory_learn, $mandatory_learn_names]; + } + # find out if any of the tests added an autolearn_force status my $force_autolearn = $scan->get_autolearn_force_status(); my $force_autolearn_names = $scan->get_autolearn_force_names();