You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by km...@apache.org on 2013/01/21 04:41:58 UTC
svn commit: r1436171 - in /spamassassin/trunk: lib/Mail/SpamAssassin/Conf.pm
lib/Mail/SpamAssassin/PerMsgStatus.pm
lib/Mail/SpamAssassin/Plugin/AutoLearnThreshold.pm t/autolearn_force.t
t/autolearn_force_fail.t
Author: kmcgrail
Date: Mon Jan 21 03:41:58 2013
New Revision: 1436171
URL: http://svn.apache.org/viewvc?rev=1436171&view=rev
Log:
feature request for tflag autolearn_force to make the requirements less stringent - bug 5503
Added:
spamassassin/trunk/t/autolearn_force.t (with props)
spamassassin/trunk/t/autolearn_force_fail.t (with props)
Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm
spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/AutoLearnThreshold.pm
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm?rev=1436171&r1=1436170&r2=1436171&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm Mon Jan 21 03:41:58 2013
@@ -3050,7 +3050,7 @@ B<Mail::SpamAssassin::Plugin::Reuse>.
}
});
-=item tflags SYMBOLIC_TEST_NAME [ {net|nice|learn|userconf|noautolearn|multiple|maxhits=N|ips_only|domains_only|a|ns} ]
+=item tflags SYMBOLIC_TEST_NAME [ {net|nice|learn|userconf|noautolearn|autolearn_force|multiple|maxhits=N|ips_only|domains_only|a|ns} ]
Used to set flags on a test. Parameter is a space-separated list of flag names.
These flags are used in the score-determination back end system for details
@@ -3083,6 +3083,10 @@ The test requires training before it can
The test will explicitly be ignored when calculating the score for
learning systems.
+=item autolearn_force
+
+The test will be subject to less stringent autolearn thresholds.
+
=item multiple
The test will be evaluated multiple times, for use with meta rules.
@@ -4391,7 +4395,8 @@ sub maybe_header_only {
return 1;
} elsif ($type == $TYPE_META_TESTS) {
- my $tflags = $self->{tflags}->{$rulename}; $tflags ||= '';
+ my $tflags = $self->{tflags}->{$rulename};
+ $tflags ||= '';
if ($tflags =~ m/\bnet\b/i) {
return 0;
} else {
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm?rev=1436171&r1=1436170&r2=1436171&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm Mon Jan 21 03:41:58 2013
@@ -386,6 +386,19 @@ sub get_body_only_points {
return $self->{body_only_points};
}
+=item $score = $status->get_autolearn_force_status()
+
+Return whether a message's score included any rules that flagged as
+autolearn_force.
+
+=cut
+
+sub get_autolearn_force_status {
+ my ($self) = @_;
+ $self->_get_autolearn_points();
+ return $self->{autolearn_force};
+}
+
sub _get_autolearn_points {
my ($self) = @_;
@@ -416,6 +429,7 @@ sub _get_autolearn_points {
$self->{learned_points} = 0;
$self->{body_only_points} = 0;
$self->{head_only_points} = 0;
+ $self->{autolearn_force} = 0;
foreach my $test (@{$self->{test_names_hit}}) {
# According to the documentation, noautolearn, userconf, and learn
@@ -431,16 +445,21 @@ sub _get_autolearn_points {
$self->{learned_points} += $self->{conf}->{scoreset}->[$orig_scoreset]->{$test};
next;
}
+
+ #IF ANY RULES ARE AUTOLEARN FORCE, SET THAT FLAG
+ if ($tflags->{$test} =~ /\bautolearn_force\b/) {
+ $self->{autolearn_force}++;
+ }
}
# ignore tests with 0 score (or undefined) in this scoreset
next if !$scores->{$test};
- # Go ahead and add points to the proper locations
+ # Go ahead and add points to the proper locations - Changed to elsif because in testing,
+ # I was getting both head and body.
if (!$self->{conf}->maybe_header_only ($test)) {
$self->{body_only_points} += $scores->{$test};
- }
- if (!$self->{conf}->maybe_body_only ($test)) {
+ } elsif (!$self->{conf}->maybe_body_only ($test)) {
$self->{head_only_points} += $scores->{$test};
}
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/AutoLearnThreshold.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/AutoLearnThreshold.pm?rev=1436171&r1=1436170&r2=1436171&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/AutoLearnThreshold.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/AutoLearnThreshold.pm Mon Jan 21 03:41:58 2013
@@ -106,6 +106,12 @@ Note: SpamAssassin requires at least 3 p
points from the body to auto-learn as spam. Therefore, the minimum
working value for this option is 6.
+If the test option autolearn_force is set, the minimum value will
+remain at 6 points but there is no requirement that the points come
+from body and header rules. This option is useful for autolearning
+with rules that are considered to be extremely safe indicators of
+the spaminess of a message.
+
=cut
push (@cmds, {
@@ -157,6 +163,9 @@ sub autolearn_discriminator {
my $head_only_points = $scan->get_head_only_points();
my $learned_points = $scan->get_learned_points();
+ # find out if any of the tests added an autolearn_force status
+ my $force_autolearn = $scan->get_autolearn_force_status();
+
dbg("learn: auto-learn? ham=$min, spam=$max, ".
"body-points=".$body_only_points.", ".
"head-points=".$head_only_points.", ".
@@ -179,6 +188,15 @@ sub autolearn_discriminator {
my $required_body_points = 3;
my $required_head_points = 3;
+ #Set a lower threshold of "just has to be spam" if autolearn_force was set on a rule
+ if ($force_autolearn) {
+ $required_body_points = 0;
+ $required_head_points = 0;
+ dbg("learn: auto-learn: autolearn_force flagged for a rule. Removing seperate body and head point threshold. Body Only Points: $body_only_points ($required_body_points req'd) / Head Only Points: $head_only_points ($required_head_points req'd)");
+ } else {
+ dbg("learn: auto-learn: autolearn_force not flagged for a rule. Body Only Points: $body_only_points ($required_body_points req'd) / Head Only Points: $head_only_points ($required_head_points req'd)");
+ }
+
if ($body_only_points < $required_body_points) {
dbg("learn: auto-learn? no: scored as spam but too few body points (".
$body_only_points." < ".$required_body_points.")");
Added: spamassassin/trunk/t/autolearn_force.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/autolearn_force.t?rev=1436171&view=auto
==============================================================================
--- spamassassin/trunk/t/autolearn_force.t (added)
+++ spamassassin/trunk/t/autolearn_force.t Mon Jan 21 03:41:58 2013
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+
+use lib '.'; use lib 't';
+use SATest; sa_t_init("autolearn_force");
+use Test; BEGIN { plan tests => 2 };
+
+# ---------------------------------------------------------------------------
+
+%patterns = (
+
+q{ autolearn=spam } => 'autolearned as spam'
+
+);
+
+%anti_patterns = (
+);
+
+tstprefs ('
+
+body WEIGHT /EVOLUTION PREVIEW RELEASE/
+score WEIGHT 7.0
+tflags WEIGHT autolearn_force
+
+use_bayes 1
+bayes_auto_learn 1
+bayes_auto_learn_threshold_spam 6.0
+
+');
+
+ok (sarun ("-L -t < data/nice/001", \&patterns_run_cb));
+ok_all_patterns();
Propchange: spamassassin/trunk/t/autolearn_force.t
------------------------------------------------------------------------------
svn:executable = *
Added: spamassassin/trunk/t/autolearn_force_fail.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/autolearn_force_fail.t?rev=1436171&view=auto
==============================================================================
--- spamassassin/trunk/t/autolearn_force_fail.t (added)
+++ spamassassin/trunk/t/autolearn_force_fail.t Mon Jan 21 03:41:58 2013
@@ -0,0 +1,29 @@
+#!/usr/bin/perl
+
+use lib '.'; use lib 't';
+use SATest; sa_t_init("autolearn_force_fail");
+use Test; BEGIN { plan tests => 3 };
+
+# ---------------------------------------------------------------------------
+
+%patterns = (
+q{ autolearn=no } => 'autolearn no',
+);
+
+%anti_patterns = (
+q{ autolearn=spam } => 'autolearned as spam',
+);
+
+tstprefs ('
+
+header WEIGHT From =~ /@/
+score WEIGHT 13.0
+
+use_bayes 1
+bayes_auto_learn 1
+bayes_auto_learn_threshold_spam 12.0
+
+');
+
+ok (sarun ("-L -t < data/nice/001", \&patterns_run_cb));
+ok_all_patterns();
Propchange: spamassassin/trunk/t/autolearn_force_fail.t
------------------------------------------------------------------------------
svn:executable = *