Mailing List Archive

svn commit: r332967 - /spamassassin/branches/3.0/lib/Mail/SpamAssassin/Message.pm
Author: sidney
Date: Sun Nov 13 03:52:01 2005
New Revision: 332967

URL: http://svn.apache.org/viewcvs?rev=332967&view=rev
Log:
bug 3712 more efficient parsing of messages with lots of newlines in header

Modified:
spamassassin/branches/3.0/lib/Mail/SpamAssassin/Message.pm

Modified: spamassassin/branches/3.0/lib/Mail/SpamAssassin/Message.pm
URL: http://svn.apache.org/viewcvs/spamassassin/branches/3.0/lib/Mail/SpamAssassin/Message.pm?rev=332967&r1=332966&r2=332967&view=diff
==============================================================================
--- spamassassin/branches/3.0/lib/Mail/SpamAssassin/Message.pm (original)
+++ spamassassin/branches/3.0/lib/Mail/SpamAssassin/Message.pm Sun Nov 13 03:52:01 2005
@@ -220,8 +220,30 @@
$self->{'pristine_body'} = join('', @message);

# CRLF -> LF
- for ( @message ) {
- s/\r\n/\n/;
+ # also merge multiple blank lines into a single one
+ my $start;
+ # iterate over lines in reverse order
+ for (my $cnt=$#message; $cnt>=0; $cnt--) {
+ $message[$cnt] =~ s/\r\n/\n/;
+
+ # line is blank
+ if ($message[$cnt] !~ /\S/) {
+ if (!defined $start) {
+ $start=$cnt;
+ }
+ next unless $cnt == 0;
+ }
+
+ # line is not blank, or we've reached the beginning
+
+ # if we've got a series of blank lines, get rid of them
+ if (defined $start) {
+ my $num = $start-$cnt;
+ if ($num > 10) {
+ splice @message, $cnt+2, $num-1;
+ }
+ undef $start;
+ }
}

# If the message does need to get parsed, save off a copy of the body