You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jh...@apache.org on 2012/10/11 16:28:12 UTC

svn commit: r1397075 - in /spamassassin/trunk: lib/Mail/SpamAssassin/Message.pm t/data/spam/badmime3.txt t/mimeparse.t

Author: jhardin
Date: Thu Oct 11 14:28:12 2012
New Revision: 1397075

URL: http://svn.apache.org/viewvc?rev=1397075&view=rev
Log:
Bug 6845: fix parsing of multipart MIME when the first body content lines could be incorrectly interpreted as MIME headers

Added:
    spamassassin/trunk/t/data/spam/badmime3.txt
Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm
    spamassassin/trunk/t/mimeparse.t

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm?rev=1397075&r1=1397074&r2=1397075&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm Thu Oct 11 14:28:12 2012
@@ -338,6 +338,24 @@ sub new {
   ($self->{'type'}, $boundary) = Mail::SpamAssassin::Util::parse_content_type($self->header('content-type'));
   dbg("message: main message type: ".$self->{'type'});
 
+#  dbg("message: \$message[0]: \"" . $message[0] . "\"");
+
+  # bug 6845: if main message type is multipart and the message body does not begin with
+  # either a blank line or the boundary (if defined), insert a blank line
+  # to ensure proper parsing - do not consider MIME headers at the beginning of the body
+  # to be part of the message headers.
+  if ($self->{'type'} =~ /^multipart\//i && $#message > 0 && $message[0] =~ /\S/)
+  {
+    if (!defined $boundary || $message[0] !~ /^--\Q$boundary\E/)
+    {
+      dbg("message: Inserting blank line at top of body to ensure correct multipart MIME parsing");
+      unshift(@message, "\012");
+    }
+  }
+
+#  dbg("message: \$message[0]: \"" . $message[0] . "\"");
+#  dbg("message: \$message[1]: \"" . $message[1] . "\"");
+
   # parse queue, simple array of parts to parse:
   # 0: part object, already in the tree
   # 1: boundary used to focus body parsing
@@ -791,6 +809,7 @@ sub _parse_multipart {
     my $line;
     my $tmp_line = @{$body};
     for ($line=0; $line < $tmp_line; $line++) {
+#      dbg("message: multipart line $line: \"" . $body->[$line] . "\"");
       # specifically look for an opening boundary
       if ($body->[$line] =~ /^--\Q$boundary\E\s*$/) {
 	# Make note that we found the opening boundary

Added: spamassassin/trunk/t/data/spam/badmime3.txt
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/data/spam/badmime3.txt?rev=1397075&view=auto
==============================================================================
--- spamassassin/trunk/t/data/spam/badmime3.txt (added)
+++ spamassassin/trunk/t/data/spam/badmime3.txt Thu Oct 11 14:28:12 2012
@@ -0,0 +1,99 @@
+Return-Path: <ne...@linksandmail.com>
+Delivered-To: spam-quarantine
+X-SMTP-MAIL: <ne...@linksandmail.com>
+X-SMTP-RCPT: <Jo...@forwarder.ijs.si>
+X-Quarantine-id: <spam-3df3c6b0d99d7b3894111963f1d79502336f6d4b-20020620-082319-31067>
+Received: from mailer1.linksandmail.com (mailer1.linksandmail.com [64.38.215.194])
+	by Tink.ijs.si (Postfix) with SMTP id 5D7334812C
+	for <jo...@nsc.ijs.si>; Thu, 20 Jun 2002 08:00:10 +0200 (CEST)
+Content-Transfer-Encoding: binary
+Content-Type: multipart/alternative; boundary="_----------=_1024552428234762025905"
+MIME-Version: 1.0
+X-Mailer: MIME::Lite 2.117  (F2.6; B2.11; Q2.03)
+Date: Thu, 20 Jun 2002 05:53:48 UT
+From: "Newsletter" <ne...@linksandmail.com>
+To: joh.dokler@nsc.ijs.si
+Reply-To: customer-service@linksandmail.com
+Subject: To get on the cheer squad I, licked a lot of pus...
+Message-Id: <20...@Tink.ijs.si>
+
+Content-Disposition: inline
+Content-Length: 5162
+Content-Transfer-Encoding: binary
+Content-Type: text/html
+
+<HTML>
+<HEAD>
+<TITLE>Untitled-1</TITLE>
+<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
+</HEAD>
+<BODY BGCOLOR=#000000 LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
+<div align="center"></div>
+<TABLE WIDTH=697 BORDER=0 align="center" CELLPADDING=0 CELLSPACING=0>
+  <TR>
+		
+    <TD> <a href="http://sexmailnetwork.com/count.cgi?queue_id=1024516018.4603&forward=http://harder-please.com/forward/LSU.htm"><IMG SRC="http://www.harder-please.com/lsu/1/index_01.jpg" ALT="" WIDTH=131 HEIGHT=149 border="0"></a></TD>
+		
+    <TD COLSPAN=2> <a href="http://sexmailnetwork.com/count.cgi?queue_id=1024516018.4603&forward=http://harder-please.com/forward/LSU.htm"><IMG SRC="http://www.harder-please.com/lsu/1/index_02.jpg" ALT="" WIDTH=184 HEIGHT=149 border="0"></a></TD>
+		
+    <TD COLSPAN=4> <a href="http://sexmailnetwork.com/count.cgi?queue_id=1024516018.4603&forward=http://harder-please.com/forward/LSU.htm"><IMG SRC="http://www.harder-please.com/lsu/1/index_03.jpg" ALT="" WIDTH=233 HEIGHT=149 border="0"></a></TD>
+		
+    <TD> <a href="http://sexmailnetwork.com/count.cgi?queue_id=1024516018.4603&forward=http://harder-please.com/forward/LSU.htm"><IMG SRC="http://www.harder-please.com/lsu/1/index_04.jpg" ALT="" WIDTH=149 HEIGHT=149 border="0"></a></TD>
+		<TD>
+			<IMG SRC="http://www.harder-please.com/lsu/1/spacer.gif" WIDTH=1 HEIGHT=149 ALT=""></TD>
+	</TR>
+	<TR>
+		
+    <TD> <a href="http://sexmailnetwork.com/count.cgi?queue_id=1024516018.4603&forward=http://harder-please.com/forward/LSU.htm"><IMG SRC="http://www.harder-please.com/lsu/1/index_05.jpg" ALT="" WIDTH=131 HEIGHT=147 border="0"></a></TD>
+    <TD COLSPAN=3> <a href="http://sexmailnetwork.com/count.cgi?queue_id=1024516018.4603&forward=http://harder-please.com/forward/LSU.htm"><IMG SRC="http://www.harder-please.com/lsu/1/index_06.jpg" ALT="" WIDTH=204 HEIGHT=147 border="0"></a></TD>
+    <TD COLSPAN=2> <a href="http://sexmailnetwork.com/count.cgi?queue_id=1024516018.4603&forward=http://harder-please.com/forward/LSU.htm"><IMG SRC="http://www.harder-please.com/lsu/1/index_07.jpg" ALT="" WIDTH=182 HEIGHT=147 border="0"></a></TD>
+    <TD COLSPAN=2 ROWSPAN=2> <a href="http://sexmailnetwork.com/count.cgi?queue_id=1024516018.4603&forward=http://harder-please.com/forward/LSU.htm"><IMG SRC="http://www.harder-please.com/lsu/1/index_08.jpg" ALT="" WIDTH=180 HEIGHT=156 border="0"></a></TD>
+		<TD>
+			<IMG SRC="http://www.harder-please.com/lsu/1/spacer.gif" WIDTH=1 HEIGHT=147 ALT=""></TD>
+	</TR>
+	<TR>
+		
+    <TD COLSPAN=2 ROWSPAN=2> <a href="http://sexmailnetwork.com/count.cgi?queue_id=1024516018.4603&forward=http://harder-please.com/forward/LSU.htm"><IMG SRC="http://www.harder-please.com/lsu/1/index_09.jpg" ALT="" WIDTH=191 HEIGHT=177 border="0"></a></TD>
+		
+    <TD COLSPAN=3 ROWSPAN=2> <a href="http://sexmailnetwork.com/count.cgi?queue_id=1024516018.4603&forward=http://harder-please.com/forward/LSU.htm"><IMG SRC="http://www.harder-please.com/lsu/1/index_10.jpg" ALT="" WIDTH=180 HEIGHT=177 border="0"></a></TD>
+		
+    <TD ROWSPAN=2> <a href="http://sexmailnetwork.com/count.cgi?queue_id=1024516018.4603&forward=http://harder-please.com/forward/LSU.htm"><IMG SRC="http://www.harder-please.com/lsu/1/index_11.jpg" ALT="" WIDTH=146 HEIGHT=177 border="0"></a></TD>
+		<TD>
+			<IMG SRC="http://www.harder-please.com/lsu/1/spacer.gif" WIDTH=1 HEIGHT=9 ALT=""></TD>
+	</TR>
+	<TR>
+		
+    <TD COLSPAN=2> <a href="http://sexmailnetwork.com/count.cgi?queue_id=1024516018.4603&forward=http://harder-please.com/forward/LSU.htm"><IMG SRC="http://www.harder-please.com/lsu/1/index_12.jpg" ALT="" WIDTH=180 HEIGHT=168 border="0"></a></TD>
+		<TD>
+			<IMG SRC="http://www.harder-please.com/lsu/1/spacer.gif" WIDTH=1 HEIGHT=168 ALT=""></TD>
+	</TR>
+	<TR>
+		<TD>
+			<IMG SRC="http://www.harder-please.com/lsu/1/spacer.gif" WIDTH=131 HEIGHT=1 ALT=""></TD>
+		<TD>
+			<IMG SRC="http://www.harder-please.com/lsu/1/spacer.gif" WIDTH=60 HEIGHT=1 ALT=""></TD>
+		<TD>
+			<IMG SRC="http://www.harder-please.com/lsu/1/spacer.gif" WIDTH=124 HEIGHT=1 ALT=""></TD>
+		<TD>
+			<IMG SRC="http://www.harder-please.com/lsu/1/spacer.gif" WIDTH=20 HEIGHT=1 ALT=""></TD>
+		<TD>
+			<IMG SRC="http://www.harder-please.com/lsu/1/spacer.gif" WIDTH=36 HEIGHT=1 ALT=""></TD>
+		<TD>
+			<IMG SRC="http://www.harder-please.com/lsu/1/spacer.gif" WIDTH=146 HEIGHT=1 ALT=""></TD>
+		<TD>
+			<IMG SRC="http://www.harder-please.com/lsu/1/spacer.gif" WIDTH=31 HEIGHT=1 ALT=""></TD>
+		<TD>
+			<IMG SRC="http://www.harder-please.com/lsu/1/spacer.gif" WIDTH=149 HEIGHT=1 ALT=""></TD>
+		<TD></TD>
+	</TR>
+</TABLE>
+<div align="center"><a href="http://sexmailnetwork.com/count.cgi?queue_id=1024516018.4603&forward=http://harder-please.com/forward/LSU.htm"><IMG SRC="http://www.harder-please.com/lsu/1/enter.gif" width="700" height="33" border="0"></a> 
+</div>
+<div align="center"><a href="http://www.sexmailnetwork.com/unsubscribe.cgi?subscription_id=1001900781"><IMG SRC="http://www.harder-please.com/lsu/1/uns.gif" border="0"></a></div>
+<IMG height=1 width=1 src="http://sexmailnetwork.com/count.cgi?queue_id=1024516018.4603" border=0>
+</BODY>
+</HTML>
+--_----------=_1024552428234762025905--
+
+
+

Modified: spamassassin/trunk/t/mimeparse.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/mimeparse.t?rev=1397075&r1=1397074&r2=1397075&view=diff
==============================================================================
--- spamassassin/trunk/t/mimeparse.t (original)
+++ spamassassin/trunk/t/mimeparse.t Thu Oct 11 14:28:12 2012
@@ -83,6 +83,11 @@ my %files = (
 	  'e6e71e824aec0e204367bfdc9a9e227039f42815'
 	],
 
+	"$prefix/t/data/spam/badmime3.txt" => [
+	  join("\n",'multipart/alternative','text/plain'),
+	  '1c9972d2708b27f4da2e2ef87dd64d53bd11d086'
+	],
+
 	"$prefix/t/data/nice/mime9" => [
 	  join("\n",'multipart/mixed','text/plain','message/rfc822,message/rfc822,multipart/mixed,multipart/alternative,text/plain,text/html,image/jpeg'),
 	  '5cdcabdb89c5fbb3a5e0c0473599668927045d9c',