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 2007/01/22 23:05:22 UTC

svn commit: r498825 - /spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm

Author: jm
Date: Mon Jan 22 14:05:21 2007
New Revision: 498825

URL: http://svn.apache.org/viewvc?view=rev&rev=498825
Log:
bug 5250: in rewrite_mail(), messages would have all line endings rewritten -- even inside 8bit binary parts.  fix

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm?view=diff&rev=498825&r1=498824&r2=498825
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm Mon Jan 22 14:05:21 2007
@@ -620,9 +620,16 @@
     $msg .= $self->rewrite_no_report_safe();
   }
 
-  # Make the line endings appropriate for the situation
+  # Make the line endings (in the header only) appropriate for the situation.
+  # bug 5250: don't rewrite the body, since it'll corrupt 8bit data
   if ($self->{msg}->{line_ending} ne "\n") {
-    $msg =~ s/\r?\n/$self->{msg}->{line_ending}/g;
+    $msg =~ /^(.*?)\r?\n\r?\n(.*)$/s;
+    my $msghead = $1;
+    my $msgbody = $2;
+    $msghead =~ s/\r?\n/$self->{msg}->{line_ending}/gs;
+    $msg = $msghead.
+            $self->{msg}->{line_ending}.$self->{msg}->{line_ending}.
+            $msgbody;
   }
 
   return $msg;
@@ -764,6 +771,13 @@
 
   my $description = $self->{conf}->{'encapsulated_content_description'};
 
+  # create an additional randomised token to represent the original
+  # mail (temporarily) in the new message as we construct it
+  my $orig_token = "__ORIGINAL_".$boundary;
+  while ($newmsg =~ /\Q$orig_token\E/) {
+    $orig_token .= "/".sprintf("%08X",int(rand(2 ** 32)));
+  }
+
   # Note: the message should end in blank line since mbox format wants
   # blank line at end and messages may be concatenated!  In addition, the
   # x-spam-type parameter is fixed since we will use it later to recognize
@@ -787,11 +801,20 @@
 Content-Disposition: $disposition
 Content-Transfer-Encoding: 8bit
 
-$original
+$orig_token
 --$boundary--
 
 EOM
   
+  # now fix line endings in there...
+  if ($self->{msg}->{line_ending} ne "\n") {
+    $newmsg =~ s/\r?\n/$self->{msg}->{line_ending}/gs;
+  }
+
+  # and replace the token with the _real_ original mail (with its
+  # original newlines preserved intact)
+  $newmsg =~ s/\Q$orig_token\E/${original}/gs;
+
   return $newmsg;
 }