You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by fe...@apache.org on 2004/02/29 03:01:46 UTC

svn commit: rev 6926 - in incubator/spamassassin/trunk: lib/Mail lib/Mail/SpamAssassin t

Author: felicity
Date: Sat Feb 28 18:01:44 2004
New Revision: 6926

Modified:
   incubator/spamassassin/trunk/lib/Mail/SpamAssassin.pm
   incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm
   incubator/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
   incubator/spamassassin/trunk/t/strip2.t
Log:
bug 3108: make the mbox seperator not a header (take it out of pristine_headers, etc.)  remove the 'look for the mbox seperator and remove it' code in a few sections of the code.  added different report_safe remove markup tests to strip2.t, etc.

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin.pm	(original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin.pm	Sat Feb 28 18:01:44 2004
@@ -351,14 +351,14 @@
 
   # Go through all the headers of the message
   while ( my $last = shift @message ) {
-    # Store the non-modified headers in a scalar
-    $msg->{'pristine_headers'} .= $last;
-
     if ( $last =~ /^From\s/ ) {
       $msg->{'mbox_sep'} = $last;
       next;
     }
 
+    # Store the non-modified headers in a scalar
+    $msg->{'pristine_headers'} .= $last;
+
     # NB: Really need to figure out special folding rules here!
     if ( $last =~ /^[ \t]+/ ) {                    # if its a continuation
       $header .= $last;                            # fold continuations
@@ -930,6 +930,8 @@
   my ($self, $mail_obj) = @_;
   local ($_);
 
+  my $mbox = $mail_obj->get_mbox_seperator() || '';
+
   dbg("Removing Markup");
   $self->init(1);
   my $ct = $mail_obj->get_header("Content-Type") || '';
@@ -946,9 +948,9 @@
     $ct   = '';
     my $cd = '';
     for ( my $i = 0 ; $i <= $#msg ; $i++ ) {
-      next
-        unless ( $msg[$i] =~ /^--$boundary$/ || $flag )
-        ;    # only look at mime headers
+      # only look at mime headers
+      next unless ( $msg[$i] =~ /^--$boundary$/ || $flag );
+
       if ( $msg[$i] =~ /^\s*$/ ) {    # end of mime header
 
         # Ok, we found the encapsulated piece ...
@@ -956,9 +958,8 @@
 	    ($ct eq "message/rfc822" &&
 	     $cd eq $self->{'encapsulated_content_description'}))
         {
-          splice @msg, 1, $i;
-            ;    # remove the front part, leave the 'From ' header.
-	  splice @msg, 0, 1 if ( $msg[0] !~ /^From / ); # not From?  remove it.
+          splice @msg, 0, $i+1;  # remove the front part, including the blank line
+
           # find the end and chop it off
           for ( $i = 0 ; $i <= $#msg ; $i++ ) {
             if ( $msg[$i] =~ /^--$boundary/ ) {
@@ -970,7 +971,7 @@
           }
 
 	  # Ok, we're done.  Return the message.
-	  return join('',@msg);
+	  return join('', $mbox, @msg);
         }
 
         $flag = 0;
@@ -1068,7 +1069,7 @@
     }
   }
 
-  return join ('', $hdrs, @newbody);
+  return join ('', $mbox, $hdrs, @newbody);
 }
 
 ###########################################################################

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm	(original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm	Sat Feb 28 18:01:44 2004
@@ -472,8 +472,6 @@
   my @rcvdlines = ($hdrs =~ /^Received: [^\n]*$/gim);
 
   # and now delete lines for headers we don't want (incl all Receiveds)
-  $hdrs =~ s/^From \S+[^\n]+$//gim;
-
   $hdrs =~ s/^${IGNORED_HDRS}: [^\n]*$//gim;
 
   if (IGNORE_MSGID_TOKENS) { $hdrs =~ s/^Message-I[dD]: [^\n]*$//gim;}

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	Sat Feb 28 18:01:44 2004
@@ -587,16 +587,17 @@
 sub rewrite_mail {
   my ($self) = @_;
 
+  my $mbox = $self->{msg}->get_mbox_seperator() || '';
   if ($self->{is_spam} && $self->{conf}->{report_safe}) {
-    return $self->rewrite_as_spam();
+    return $mbox.$self->rewrite_report_safe();
   }
   else {
-    return $self->rewrite_headers();
+    return $mbox.$self->rewrite_no_report_safe();
   }
 }
 
 # rewrite the entire message as spam (headers and body)
-sub rewrite_as_spam {
+sub rewrite_report_safe {
   my ($self) = @_;
 
   # This is the original message.  We do not want to make any modifications so
@@ -607,9 +608,6 @@
   # This is the new message.
   my $newmsg = '';
 
-  # remove first line if it is "From "
-  $original =~ s/^From .*\n//;
-
   # the report charset
   my $report_charset = "";
   if ($self->{conf}->{report_charset}) {
@@ -752,11 +750,10 @@
 
 EOM
   
-  my $mbox = $self->{msg}->get_mbox_seperator() || '';
-  return $mbox . $newmsg;
+  return $newmsg;
 }
 
-sub rewrite_headers {
+sub rewrite_no_report_safe {
   my ($self) = @_;
 
   # put the pristine headers into an array
@@ -795,8 +792,7 @@
     push(@pristine_headers, "X-Spam-$header: $line\n");
   }
 
-  my $mbox = $self->{msg}->get_mbox_seperator() || '';
-  return join('', $mbox, @pristine_headers, "\n", $self->{msg}->get_pristine_body());
+  return join('', @pristine_headers, "\n", $self->{msg}->get_pristine_body());
 }
 
 sub qp_encode_header {

Modified: incubator/spamassassin/trunk/t/strip2.t
==============================================================================
--- incubator/spamassassin/trunk/t/strip2.t	(original)
+++ incubator/spamassassin/trunk/t/strip2.t	Sat Feb 28 18:01:44 2004
@@ -2,7 +2,7 @@
 
 use lib '.'; use lib 't';
 use SATest; sa_t_init("strip2");
-use Test; BEGIN { plan tests => 3 };
+use Test; BEGIN { plan tests => 4 };
 
 # ---------------------------------------------------------------------------
 
@@ -17,7 +17,12 @@
 my $INPUT = 'data/spam/002';
 my $MUNGED = 'log/strip2.munged';
 
-# create the -t output
+tstprefs ("
+        $default_cf_lines
+        report_safe 1
+	");
+
+# create report_safe 1 and -t output
 sarun ("-L -t < $INPUT");
 if (move("log/$testname.${Test::ntest}", $MUNGED)) {
   sarun ("-d < $MUNGED");
@@ -28,7 +33,28 @@
   ok(0);
 }
 
-# create the normal output
+tstprefs ("
+        $default_cf_lines
+        report_safe 2
+	");
+
+# create report_safe 2 output
+sarun ("-L < $INPUT");
+if (move("log/$testname.${Test::ntest}", $MUNGED)) {
+  sarun ("-d < $MUNGED");
+  ok(diff($INPUT,"log/$testname.${Test::ntest}"));
+}
+else {
+  warn "move failed: $!\n";
+  ok(0);
+}
+
+tstprefs ("
+        $default_cf_lines
+        report_safe 0
+	");
+
+# create report_safe 0 output
 sarun ("-L < $INPUT");
 if (move("log/$testname.${Test::ntest}", $MUNGED)) {
   sarun ("-d < $MUNGED");