You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by mm...@apache.org on 2008/02/21 18:43:44 UTC
svn commit: r629888 - in /spamassassin/trunk/lib/Mail/SpamAssassin:
Message.pm Message/Node.pm Plugin/BodyEval.pm
Author: mmartinec
Date: Thu Feb 21 09:43:43 2008
New Revision: 629888
URL: http://svn.apache.org/viewvc?rev=629888&view=rev
Log:
New sub Message::split_into_array_of_short_lines to nicely split a text into array of paragraph chunks of sizes between 1 kB and 2 kB; bugs: 5717, 5644, 5795, 5486, 5801, 5041
Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm
spamassassin/trunk/lib/Mail/SpamAssassin/Message/Node.pm
spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/BodyEval.pm
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm?rev=629888&r1=629887&r2=629888&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm Thu Feb 21 09:43:43 2008
@@ -1098,7 +1098,8 @@
next if ($parts[$pt]->{'type'} eq 'text/calendar');
push(@{$self->{text_decoded}}, "\n") if ( @{$self->{text_decoded}} );
- push(@{$self->{text_decoded}}, $parts[$pt]->decode());
+ push(@{$self->{text_decoded}},
+ split_into_array_of_short_paragraphs($parts[$pt]->decode()));
}
return $self->{text_decoded};
@@ -1118,6 +1119,28 @@
}
push (@result, $line);
}
+ @result;
+}
+
+# ---------------------------------------------------------------------------
+
+# split a text into array of paragraphs of sizes between
+# $chunk_size and 2 * $chunk_size, returning the resulting array
+
+sub split_into_array_of_short_paragraphs {
+ my @result;
+ my $chunk_size = 1024;
+ my $text_l = length($_[0]);
+ my($j,$ofs);
+ for ($ofs = 0; $text_l - $ofs > 2 * $chunk_size; $ofs = $j+1) {
+ $j = index($_[0], "\n", $ofs+$chunk_size);
+ if ($j < 0) {
+ $j = index($_[0], " ", $ofs+$chunk_size);
+ if ($j < 0) { $j = $ofs+$chunk_size }
+ }
+ push(@result, substr($_[0], $ofs, $j-$ofs+1));
+ }
+ push(@result, substr($_[0], $ofs)) if $ofs < $text_l;
@result;
}
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Message/Node.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Message/Node.pm?rev=629888&r1=629887&r2=629888&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Message/Node.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Message/Node.pm Thu Feb 21 09:43:43 2008
@@ -333,7 +333,6 @@
$self->{'decoded'} = Mail::SpamAssassin::Util::base64_decode($raw);
}
- # If it's a type text or message, split it into an array of lines
if ( $self->{'type'} =~ m@^(?:text|message)\b/@i ) {
$self->{'decoded'} =~ s/\015\012/\012/gs;
}
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/BodyEval.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/BodyEval.pm?rev=629888&r1=629887&r2=629888&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/BodyEval.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/BodyEval.pm Thu Feb 21 09:43:43 2008
@@ -241,27 +241,34 @@
my ($type, $rnd) = $part->rendered();
return unless $type;
- foreach ( $rnd =~ /^\s*([^:\s][^:\n]{2,29})\s*:\s*\S/mg ) {
- my $str = lc $_;
- $str =~ tr/a-z//cd;
- #$str =~ s/([a-z])0([a-z])/$1o$2/g;
+ # bug 5644,5717: avoid pathological cases where a regexp takes massive amount
+ # of time by applying the regexp to limited-size text chunks, one at a time
- if ($str =~ /(
- ^trad(?:e|ing)date|
- company(?:name)?|
- s\w?(?:t\w?o\w?c\w?k|y\w?m(?:\w?b\w?o\w?l)?)|
- t(?:arget|icker)|
- (?:opening|current)p(?:rice)?|
- p(?:rojected|osition)|
- expectations|
- weeks?high|
- marketperformance|
- (?:year|week|month|day|price)(?:target|estimates?)|
- sector|
- r(?:ecommendation|ating)
- )$/x) {
- $hits{$1}++;
- dbg("eval: stock info hit: $1");
+ foreach my $rnd_chunk (
+ Mail::SpamAssassin::Message::split_into_array_of_short_paragraphs($rnd))
+ {
+ foreach ( $rnd_chunk =~ /^\s*([^:\s][^:\n]{2,29})\s*:\s*\S/mg ) {
+ my $str = lc $_;
+ $str =~ tr/a-z//cd;
+ #$str =~ s/([a-z])0([a-z])/$1o$2/g;
+
+ if ($str =~ /(
+ ^trad(?:e|ing)date|
+ company(?:name)?|
+ s\w?(?:t\w?o\w?c\w?k|y\w?m(?:\w?b\w?o\w?l)?)|
+ t(?:arget|icker)|
+ (?:opening|current)p(?:rice)?|
+ p(?:rojected|osition)|
+ expectations|
+ weeks?high|
+ marketperformance|
+ (?:year|week|month|day|price)(?:target|estimates?)|
+ sector|
+ r(?:ecommendation|ating)
+ )$/x) {
+ $hits{$1}++;
+ dbg("eval: stock info hit: $1");
+ }
}
}