Bug 6617: Fix description appending emails
git-svn-id: https://svn.apache.org/repos/asf/spamassassin/branches/3.3@1308175 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/Mail/SpamAssassin/Plugin/FreeMail.pm b/lib/Mail/SpamAssassin/Plugin/FreeMail.pm
index 93d7571..291e8f1 100644
--- a/lib/Mail/SpamAssassin/Plugin/FreeMail.pm
+++ b/lib/Mail/SpamAssassin/Plugin/FreeMail.pm
@@ -1,5 +1,6 @@
package Mail::SpamAssassin::Plugin::FreeMail;
-my $VERSION = 2.001;
+use strict;
+my $VERSION = 2.002;
### About:
#
@@ -80,6 +81,7 @@
# 1.999 - default whitelist undisclosed-recipient@yahoo.com etc
# 2.000 - some cleaning up
# 2.001 - fix freemail_whitelist
+# 2.002 - _add_desc -> _got_hit, fix description email append bug
#
### Blah:
@@ -108,7 +110,6 @@
use Mail::SpamAssassin::Plugin;
use Mail::SpamAssassin::PerMsgStatus;
use Mail::SpamAssassin::Util::RegistrarBoundaries;
-use strict;
use vars qw(@ISA);
@ISA = qw(Mail::SpamAssassin::Plugin);
@@ -178,7 +179,7 @@
sub set_config {
my ($self, $conf) = @_;
- my @cmds = ();
+ my @cmds;
push(@cmds, {
setting => 'freemail_max_body_emails',
default => 5,
@@ -328,7 +329,7 @@
my $parsed = $pms->get_uri_detail_list();
while (my($uri, $info) = each %{$parsed}) {
if (defined $info->{types}->{a} and not defined $info->{types}->{parsed}) {
- if ($uri =~ /^mailto:${email_regex}/) {
+ if ($uri =~ /^(?:(?i)mailto):${email_regex}/) {
my $email = lc($1);
push(@body_emails, $email) unless defined $seen{$email};
$seen{$email} = 1;
@@ -384,16 +385,21 @@
return 1;
}
-sub _add_desc {
+sub _got_hit {
my ($self, $pms, $email, $desc) = @_;
my $rulename = $pms->get_current_eval_rule_name();
- if (not defined $pms->{conf}->{descriptions}->{$rulename}) {
- $pms->{conf}->{descriptions}->{$rulename} = $desc;
+
+ if (defined $pms->{conf}->{descriptions}->{$rulename}) {
+ $desc = $pms->{conf}->{descriptions}->{$rulename};
}
+
if ($pms->{main}->{conf}->{freemail_add_describe_email}) {
$email =~ s/\@/[at]/g;
- $pms->{conf}->{descriptions}->{$rulename} .= " ($email)";
+ $pms->got_hit($rulename, "", description => $desc." ($email)", ruletype => 'eval');
+ }
+ else {
+ $pms->got_hit($rulename, "", description => $desc, ruletype => 'eval');
}
}
@@ -435,8 +441,8 @@
else {
dbg("HIT! $email is freemail");
}
- $self->_add_desc($pms, $email, "Header $header is freemail");
- return 1;
+ $self->_got_hit($pms, $email, "Header $header is freemail");
+ return 0;
}
return 0;
@@ -465,16 +471,16 @@
foreach my $email (keys %{$pms->{freemail_cache}{body}}) {
if ($email =~ $re) {
dbg("HIT! email from body is freemail and matches regex: $email");
- $self->_add_desc($pms, $email, "Email from body is freemail");
- return 1;
+ $self->_got_hit($pms, $email, "Email from body is freemail");
+ return 0;
}
}
}
elsif (scalar keys %{$pms->{freemail_cache}{body}}) {
my $emails = join(', ', keys %{$pms->{freemail_cache}{body}});
dbg("HIT! body has freemails: $emails");
- $self->_add_desc($pms, $emails, "Body contains freemails");
- return 1;
+ $self->_got_hit($pms, $emails, "Body contains freemails");
+ return 0;
}
return 0;
@@ -516,8 +522,8 @@
else {
dbg("HIT! $email is freemail");
}
- $self->_add_desc($pms, $email, "Sender address is freemail");
- return 1;
+ $self->_got_hit($pms, $email, "Sender address is freemail");
+ return 0;
}
return 0;
@@ -560,8 +566,8 @@
if ($from_is_fm and $replyto_is_fm and ($from ne $replyto)) {
dbg("HIT! From and Reply-To are different freemails");
- $self->_add_desc($pms, "$from, $replyto", "From and Reply-To are different freemails");
- return 1;
+ $self->_got_hit($pms, "$from, $replyto", "From and Reply-To are different freemails");
+ return 0;
}
if ($what eq 'replyto') {
@@ -591,8 +597,8 @@
foreach my $email (keys %{$pms->{freemail_cache}{body}}) {
if ($email ne $check) {
dbg("HIT! $check and $email are different freemails");
- $self->_add_desc($pms, "$check, $email", "Different freemails in reply header and body");
- return 1;
+ $self->_got_hit($pms, "$check, $email", "Different freemails in reply header and body");
+ return 0;
}
}
}