You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2006/11/24 19:57:57 UTC

svn commit: r478942 - in /spamassassin/branches/jm_re2c_hacks: ./ lib/Mail/SpamAssassin/Plugin/ rules/

Author: jm
Date: Fri Nov 24 10:57:56 2006
New Revision: 478942

URL: http://svn.apache.org/viewvc?view=rev&rev=478942
Log:
hooray, changes to trunk files are now down to a single call_plugin invocation.  This will need reworking once the rule-type-plugin (bug 4778) code is done, eventually, though

Added:
    spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/OneLineBodyRuleType.pm
Modified:
    spamassassin/branches/jm_re2c_hacks/MANIFEST
    spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/Check.pm
    spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/P595Body.pm
    spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/RabinKarpBody.pm
    spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/Rule2XSBody.pm
    spamassassin/branches/jm_re2c_hacks/rules/v320.pre

Modified: spamassassin/branches/jm_re2c_hacks/MANIFEST
URL: http://svn.apache.org/viewvc/spamassassin/branches/jm_re2c_hacks/MANIFEST?view=diff&rev=478942&r1=478941&r2=478942
==============================================================================
--- spamassassin/branches/jm_re2c_hacks/MANIFEST (original)
+++ spamassassin/branches/jm_re2c_hacks/MANIFEST Fri Nov 24 10:57:56 2006
@@ -458,8 +458,10 @@
 t/shortcircuit.t
 t/spamc_y.t
 lib/Mail/SpamAssassin/Plugin/BodyRuleBaseExtractor.pm
+lib/Mail/SpamAssassin/Plugin/OneLineBodyRuleType.pm
 lib/Mail/SpamAssassin/Plugin/RabinKarpBody.pm
 lib/Mail/SpamAssassin/Plugin/Rule2XSBody.pm
+lib/Mail/SpamAssassin/Plugin/P595Body.pm
 t/spamd_kill_restart.t
 t/spamd_kill_restart_rr.t
 t/re_base_extraction.t

Modified: spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/Check.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/Check.pm?view=diff&rev=478942&r1=478941&r2=478942
==============================================================================
--- spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/Check.pm (original)
+++ spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/Check.pm Fri Nov 24 10:57:56 2006
@@ -91,6 +91,10 @@
       $pms->{resolver}->finish_socket() if $pms->{resolver};
     }
 
+    # allow other, plugin-defined rule types to be called here
+    $self->{main}->call_plugins ("check_rules_at_priority", 
+        { permsgstatus => $pms, priority => $priority, checkobj => $self });
+
     # do head tests
     $self->do_head_tests($pms, $priority);
     $self->do_head_eval_tests($pms, $priority);
@@ -548,9 +552,6 @@
   {
     my ($self, $pms, $conf, $rulename, $pat, %opts) = @_;
     my $sub;
-    my $sub_one_line;
-
-    my $need_one_line = ($pms->{conf}->{generate_body_one_line_sub}->{$rulename});
 
     if (($conf->{tflags}->{$rulename}||'') =~ /\bmultiple\b/)
     {
@@ -568,19 +569,6 @@
       }
       ';
 
-      if ($need_one_line) {
-        $sub_one_line = '
-        pos $_[1] = 0;
-        '.$self->hash_line_for_rule($pms, $rulename).'
-        while ($_[1] =~ '.$pat.'g) {
-          my $self = $_[0];
-          $self->got_hit(q{'.$rulename.'}, "BODY: ", ruletype => "body");
-          '. $self->hit_rule_plugin_code($pms, $rulename, "body",
-                                        "return 1") . '
-        }
-        ';
-      }
-
     }
     else {
       # omitting the "pos" call, "body_loopid" label, use of while()
@@ -595,17 +583,6 @@
       }
       ';
 
-      if ($need_one_line) {
-        $sub_one_line = '
-        '.$self->hash_line_for_rule($pms, $rulename).'
-        if ($_[1] =~ '.$pat.') {
-          my $self = $_[0];
-          $self->got_hit(q{'.$rulename.'}, "BODY: ", ruletype => "body");
-          '. $self->hit_rule_plugin_code($pms, $rulename, "body", "return 1") . '
-        }
-        ';
-      }
-
     }
 
     if ($self->{main}->{use_rule_subs}) {
@@ -632,23 +609,6 @@
       $self->add_temporary_method ($rulename.'_body_test',
         '{ my $self = shift; '.$sub.' }');
     }
-
-    if ($need_one_line) {
-      $self->add_temporary_method ($rulename.'_one_line_body_test',
-        '{ my $self = shift; '.$sub_one_line.' }');
-    }
-  }
-    pre_loop_body => sub
-  {
-    my ($self, $pms, $conf, %opts) = @_;
-    $self->add_evalstr ('
- 
-      $self->{main}->call_plugins("run_body_hack", {
-              permsgstatus => $self, ruletype => "body",
-              priority => '.$opts{priority}.', lines => \@_
-            });
-
-    ');
   });
 }
 

Added: spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/OneLineBodyRuleType.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/OneLineBodyRuleType.pm?view=auto&rev=478942
==============================================================================
--- spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/OneLineBodyRuleType.pm (added)
+++ spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/OneLineBodyRuleType.pm Fri Nov 24 10:57:56 2006
@@ -0,0 +1,140 @@
+=head1 NAME
+
+Mail::SpamAssassin::Plugin::OneLineBodyRuleType
+
+=cut
+
+package Mail::SpamAssassin::Plugin::OneLineBodyRuleType;
+
+use Mail::SpamAssassin::Plugin;
+use Mail::SpamAssassin::Logger;
+use Mail::SpamAssassin::Util;
+use Mail::SpamAssassin::Constants qw(:sa);
+
+use strict;
+use warnings;
+
+use vars qw(@ISA); @ISA = qw();
+
+# constructor
+sub new {
+  my $class = shift;
+  $class = ref($class) || $class;
+  my $self = {};
+  bless ($self, $class);
+  return $self;
+}
+
+###########################################################################
+
+sub check_rules_at_priority {
+  my ($self, $params) = @_;
+  my $pms = $params->{permsgstatus};
+  my $checkobj = $params->{checkobj};
+  my $priority = $params->{priority};
+  Mail::SpamAssassin::Plugin::Check::do_one_line_body_tests($checkobj,
+            $pms, $priority);
+}
+
+sub check_start {
+  my ($self, $params) = @_;
+  my $pms = $params->{permsgstatus};
+  my $conf = $pms->{conf};
+
+  # this method runs before the body ruleset is compiled, but after
+  # finish_tests().  perfect spot to remove rules from the body
+  # set and add to another set...
+
+  my $test_set = $conf->{body_tests};
+  foreach my $pri (keys %{$test_set})
+  {
+    my $nicepri = $pri; $nicepri =~ s/-/neg/g;
+    foreach my $rulename (keys %{$test_set->{$pri}})
+    {
+      if ($conf->{generate_body_one_line_sub}->{$rulename}) {
+        # add the rule to the one-liner set
+        $conf->{one_line_body_tests}->{$pri} ||= { };
+        $conf->{one_line_body_tests}->{$pri}->{$rulename} =
+                    $test_set->{$pri}->{$rulename};
+      }
+
+      if ($conf->{skip_body_rules}->{$rulename}) {
+        # remove from the body set
+        delete $test_set->{$pri}->{$rulename};
+      }
+    }
+  }
+}
+
+###########################################################################
+
+1;
+
+# inject this method into the Check plugin's namespace
+# TODO: we need a better way to define new ruletypes via plugin
+package Mail::SpamAssassin::Plugin::Check;
+
+sub do_one_line_body_tests {
+  my ($self, $pms, $priority) = @_;
+  my $loopid = 0;
+
+  # TODO: should have a consttype for plugin-defined "alien" rule types,
+  # probably something like TYPE_ALIEN_TESTS.  it's only used as a key
+  # for {user_rules_of_type}, so that should be fine
+
+  $self->run_generic_tests ($pms, $priority,
+    consttype => $Mail::SpamAssassin::Conf::TYPE_BODY_TESTS,
+    type => 'one_line_body',
+    testhash => $pms->{conf}->{one_line_body_tests},
+    args => [ ],
+    loop_body => sub
+  {
+    my ($self, $pms, $conf, $rulename, $pat, %opts) = @_;
+    my $sub;
+
+    if (($conf->{tflags}->{$rulename}||'') =~ /\bmultiple\b/)
+    {
+      $loopid++;                 # support multiple matches
+      $sub = '
+      pos $_[1] = 0;
+      '.$self->hash_line_for_rule($pms, $rulename).'
+      while ($_[1] =~ '.$pat.'g) {
+        my $self = $_[0];
+        $self->got_hit(q{'.$rulename.'}, "BODY: ", ruletype => "one_line_body");
+        '. $self->hit_rule_plugin_code($pms, $rulename, "one_line_body",
+                                      "return 1") . '
+      }
+      ';
+
+    } else {
+      $sub = '
+      '.$self->hash_line_for_rule($pms, $rulename).'
+      if ($_[1] =~ '.$pat.') {
+        my $self = $_[0];
+        $self->got_hit(q{'.$rulename.'}, "BODY: ", ruletype => "one_line_body");
+        '. $self->hit_rule_plugin_code($pms, $rulename, "one_line_body", "return 1") . '
+      }
+      ';
+
+    }
+
+    $self->add_temporary_method ($rulename.'_one_line_body_test', '{'.$sub.'}');
+  },
+    pre_loop_body => sub
+  {
+    my ($self, $pms, $conf, %opts) = @_;
+    $self->add_evalstr ('
+ 
+      my $bodytext = $self->get_decoded_body_text_array();
+      $self->{main}->call_plugins("run_body_fast_scan", {
+              permsgstatus => $self, ruletype => "body",
+              priority => '.$opts{priority}.', lines => $bodytext
+            });
+
+    ');
+  });
+}
+
+###########################################################################
+
+1;

Modified: spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/P595Body.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/P595Body.pm?view=diff&rev=478942&r1=478941&r2=478942
==============================================================================
--- spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/P595Body.pm (original)
+++ spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/P595Body.pm Fri Nov 24 10:57:56 2006
@@ -19,6 +19,7 @@
 use Mail::SpamAssassin::Plugin;
 use Mail::SpamAssassin::Logger;
 use Mail::SpamAssassin::Plugin::BodyRuleBaseExtractor;
+use Mail::SpamAssassin::Plugin::OneLineBodyRuleType;
 
 use strict;
 use warnings;
@@ -34,6 +35,8 @@
   my $self = $class->SUPER::new($mailsaobject);
   bless ($self, $class);
 
+  $self->{one_line_body} = Mail::SpamAssassin::Plugin::OneLineBodyRuleType->new();
+
   return $self;
 }
 
@@ -123,7 +126,20 @@
 
 ###########################################################################
 
-sub run_body_hack {
+# delegate these to the OneLineBodyRuleType object
+sub check_start {
+  my ($self, $params) = @_;
+  $self->{one_line_body}->check_start($params);
+}
+
+sub check_rules_at_priority {
+  my ($self, $params) = @_;
+  $self->{one_line_body}->check_rules_at_priority($params);
+}
+
+###########################################################################
+
+sub run_body_fast_scan {
   my ($self, $params) = @_;
 
   return unless ($params->{ruletype} eq 'body');
@@ -138,14 +154,14 @@
   my $trie_rules = $conf->{$ruletype}->{trie_rules};
   if (!$trie_re_sub || !$trie_rules)
   {
-    dbg("zoom: run_body_hack for $ruletype skipped, no rules");
+    dbg("zoom: run_body_fast_scan for $ruletype skipped, no rules");
     return;
   }
 
   my $do_dbg = (would_log('dbg', 'zoom') > 1);
   my $scoresptr = $conf->{scores};
 
-  dbg("zoom: run_body_hack for $ruletype start");
+  dbg("zoom: run_body_fast_scan for $ruletype start");
 
   {
     no strict "refs";
@@ -168,6 +184,9 @@
 
           # dbg("zoom: base found for $rulename: $line");
 
+          # TODO: ick, this shouldn't have to use this package name. A good
+          # solution would be for compiled rule methods to live in their own
+          # namespace anyway; Mail::SpamAssassin::CompiledRules or something
           my $fn = 'Mail::SpamAssassin::Plugin::Check::'.
                                   $rulename.'_one_line_body_test';
 
@@ -181,7 +200,7 @@
     use strict "refs";
   }
 
-  dbg("zoom: run_body_hack for $ruletype done");
+  dbg("zoom: run_body_fast_scan for $ruletype done");
 }
 
 sub finish {

Modified: spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/RabinKarpBody.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/RabinKarpBody.pm?view=diff&rev=478942&r1=478941&r2=478942
==============================================================================
--- spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/RabinKarpBody.pm (original)
+++ spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/RabinKarpBody.pm Fri Nov 24 10:57:56 2006
@@ -20,6 +20,7 @@
 use Mail::SpamAssassin::Logger;
 use RabinKarpAccel;
 use Mail::SpamAssassin::Plugin::BodyRuleBaseExtractor;
+use Mail::SpamAssassin::Plugin::OneLineBodyRuleType;
 
 use strict;
 use warnings;
@@ -34,7 +35,7 @@
   $class = ref($class) || $class;
   my $self = $class->SUPER::new($mailsaobject);
   bless ($self, $class);
-
+  $self->{one_line_body} = Mail::SpamAssassin::Plugin::OneLineBodyRuleType->new();
   return $self;
 }
 
@@ -97,7 +98,20 @@
 
 ###########################################################################
 
-sub run_body_hack {
+# delegate these to the OneLineBodyRuleType object
+sub check_start {
+  my ($self, $params) = @_;
+  $self->{one_line_body}->check_start($params);
+}
+
+sub check_rules_at_priority {
+  my ($self, $params) = @_;
+  $self->{one_line_body}->check_rules_at_priority($params);
+}
+
+###########################################################################
+
+sub run_body_fast_scan {
   my ($self, $params) = @_;
 
   return unless ($params->{ruletype} eq 'body');
@@ -111,14 +125,14 @@
   my $rkhashes = $conf->{$ruletype}->{rkhashes};
   if (!$rkhashes || (scalar keys %{$conf->{$ruletype}->{rkhashes}} <= 0))
   {
-    dbg("zoom: run_body_hack for $ruletype skipped, no rules");
+    dbg("zoom: run_body_fast_scan for $ruletype skipped, no rules");
     return;
   }
 
   my $do_dbg = (would_log('dbg', 'zoom') > 1);
   my $scoresptr = $conf->{scores};
 
-  dbg("zoom: run_body_hack for $ruletype start");
+  dbg("zoom: run_body_fast_scan for $ruletype start");
 
   {
     no strict "refs";
@@ -157,7 +171,7 @@
     use strict "refs";
   }
 
-  dbg("zoom: run_body_hack for $ruletype done");
+  dbg("zoom: run_body_fast_scan for $ruletype done");
 }
 
 ###########################################################################

Modified: spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/Rule2XSBody.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/Rule2XSBody.pm?view=diff&rev=478942&r1=478941&r2=478942
==============================================================================
--- spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/Rule2XSBody.pm (original)
+++ spamassassin/branches/jm_re2c_hacks/lib/Mail/SpamAssassin/Plugin/Rule2XSBody.pm Fri Nov 24 10:57:56 2006
@@ -36,6 +36,7 @@
 
 use Mail::SpamAssassin::Plugin;
 use Mail::SpamAssassin::Logger;
+use Mail::SpamAssassin::Plugin::OneLineBodyRuleType;
 
 use strict;
 use warnings;
@@ -50,7 +51,7 @@
   $class = ref($class) || $class;
   my $self = $class->SUPER::new($mailsaobject);
   bless ($self, $class);
-
+  $self->{one_line_body} = Mail::SpamAssassin::Plugin::OneLineBodyRuleType->new();
   return $self;
 }
 
@@ -136,7 +137,20 @@
 
 ###########################################################################
 
-sub run_body_hack {
+# delegate these to the OneLineBodyRuleType object
+sub check_start {
+  my ($self, $params) = @_;
+  $self->{one_line_body}->check_start($params);
+}
+
+sub check_rules_at_priority {
+  my ($self, $params) = @_;
+  $self->{one_line_body}->check_rules_at_priority($params);
+}
+
+###########################################################################
+
+sub run_body_fast_scan {
   my ($self, $params) = @_;
 
   return unless ($params->{ruletype} eq 'body');
@@ -147,7 +161,7 @@
   my $conf = $scanner->{conf};
   return unless $conf->{zoom_ruletypes_available}->{$ruletype};
 
-  dbg("zoom: run_body_hack for $ruletype start");
+  dbg("zoom: run_body_fast_scan for $ruletype start");
 
   my $do_dbg = (would_log('dbg', 'zoom') > 1);
 
@@ -193,7 +207,7 @@
     use strict "refs";
   }
 
-  dbg("zoom: run_body_hack for $ruletype done");
+  dbg("zoom: run_body_fast_scan for $ruletype done");
 }
 
 sub finish {

Modified: spamassassin/branches/jm_re2c_hacks/rules/v320.pre
URL: http://svn.apache.org/viewvc/spamassassin/branches/jm_re2c_hacks/rules/v320.pre?view=diff&rev=478942&r1=478941&r2=478942
==============================================================================
--- spamassassin/branches/jm_re2c_hacks/rules/v320.pre (original)
+++ spamassassin/branches/jm_re2c_hacks/rules/v320.pre Fri Nov 24 10:57:56 2006
@@ -46,3 +46,4 @@
 
 # P595Body - EXPERIMENTAL speedup plugin, using bleadperl RE optimizations
 loadplugin Mail::SpamAssassin::Plugin::P595Body
+