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 2004/02/27 05:42:49 UTC

svn commit: rev 6895 - in incubator/spamassassin/trunk: . lib/Mail/SpamAssassin lib/Mail/SpamAssassin/Plugin masses rules

Author: jm
Date: Thu Feb 26 20:42:47 2004
New Revision: 6895

Added:
   incubator/spamassassin/trunk/rules/25_uribl.cf
Modified:
   incubator/spamassassin/trunk/MANIFEST
   incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm
   incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Dns.pm
   incubator/spamassassin/trunk/lib/Mail/SpamAssassin/MsgMetadata.pm
   incubator/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
   incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Test.pm
   incubator/spamassassin/trunk/lib/Mail/SpamAssassin/PluginHandler.pm
   incubator/spamassassin/trunk/masses/mass-check
Log:
bug 1375: do DNSBL lookups on URLs, implemented as plugin Mail::SpamAssassin::Plugin::URIDNSBL

Modified: incubator/spamassassin/trunk/MANIFEST
==============================================================================
--- incubator/spamassassin/trunk/MANIFEST	(original)
+++ incubator/spamassassin/trunk/MANIFEST	Thu Feb 26 20:42:47 2004
@@ -308,3 +308,4 @@
 tools/test_extract
 tools/triplets.pl
 lib/Mail/SpamAssassin/Constants.pm
+rules/25_uribl.cf

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm	(original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm	Thu Feb 26 20:42:47 2004
@@ -1935,17 +1935,6 @@
     }
 
 ###########################################################################
-
-    if ($self->{main}->call_plugins ("parse_config", {
-		line => $_,
-		user_config => $scoresonly
-	    }))
-    {
-      # a plugin dealt with it successfully.
-      next;
-    }
-
-###########################################################################
     # SECURITY: no eval'd code should be loaded before this line.
     #
     if ($scoresonly && !$self->{allow_user_rules}) { goto failed_line; }
@@ -2756,6 +2745,22 @@
 ###########################################################################
 
 failed_line:
+
+    # last ditch: try to see if the plugins know what to do with it
+    if ($self->{main}->call_plugins ("parse_config", {
+		key => $key,
+		value => $value,
+		line => $_,
+		conf => $self,
+		user_config => $scoresonly
+	    }))
+    {
+      # a plugin dealt with it successfully.
+      next;
+    }
+
+###########################################################################
+
     my $msg = "Failed to parse line in SpamAssassin configuration, ".
                         "skipping: $_";
 

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Dns.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Dns.pm	(original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Dns.pm	Thu Feb 26 20:42:47 2004
@@ -250,6 +250,9 @@
 	push(@left, $query);
       }
     }
+
+    $self->{main}->call_plugins ("check_tick", { permsgstatus => $self });
+
     last unless @left;
     last if time >= $timeout;
     @waiting = @left;
@@ -283,6 +286,7 @@
     $self->{tag_data}->{RBL} .= "<$dnsuri>" .
 	" [" . join(", ", @{ $answers }) . "]\n";
   }
+
   chomp $self->{tag_data}->{RBL} if defined $self->{tag_data}->{RBL};
 }
 

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/MsgMetadata.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/MsgMetadata.pm	(original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/MsgMetadata.pm	Thu Feb 26 20:42:47 2004
@@ -49,6 +49,7 @@
 
 package Mail::SpamAssassin::MsgMetadata;
 use strict;
+use bytes;
 
 use Mail::SpamAssassin;
 use Mail::SpamAssassin::Received;

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm	(original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm	Thu Feb 26 20:42:47 2004
@@ -143,6 +143,8 @@
     # do head tests
     $self->do_head_tests();
 
+    $self->{main}->call_plugins ("check_tick", { permsgstatus => $self });
+
     # do body tests with decoded portions
     {
       my $decoded = $self->get_decoded_stripped_body_text_array();
@@ -156,6 +158,7 @@
       $self->do_body_eval_tests($decoded);
       undef $decoded;
     }
+    $self->{main}->call_plugins ("check_tick", { permsgstatus => $self });
 
     # do rawbody tests with raw text portions
     {
@@ -166,6 +169,7 @@
       $self->do_body_uri_tests($bodytext);
       undef $bodytext;
     }
+    $self->{main}->call_plugins ("check_tick", { permsgstatus => $self });
 
     # and do full tests: first with entire, full, undecoded message
     # use get_all_headers instead of 
@@ -184,6 +188,7 @@
 
     # finish the DNS results
     $self->rbl_finish();
+    $self->{main}->call_plugins ("check_post_dnsbl", { permsgstatus => $self });
 
     # Do meta rules second-to-last
     $self->do_meta_tests();
@@ -2020,6 +2025,19 @@
 # the clearing of the test state is now inlined as:
 #
 # $self->{test_log_msgs} = ();        # clear test state
+#
+# except for this public API for plugin use:
+
+=item $status->clear_test_state()
+
+Clear test state, including test log messages from C<$status->test_log()>.
+
+=cut
+
+sub clear_test_state {
+    my ($self) = @_;
+    $self->{test_log_msgs} = ();
+}
 
 sub _handle_hit {
     my ($self, $rule, $score, $area, $desc) = @_;

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Test.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Test.pm	(original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Test.pm	Thu Feb 26 20:42:47 2004
@@ -10,6 +10,9 @@
 package Mail::SpamAssassin::Plugin::Test;
 
 use Mail::SpamAssassin::Plugin;
+use strict;
+use bytes;
+
 use vars qw(@ISA);
 @ISA = qw(Mail::SpamAssassin::Plugin);
 

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/PluginHandler.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/PluginHandler.pm	(original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/PluginHandler.pm	Thu Feb 26 20:42:47 2004
@@ -69,6 +69,7 @@
   else {
     dbg ("plugin: loading $package from \@INC");
     $ret = eval qq{ require $package; };
+    $path = "(from \@INC)";
   }
 
   if (!$ret) {
@@ -103,13 +104,13 @@
   foreach my $plugin (@{$self->{plugins}}) {
     $plugin->{_inhibit_further_callbacks} = 0;
 
-    dbg ("plugin: calling $subname on $plugin");
     my $methodref = $plugin->can ($subname);
 
     if (defined $methodref) {
       eval {
 	$ret = &$methodref ($plugin, @_);
       };
+      if ($ret) { dbg ("plugin: ${plugin}->${subname} => $ret"); }
     }
 
     if ($plugin->{_inhibit_further_callbacks}) {

Modified: incubator/spamassassin/trunk/masses/mass-check
==============================================================================
--- incubator/spamassassin/trunk/masses/mass-check	(original)
+++ incubator/spamassassin/trunk/masses/mass-check	Thu Feb 26 20:42:47 2004
@@ -35,6 +35,7 @@
   log options
   -o            write all logs to stdout
   --loghits     log the text hit for patterns (useful for debugging)
+  --loguris	log the URIs found
   --hamlog=log  use <log> as ham log ('ham.log' is default)
   --spamlog=log use <log> as spam log ('spam.log' is default)
  
@@ -70,7 +71,7 @@
 	    $opt_debug $opt_format $opt_hamlog $opt_head $opt_loghits
 	    $opt_mid $opt_mh $opt_ms $opt_net $opt_nosort $opt_progress
 	    $opt_showdots $opt_spamlog $opt_tail $opt_rules $opt_restart
-	    $opt_after $opt_rewrite);
+	    $opt_loguris $opt_after $opt_rewrite);
 
 use FindBin;
 use lib "$FindBin::Bin/../lib";
@@ -91,7 +92,7 @@
 GetOptions("c=s", "f=s", "j=i", "n", "o", "all", "bayes", "debug",
 	   "hamlog=s", "head=i", "loghits", "mh", "mid", "ms", "net",
 	   "progress", "rewrite:s", "showdots", "spamlog=s", "tail=i",
-	   "rules=s", "restart=i", "after=s",
+	   "rules=s", "restart=i", "after=s", "loguris",
 	   "dir" => sub { $opt_format = "dir"; },
 	   "file" => sub { $opt_format = "file"; },
 	   "mbox" => sub { $opt_format = "mbox"; },
@@ -251,13 +252,23 @@
     $ma = $new_ma;
   }
 
-  my $status = $spamtest->check($ma);
+  # log-uris support
+  my $status;
+  my @uris;
+  if ($opt_loguris) {
+    my $pms = Mail::SpamAssassin::PerMsgStatus->new ($spamtest, $ma);
+    @uris = $pms->get_uri_list ();
+    $pms->finish();
+
+  } else {
+    $status = $spamtest->check($ma);
+  }
 
   my @extra;
   if (defined($time)) {
     push(@extra, "time=$time");
   }
-  if (defined $status->{bayes_score}) {
+  if ($status && defined $status->{bayes_score}) {
     push(@extra, "bayes=" . $status->{bayes_score});
   }
   if ($opt_mid) {
@@ -276,10 +287,22 @@
     push(@extra, "mid=$mid");
   }
 
-  my $yorn = $status->is_spam() ? 'Y' : '.';
-  my $score = $status->get_score();
-  my $tests = join(",", sort(grep(length,$status->get_names_of_tests_hit(),$status->get_names_of_subtests_hit())));
-  my $extra = join(",", @extra);
+  my $yorn;
+  my $score;
+  my $tests;
+  my $extra;
+
+  if ($opt_loguris) {
+    $yorn = '.';
+    $score = 0;
+    $tests = join (" ", sort @uris);
+    $extra = '';
+  } else {
+    $yorn = $status->is_spam() ? 'Y' : '.';
+    $score = $status->get_score();
+    $tests = join(",", sort(grep(length,$status->get_names_of_tests_hit(),$status->get_names_of_subtests_hit())));
+    $extra = join(",", @extra);
+  }
 
   if (defined $opt_rewrite) {
     open(REWRITE, "> " . ($opt_rewrite ? $opt_rewrite : "/tmp/out"));
@@ -310,7 +333,7 @@
     }
   }
 
-  $status->finish();
+  if (defined $status) { $status->finish(); }
   $ma->finish();
   undef $ma;		# clean 'em up
   undef $status;

Added: incubator/spamassassin/trunk/rules/25_uribl.cf
==============================================================================
--- (empty file)
+++ incubator/spamassassin/trunk/rules/25_uribl.cf	Thu Feb 26 20:42:47 2004
@@ -0,0 +1,23 @@
+
+loadplugin Mail::SpamAssassin::Plugin::URIDNSBL
+
+# note that this plugin defines a new config setting, 'uridnsbl',
+# which lists the zones to look up in advance.  The rules will
+# not hit unless each rule has a corresponding 'uridnsbl' line.
+
+# URI-DNSBL lookups can take a *maximum* of this many seconds past the
+# normal DNSBL lookups.
+uridnsbl_timeout	2
+
+uridnsbl	URIBL_SBLXBL	sbl-xbl.spamhaus.org.	TXT
+header		URIBL_SBLXBL	eval:check_uridnsbl('URIBL_SBLXBL')
+describe	URIBL_SBLXBL	Contains a URL listed in the SBL/XBL blocklist
+
+uridnsbl	URIBL_DSBL	list.dsbl.org.		TXT
+header		URIBL_DSBL	eval:check_uridnsbl('URIBL_DSBL')
+describe	URIBL_DSBL	Contains a URL listed in the DSBL blocklist
+
+uridnsbl	URIBL_SORBS	dnsbl.sorbs.net.	A
+header		URIBL_SORBS	eval:check_uridnsbl('URIBL_SORBS')
+describe	URIBL_SORBS	Contains a URL listed in the SORBS blocklist
+