Index: MANIFEST =================================================================== --- MANIFEST (revision 56704) +++ MANIFEST (working copy) @@ -366,3 +366,5 @@ TRADEMARK UPGRADE USAGE +t/strip_no_subject.t +t/data/spam/014 Index: lib/Mail/SpamAssassin.pm =================================================================== --- lib/Mail/SpamAssassin.pm (revision 56704) +++ lib/Mail/SpamAssassin.pm (working copy) @@ -931,6 +931,16 @@ 1 while ($body =~ s/^\n?SPAM: ----.+\n(?:SPAM:.*\n)*SPAM: ----.+\n\n//); ########################################################################### + # 3.0 version -- support for previously-nonexistent Subject hdr. + # ensure the Subject line didn't *really* contain "(nonexistent)" in + # the original message! + if ($hdrs =~ /^X-Spam-Prev-Subject:\s*\(nonexistent\)$/m + && $hdrs !~ /^Subject:.*\(nonexistent\).*$/m) + { + $hdrs =~ s/(^|\n)X-Spam-Prev-Subject:\s*\(nonexistent\)\n/$1\n/s; + $hdrs =~ s/(^|\n)Subject:\s*[ \t]*.*\n(?:\s+\S.*\n)*/$1\n/s; + } + # 3.0 version -- revert from X-Spam-Prev to original ... while ($hdrs =~ s/^X-Spam-Prev-(([^:]+:)[ \t]*.*\n(?:\s+\S.*\n)*)//m) { my($hdr, $name) = ($1,$2); Index: lib/Mail/SpamAssassin/Conf.pm =================================================================== --- lib/Mail/SpamAssassin/Conf.pm (revision 56704) +++ lib/Mail/SpamAssassin/Conf.pm (working copy) @@ -551,11 +551,17 @@ this will be prepended to the original subject. Note that you should only use the _REQD_ and _SCORE_ tags when rewriting the Subject header unless C is 0. Otherwise, you may not be able to remove -the SpamAssassin markup via the normal methods. Parentheses are not -permitted in STRING if rewriting the From or To headers. (They will be -converted to square brackets.) A null value for C will remove -any existing rewrite for the specified header. +the SpamAssassin markup via the normal methods. +Parentheses are not permitted in STRING if rewriting the From or To headers. +(They will be converted to square brackets.) + +If C is used, but the message being rewritten +does not already contain a C header, one will be created. + +A null value for C will remove any existing rewrite for the specified +header. + =cut push (@cmds, { Index: lib/Mail/SpamAssassin/PerMsgStatus.pm =================================================================== --- lib/Mail/SpamAssassin/PerMsgStatus.pm (revision 56705) +++ lib/Mail/SpamAssassin/PerMsgStatus.pm (working copy) @@ -873,7 +873,19 @@ my(@pristine_headers) = grep(!/^X-Spam-(?!Prev-)/i, $self->{msg}->get_pristine_header() =~ /^([^:]+:[ \t]*(?:.*\n(?:\s+\S.*\n)*))/mig); my $addition = 'headers_ham'; - if($self->{is_spam}) { + if($self->{is_spam}) + { + # special-case: Subject lines. ensure one exists, if we're + # supposed to mark it up. + my $created_subject = 0; + my $subject = $self->{msg}->get_pristine_header('Subject'); + if (!defined($subject) && $self->{is_spam} + && exists $self->{conf}->{rewrite_header}->{'Subject'}) + { + push(@pristine_headers, "Subject: \n"); + $created_subject = 1; + } + # Deal with header rewriting foreach (@pristine_headers) { # if we're not going to do a rewrite, skip this header! @@ -882,7 +894,11 @@ next if (!exists $self->{conf}->{rewrite_header}->{$hdr}); # pop the original version onto the end of the header array - push(@pristine_headers, "X-Spam-Prev-$_"); + if ($created_subject) { + push(@pristine_headers, "X-Spam-Prev-Subject: (nonexistent)\n"); + } else { + push(@pristine_headers, "X-Spam-Prev-$_"); + } # Figure out the rewrite piece my $tag = $self->_replace_tags($self->{conf}->{rewrite_header}->{$hdr}); Index: t/strip_no_subject.t =================================================================== --- t/strip_no_subject.t (revision 0) +++ t/strip_no_subject.t (revision 0) @@ -0,0 +1,68 @@ +#!/usr/bin/perl + +use lib '.'; use lib 't'; +use SATest; sa_t_init("strip_no_subject"); +use Test; BEGIN { plan tests => 4 }; + +# --------------------------------------------------------------------------- + +use File::Copy; +use File::Compare qw(compare_text); + +my $INPUT = 'data/spam/014'; +my $MUNGED = 'log/strip_no_subject.munged'; + +tstprefs (" + $default_cf_lines + report_safe 1 + rewrite_header subject ***SPAM*** + "); + +# create report_safe 1 and -t output +sarun ("-L -t < $INPUT"); +if (move("log/$testname.${Test::ntest}", $MUNGED)) { + sarun ("-d < $MUNGED"); + ok(!compare_text($INPUT,"log/$testname.${Test::ntest}")); +} +else { + warn "move failed: $!\n"; + ok(0); +} + +tstprefs (" + $default_cf_lines + report_safe 2 + rewrite_header subject ***SPAM*** + "); + +# create report_safe 2 output +sarun ("-L < $INPUT"); +if (move("log/$testname.${Test::ntest}", $MUNGED)) { + sarun ("-d < $MUNGED"); + ok(!compare_text($INPUT,"log/$testname.${Test::ntest}")); +} +else { + warn "move failed: $!\n"; + ok(0); +} + +tstprefs (" + $default_cf_lines + report_safe 0 + rewrite_header subject ***SPAM*** + "); + +# create report_safe 0 output +sarun ("-L < $INPUT"); +if (move("log/$testname.${Test::ntest}", $MUNGED)) { + sarun ("-d < $MUNGED"); + ok(!compare_text($INPUT,"log/$testname.${Test::ntest}")); +} +else { + warn "move failed: $!\n"; + ok(0); +} + +# Work directly on regular message, as though it was not spam +sarun ("-d < $INPUT"); +ok(!compare_text($INPUT,"log/$testname.${Test::ntest}")); Property changes on: t/strip_no_subject.t ___________________________________________________________________ Name: svn:executable + * Index: t/data/spam/014 =================================================================== --- t/data/spam/014 (revision 0) +++ t/data/spam/014 (revision 0) @@ -0,0 +1,7 @@ +Message-ID: +Date: Wed, 23 Jul 2003 23:30:00 +0200 +From: Sender +To: Recipient + +XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X +