-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecipientMsgID.pm
More file actions
91 lines (67 loc) · 1.79 KB
/
Copy pathRecipientMsgID.pm
File metadata and controls
91 lines (67 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package Mail::SpamAssassin::Plugin::RecipientMsgID;
my $VERSION = 0.23;
use strict;
use Mail::SpamAssassin::Plugin;
use vars qw(@ISA);
@ISA = qw(Mail::SpamAssassin::Plugin);
sub dbg {
Mail::SpamAssassin::Plugin::dbg ("RecipientMsgID: @_");
}
sub uri_to_domain {
my ($self, $domain) = @_;
if ($Mail::SpamAssassin::VERSION <= 3.004000) {
Mail::SpamAssassin::Util::uri_to_domain($domain);
} else {
$self->{main}->{registryboundaries}->uri_to_domain($domain);
}
}
sub new {
my ($class, $mailsa) = @_;
$class = ref($class) || $class;
my $self = $class->SUPER::new($mailsa);
bless ($self, $class);
$self->register_eval_rule("check_msgid_belongs_recipient");
return $self;
}
sub check_msgid_belongs_recipient {
my ($self, $pms) = @_;
my $message_id = lc($pms->get("Message-Id"));
chomp $message_id;
$message_id =~ s/\>$//;
if (defined $message_id) {
$message_id = $self->uri_to_domain($message_id);
}
return 0 unless defined $message_id;
dbg("Message-Id: $message_id");
my $from = lc($pms->get("From:addr"));
my $replyto = lc($pms->get("Reply-To:addr"));
my $from_dom = '';
$from_dom = $self->uri_to_domain($from);
if ($replyto) {
$from_dom = $self->uri_to_domain($replyto);
}
return 0 unless defined $from_dom;
dbg("FromDom: $from_dom");
my $matched = 0;
my @toaddrs;
for ('ToCc', 'Bcc') {
my $to = $pms->get($_ . ":addr"); # get recipients
if ($to) {
$to = $self->uri_to_domain($to);
next unless defined $to;
dbg("ToDom: $to");
push(@toaddrs, $to);
}
}
foreach my $to_domain (@toaddrs) {
if ($to_domain eq $message_id) {
$matched = 1;
}
}
if (($from_dom ne $message_id) && ($matched == 1)) {
dbg("Message ID matches recipient domain");
return 1;
}
return 0;
}
1;