| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# <@LICENSE> |
|
2
|
|
|
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more |
|
3
|
|
|
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
|
4
|
|
|
|
|
|
|
# this work for additional information regarding copyright ownership. |
|
5
|
|
|
|
|
|
|
# The ASF licenses this file to you under the Apache License, Version 2.0 |
|
6
|
|
|
|
|
|
|
# (the "License"); you may not use this file except in compliance with |
|
7
|
|
|
|
|
|
|
# the License. You may obtain a copy of the License at: |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
|
|
|
|
# |
|
11
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
|
|
|
|
# See the License for the specific language governing permissions and |
|
15
|
|
|
|
|
|
|
# limitations under the License. |
|
16
|
|
|
|
|
|
|
# </@LICENSE> |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Mail::SpamAssassin::Message::Metadata - extract metadata from a message |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This class is tasked with extracting "metadata" from messages for use as |
|
25
|
|
|
|
|
|
|
Bayes tokens, fodder for eval tests, or other rules. Metadata is |
|
26
|
|
|
|
|
|
|
supplemental data inferred from the message, like the examples below. |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
It is held in two forms: |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
1. as name-value pairs of strings, presented in mail header format. For |
|
31
|
|
|
|
|
|
|
example, "X-Languages" => "en". This is the general form for simple |
|
32
|
|
|
|
|
|
|
metadata that's useful as Bayes tokens, can be added to marked-up |
|
33
|
|
|
|
|
|
|
messages using "add_header", etc., such as the trusted-relay inference |
|
34
|
|
|
|
|
|
|
and language detection. |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
2. as more complex data structures on the $msg->{metadata} object. This |
|
37
|
|
|
|
|
|
|
is the form used for metadata like the HTML parse data, which is stored |
|
38
|
|
|
|
|
|
|
there for access by eval rule code. Because it's not simple strings, |
|
39
|
|
|
|
|
|
|
it's not added as a Bayes token by default (Bayes needs simple strings). |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 PUBLIC METHODS |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=over 4 |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
use strict; |
|
49
|
41
|
|
|
41
|
|
262
|
use warnings; |
|
|
41
|
|
|
|
|
73
|
|
|
|
41
|
|
|
|
|
1197
|
|
|
50
|
41
|
|
|
41
|
|
214
|
# use bytes; |
|
|
41
|
|
|
|
|
85
|
|
|
|
41
|
|
|
|
|
1395
|
|
|
51
|
|
|
|
|
|
|
use re 'taint'; |
|
52
|
41
|
|
|
41
|
|
222
|
|
|
|
41
|
|
|
|
|
93
|
|
|
|
41
|
|
|
|
|
1491
|
|
|
53
|
|
|
|
|
|
|
use Mail::SpamAssassin; |
|
54
|
41
|
|
|
41
|
|
273
|
use Mail::SpamAssassin::Constants qw(:sa); |
|
|
41
|
|
|
|
|
98
|
|
|
|
41
|
|
|
|
|
1071
|
|
|
55
|
41
|
|
|
41
|
|
208
|
use Mail::SpamAssassin::Util qw(reverse_ip_address); |
|
|
41
|
|
|
|
|
109
|
|
|
|
41
|
|
|
|
|
6414
|
|
|
56
|
41
|
|
|
41
|
|
269
|
use Mail::SpamAssassin::Message::Metadata::Received; |
|
|
41
|
|
|
|
|
74
|
|
|
|
41
|
|
|
|
|
1910
|
|
|
57
|
41
|
|
|
41
|
|
11937
|
use Mail::SpamAssassin::Logger; |
|
|
41
|
|
|
|
|
194
|
|
|
|
41
|
|
|
|
|
3303
|
|
|
58
|
41
|
|
|
41
|
|
444
|
|
|
|
41
|
|
|
|
|
455
|
|
|
|
41
|
|
|
|
|
13871
|
|
|
59
|
|
|
|
|
|
|
=item new() |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=back |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my ($class, $msg) = @_; |
|
66
|
|
|
|
|
|
|
$class = ref($class) || $class; |
|
67
|
150
|
|
|
150
|
1
|
488
|
|
|
68
|
150
|
|
33
|
|
|
679
|
my $self = { |
|
69
|
|
|
|
|
|
|
msg => $msg, |
|
70
|
150
|
|
|
|
|
777
|
strings => { } |
|
71
|
|
|
|
|
|
|
}; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
bless($self,$class); |
|
74
|
|
|
|
|
|
|
$self; |
|
75
|
150
|
|
|
|
|
425
|
} |
|
76
|
150
|
|
|
|
|
572
|
|
|
77
|
|
|
|
|
|
|
my ($self, $msg, $permsgstatus) = @_; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# pre-chew Received headers |
|
80
|
102
|
|
|
102
|
0
|
273
|
$self->parse_received_headers ($permsgstatus, $msg); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
foreach my $tuple ( |
|
83
|
102
|
|
|
|
|
698
|
[$self->{relays_trusted}, 'RELAYSTRUSTEDREVIP' ], |
|
84
|
|
|
|
|
|
|
[$self->{relays_untrusted}, 'RELAYSUNTRUSTEDREVIP'], |
|
85
|
102
|
|
|
|
|
958
|
[$self->{relays_internal}, 'RELAYSINTERNALREVIP' ], |
|
86
|
|
|
|
|
|
|
[$self->{relays_external}, 'RELAYSEXTERNALREVIP' ]) |
|
87
|
|
|
|
|
|
|
{ my($rly, $tag) = @$tuple; |
|
88
|
|
|
|
|
|
|
my @revips; |
|
89
|
|
|
|
|
|
|
@revips = map { |
|
90
|
408
|
|
|
|
|
725
|
my($ip,$revip); |
|
91
|
408
|
|
|
|
|
492
|
$ip = $_->{ip} if ref $_ && !$_->{ip_private}; |
|
92
|
|
|
|
|
|
|
$revip = reverse_ip_address($ip) if defined $ip && $ip ne ''; |
|
93
|
408
|
50
|
|
|
|
830
|
defined $revip && $revip ne '' ? $revip : (); |
|
|
130
|
|
|
|
|
192
|
|
|
94
|
130
|
100
|
66
|
|
|
586
|
} @$rly if $rly; |
|
95
|
130
|
100
|
66
|
|
|
741
|
$permsgstatus->set_tag($tag, |
|
96
|
130
|
100
|
66
|
|
|
771
|
@revips == 1 ? $revips[0] : \@revips) if @revips; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
408
|
100
|
|
|
|
1203
|
|
|
|
|
100
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$permsgstatus->{main}->call_plugins("extract_metadata", |
|
100
|
|
|
|
|
|
|
{ msg => $msg, permsgstatus => $permsgstatus, |
|
101
|
|
|
|
|
|
|
conf => $permsgstatus->{main}->{conf} }); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
102
|
|
|
|
|
1023
|
my ($self) = @_; |
|
105
|
|
|
|
|
|
|
%{$self} = (); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
128
|
|
|
128
|
0
|
257
|
1; |