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/11/23 17:34:35 UTC

svn commit: r106311 - /spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm /spamassassin/trunk/t/missing_hb_separator.t

Author: felicity
Date: Tue Nov 23 08:34:32 2004
New Revision: 106311

Modified:
   spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm
   spamassassin/trunk/t/missing_hb_separator.t
Log:
bug 3974: more updates to the test, found a case which wasn't covered, simplified the handling of the missing separator, header boundary check depended on multipart content-type which isn't required for a boundary.

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm
Url: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm?view=diff&rev=106311&p1=spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm&r1=106310&p2=spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm&r2=106311
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm	(original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm	Tue Nov 23 08:34:32 2004
@@ -128,12 +128,12 @@
   # Go through all the headers of the message
   my $header = '';
   my $boundary;
-  while ( my $last = shift @message ) {
-    if ( $last =~ /^From\s/ ) {
+  while ( my $current = shift @message ) {
+    if ( $current =~ /^From\s/ ) {
 	# mbox formated mailbox
-	$self->{'mbox_sep'} = $last;
+	$self->{'mbox_sep'} = $current;
 	next;
-    } elsif ($last =~ MBX_SEPARATOR) {
+    } elsif ($current =~ MBX_SEPARATOR) {
 	# Munge the mbx message separator into mbox format as a sort of
 	# de facto portability standard in SA's internals.  We need to
 	# to this so that Mail::SpamAssassin::Util::parse_rfc822_date
@@ -162,12 +162,26 @@
     }
 
     # Store the non-modified headers in a scalar
-    $self->{'pristine_headers'} .= $last;
+    $self->{'pristine_headers'} .= $current;
+
+    # Check for missing head/body separator and deal appropriately
+    if ($current !~ /^\r?$/) {
+      if (!@message) {
+	# No body is invalid
+        $self->{'missing_head_body_separator'} = 1;
+        push(@message, "\n");
+      }
+      elsif (defined $boundary && $message[0] =~ /^--\Q$boundary\E(?:--|\s*$)/) {
+        # No separator before the body is invalid
+        $self->{'missing_head_body_separator'} = 1;
+	unshift(@message, "\n");
+      }
+    }
 
     # NB: Really need to figure out special folding rules here!
-    if ( $last =~ /^[ \t]+/ ) {                    # if its a continuation
+    if ( $current =~ /^[ \t]+/ ) {                    # if its a continuation
       if ($header) {
-        $header .= $last;                            # fold continuations
+        $header .= $current;                            # fold continuations
 
 	# If we're currently dealing with a content-type header, and there's a
 	# boundary defined, use it.  Since there could be multiple
@@ -175,13 +189,8 @@
 	# should use, so just keep updating as they come in.
         if ($header =~ /^content-type:\s*(\S.*)$/is) {
 	  my($type,$temp_boundary) = Mail::SpamAssassin::Util::parse_content_type($1);
-	  $boundary = $temp_boundary if ($type =~ /^multipart/ && defined $temp_boundary);
+	  $boundary = $temp_boundary if (defined $temp_boundary);
 	}
-
-	# Go onto the next header line, unless the next line is a
-	# multipart mime boundary, where we know we're going to stop
-	# below, so drop through for final header processing.
-        next unless (defined $boundary && $message[0] =~ /^--\Q$boundary\E(?:--|\s*$)/);
       }
       else {
 	# There was no previous header and this is just "out there"?
@@ -214,30 +223,16 @@
 	# should use, so just keep updating as they come in.
         if (lc $key eq 'content-type') {
 	  my($type,$temp_boundary) = Mail::SpamAssassin::Util::parse_content_type($value);
-	  $boundary = $temp_boundary if ($type =~ /^multipart/ && defined $temp_boundary);
+	  $boundary = $temp_boundary if (defined $temp_boundary);
 	}
       }
     }
 
-    # not a continuation...
-    $header = $last;
-
     # Ok, we found the header/body blank line ...
-    last if ($last =~ /^\r?$/m);
-
-    # There's no body on this message?!?  Fake the separator and mark the behavior!
-    if (!@message) {
-      $self->{'missing_head_body_separator'} = 1;
-      push(@message, "\n");
-      next;
-    }
+    last if ($current =~ /^\r?$/);
 
-    # Alternately, if a multipart mime boundary is found in the header area,
-    # aka it's malformed, exit out as well and treat it as part of the body.
-    if (defined $boundary && $message[0] =~ /^--\Q$boundary\E(?:--|\s*$)/) {
-      $self->{'missing_head_body_separator'} = 1;
-      last;
-    }
+    # not a continuation...
+    $header = $current;
   }
 
   # Store the pristine body for later -- store as a copy since @message

Modified: spamassassin/trunk/t/missing_hb_separator.t
Url: http://svn.apache.org/viewcvs/spamassassin/trunk/t/missing_hb_separator.t?view=diff&rev=106311&p1=spamassassin/trunk/t/missing_hb_separator.t&r1=106310&p2=spamassassin/trunk/t/missing_hb_separator.t&r2=106311
==============================================================================
--- spamassassin/trunk/t/missing_hb_separator.t	(original)
+++ spamassassin/trunk/t/missing_hb_separator.t	Tue Nov 23 08:34:32 2004
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/perl -w
 
 BEGIN {
   if (-e 't/test_dir') { # if we are running "t/rule_tests.t", kluge around ...
@@ -20,7 +20,7 @@
 use SATest; sa_t_init("missing_hb_separator");
 use Mail::SpamAssassin;
 
-plan tests => 2;
+plan tests => 3;
 
 # initialize SpamAssassin
 my $sa = Mail::SpamAssassin->new({
@@ -33,11 +33,18 @@
 });
 $sa->init(0); # parse rules
 
-my @msg = ( "Subject: foo bar\n" );
-my $mail = $sa->parse(\@msg, 1);
-my $status = $sa->check($mail);
+my @msg;
+my $mail;
+my $status;
+my $result;
 
-my $result = 0;
+#####
+
+@msg = ("Content-Type: text/plain; boundary=--foo\n");
+$mail = $sa->parse(\@msg, 1);
+$status = $sa->check($mail);
+
+$result = 0;
 foreach (@{$status->{test_names_hit}}) {
   $result = 1 if ($_ eq 'MISSING_HB_SEP');
 }
@@ -47,12 +54,31 @@
 $status->finish();
 $mail->finish();
 
+#####
 
-$result = 1;
-push(@msg, "\n");
+@msg = ("Content-Type: text/plain;\n"," boundary=--foo\n");
+$mail = $sa->parse(\@msg, 1);
+$status = $sa->check($mail);
+
+$result = 0;
+foreach (@{$status->{test_names_hit}}) {
+  $result = 1 if ($_ eq 'MISSING_HB_SEP');
+}
+
+ok ( $result );
+
+$status->finish();
+$mail->finish();
+
+#####
+
+# A normal message, should not trigger
+
+@msg = ("Content-Type: text/plain; boundary=--foo\n","\n","--foo\n");
 $mail = $sa->parse(\@msg, 1);
 $status = $sa->check($mail);
 
+$result = 1;
 foreach (@{$status->{test_names_hit}}) {
   $result = 0 if ($_ eq 'MISSING_HB_SEP');
 }