~ubuntu-branches/ubuntu/utopic/spamassassin/utopic-updates

« back to all changes in this revision

Viewing changes to lib/Mail/SpamAssassin/Plugin/FreeMail.pm

  • Committer: Package Import Robot
  • Author(s): Noah Meyerhans
  • Date: 2014-02-14 22:45:15 UTC
  • mfrom: (0.8.1) (0.6.2) (5.1.22 sid)
  • Revision ID: package-import@ubuntu.com-20140214224515-z1es2twos8xh7n2y
Tags: 3.4.0-1
* New upstream version! (Closes: 738963, 738872, 738867)
* Scrub the environment when switching to the debian-spamd user in
  postinst and cron.daily. (Closes: 738951)
* Enhancements to postinst to better manage ownership of
  /var/lib/spamassassin, via Iain Lane <iain.lane@canonical.com>
  (Closes: 738974)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package Mail::SpamAssassin::Plugin::FreeMail;
2
 
my $VERSION = 2.001;
 
2
use strict;
 
3
my $VERSION = 2.002;
3
4
 
4
5
### About:
5
6
#
80
81
# 1.999 - default whitelist undisclosed-recipient@yahoo.com etc
81
82
# 2.000 - some cleaning up
82
83
# 2.001 - fix freemail_whitelist
 
84
# 2.002 - _add_desc -> _got_hit, fix description email append bug
83
85
#
84
86
 
85
87
### Blah:
108
110
use Mail::SpamAssassin::Plugin;
109
111
use Mail::SpamAssassin::PerMsgStatus;
110
112
use Mail::SpamAssassin::Util::RegistrarBoundaries;
111
 
use strict;
112
113
use vars qw(@ISA);
113
114
@ISA = qw(Mail::SpamAssassin::Plugin);
114
115
 
120
121
# full email regex
121
122
my $email_regex = qr/
122
123
  (?=.{0,64}\@)                         # limit userpart to 64 chars (and speed up searching?)
123
 
  (?<![a-z0-9!#$%&'*+\/=?^_`{|}~-])     # start boundary
 
124
  (?<![a-z0-9!#\$%&'*+\/=?^_`{|}~-])    # start boundary
124
125
  (                                     # capture email
125
 
  [a-z0-9!#$%&'*+\/=?^_`{|}~-]+         # no dot in beginning
126
 
  (?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*  # no consecutive dots, no ending dot
 
126
  [a-z0-9!#\$%&'*+\/=?^_`{|}~-]+        # no dot in beginning
 
127
  (?:\.[a-z0-9!#\$%&'*+\/=?^_`{|}~-]+)* # no consecutive dots, no ending dot
127
128
  \@
128
129
  (?:[a-z0-9](?:[a-z0-9-]{0,59}[a-z0-9])?\.){1,4} # max 4x61 char parts (should be enough?)
129
130
  ${tlds}                               # ends with valid tld
178
179
 
179
180
sub set_config {
180
181
    my ($self, $conf) = @_;
181
 
    my @cmds = ();
 
182
    my @cmds;
182
183
    push(@cmds, {
183
184
        setting => 'freemail_max_body_emails',
184
185
        default => 5,
328
329
        my $parsed = $pms->get_uri_detail_list();
329
330
        while (my($uri, $info) = each %{$parsed}) {
330
331
            if (defined $info->{types}->{a} and not defined $info->{types}->{parsed}) {
331
 
                if ($uri =~ /^mailto:${email_regex}/) {
 
332
                if ($uri =~ /^(?:(?i)mailto):${email_regex}/) {
332
333
                    my $email = lc($1);
333
334
                    push(@body_emails, $email) unless defined $seen{$email};
334
335
                    $seen{$email} = 1;
384
385
    return 1;
385
386
}
386
387
 
387
 
sub _add_desc {
 
388
sub _got_hit {
388
389
    my ($self, $pms, $email, $desc) = @_;
389
390
 
390
391
    my $rulename = $pms->get_current_eval_rule_name();
391
 
    if (not defined $pms->{conf}->{descriptions}->{$rulename}) {
392
 
        $pms->{conf}->{descriptions}->{$rulename} = $desc;
 
392
 
 
393
    if (defined $pms->{conf}->{descriptions}->{$rulename}) {
 
394
        $desc = $pms->{conf}->{descriptions}->{$rulename};
393
395
    }
 
396
 
394
397
    if ($pms->{main}->{conf}->{freemail_add_describe_email}) {
395
398
        $email =~ s/\@/[at]/g;
396
 
        $pms->{conf}->{descriptions}->{$rulename} .= " ($email)";
 
399
        $pms->got_hit($rulename, "", description => $desc." ($email)", ruletype => 'eval');
 
400
    }
 
401
    else {
 
402
        $pms->got_hit($rulename, "", description => $desc, ruletype => 'eval');
397
403
    }
398
404
}
399
405
 
419
425
        }
420
426
    }
421
427
 
422
 
    my $email = lc($pms->get(index($header,':') ? $header : $header.":addr"));
 
428
    my $email = lc($pms->get(index($header,':') >= 0 ? $header : $header.":addr"));
423
429
 
424
430
    if ($email eq '') {
425
431
        dbg("header $header not found from mail");
435
441
        else {
436
442
            dbg("HIT! $email is freemail");
437
443
        }
438
 
        $self->_add_desc($pms, $email, "Header $header is freemail");
439
 
        return 1;
 
444
        $self->_got_hit($pms, $email, "Header $header is freemail");
 
445
        return 0;
440
446
    }
441
447
 
442
448
    return 0;
465
471
        foreach my $email (keys %{$pms->{freemail_cache}{body}}) {
466
472
            if ($email =~ $re) {
467
473
                dbg("HIT! email from body is freemail and matches regex: $email");
468
 
                $self->_add_desc($pms, $email, "Email from body is freemail");
469
 
                return 1;
 
474
                $self->_got_hit($pms, $email, "Email from body is freemail");
 
475
                return 0;
470
476
            }
471
477
        }
472
478
    }
473
479
    elsif (scalar keys %{$pms->{freemail_cache}{body}}) {
474
480
        my $emails = join(', ', keys %{$pms->{freemail_cache}{body}});
475
481
        dbg("HIT! body has freemails: $emails");
476
 
        $self->_add_desc($pms, $emails, "Body contains freemails");
477
 
        return 1;
 
482
        $self->_got_hit($pms, $emails, "Body contains freemails");
 
483
        return 0;
478
484
    }
479
485
 
480
486
    return 0;
516
522
        else {
517
523
            dbg("HIT! $email is freemail");
518
524
        }
519
 
        $self->_add_desc($pms, $email, "Sender address is freemail");
520
 
        return 1;
 
525
        $self->_got_hit($pms, $email, "Sender address is freemail");
 
526
        return 0;
521
527
    }
522
528
 
523
529
    return 0;
560
566
 
561
567
    if ($from_is_fm and $replyto_is_fm and ($from ne $replyto)) {
562
568
        dbg("HIT! From and Reply-To are different freemails");
563
 
        $self->_add_desc($pms, "$from, $replyto", "From and Reply-To are different freemails");
564
 
        return 1;
 
569
        $self->_got_hit($pms, "$from, $replyto", "From and Reply-To are different freemails");
 
570
        return 0;
565
571
    }
566
572
 
567
573
    if ($what eq 'replyto') {
591
597
        foreach my $email (keys %{$pms->{freemail_cache}{body}}) {
592
598
            if ($email ne $check) {
593
599
                dbg("HIT! $check and $email are different freemails");
594
 
                $self->_add_desc($pms, "$check, $email", "Different freemails in reply header and body");
595
 
                return 1;
 
600
                $self->_got_hit($pms, "$check, $email", "Different freemails in reply header and body");
 
601
                return 0;
596
602
            }
597
603
        }
598
604
    }