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/04/23 03:04:17 UTC

svn commit: rev 10189 - incubator/spamassassin/trunk/masses

Author: jm
Date: Thu Apr 22 18:04:16 2004
New Revision: 10189

Modified:
   incubator/spamassassin/trunk/masses/mass-check
Log:
added support for --deencap switch: de-encapsulate only mails that were marked up on a specific host

Modified: incubator/spamassassin/trunk/masses/mass-check
==============================================================================
--- incubator/spamassassin/trunk/masses/mass-check	(original)
+++ incubator/spamassassin/trunk/masses/mass-check	Thu Apr 22 18:04:16 2004
@@ -32,6 +32,9 @@
   --showdots    print a dot for each scanned message
   --rules=RE    Only test rules matching the given regexp RE
   --restart=N   restart all of the children after processing N messages
+  --deencap=RE  Extract SpamAssassin-encapsulated spam mails only if they
+                were encapsulated by servers matching the regexp RE
+                (default = extract all SpamAssassin-encapsulated mails)
  
   log options
   -o            write all logs to stdout
@@ -72,7 +75,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_loguris $opt_after $opt_rewrite);
+	    $opt_loguris $opt_after $opt_rewrite $opt_deencap);
 
 use FindBin;
 use lib "$FindBin::Bin/../lib";
@@ -94,7 +97,7 @@
 GetOptions("c=s", "p=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", "loguris",
+	   "rules=s", "restart=i", "after=s", "loguris", "deencap=s",
 	   "dir" => sub { $opt_format = "dir"; },
 	   "file" => sub { $opt_format = "file"; },
 	   "mbox" => sub { $opt_format = "mbox"; },
@@ -247,13 +250,16 @@
   my $ma = $spamtest->parse($dataref);
 
   # remove SpamAssassin markup, if present and the mail was spam
-  $_ = $ma->get_header ("X-Spam-Status");
-  if (defined($_) && /^Yes,/) {
-    my $new_ma = $spamtest->parse ($spamtest->remove_spamassassin_markup($ma), 1);
-    $ma->finish();
-    $ma = $new_ma;
+  my $stat = $ma->get_header ("X-Spam-Status");
+  if ($stat && $stat =~ /^Yes,/) {
+    if (!$opt_deencap || message_should_be_deencapped ($ma)) {
+      my $new_ma = $spamtest->parse ($spamtest->remove_spamassassin_markup($ma), 1);
+      $ma->finish();
+      $ma = $new_ma;
+    }
   }
 
+
   # log-uris support
   my $status;
   my @uris;
@@ -345,6 +351,29 @@
   }
 
   return $out;
+}
+
+sub message_should_be_deencapped {
+  my ($ma) = @_;
+
+  my $vers = $ma->get_header ("X-Spam-Checker-Version");
+  return 1 if (!$vers);     # no header? probably not SpamAssassin encapsulation.
+  # return 1 so that old versions of SpamAssassin encapping are removed
+
+  $vers =~ s/\s+/ /gs;
+  if ($vers !~ / on (\S+)\s*$/) {
+    # X-Spam-Checker-Version has no hostname.
+    # always remove the markup, it's probably not an encapsulated message
+    # in that case
+    return 1;
+  }
+
+  my $hname = $1;
+  if ($hname =~ /$opt_deencap/io) {
+    return 1;
+  }
+
+  return 0;     # a different host marked it up.  pass it through!
 }
 
 sub logkilled {