line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::DKIM::Common; |
2
|
12
|
|
|
12
|
|
105
|
use strict; |
|
12
|
|
|
|
|
25
|
|
|
12
|
|
|
|
|
387
|
|
3
|
12
|
|
|
12
|
|
59
|
use warnings; |
|
12
|
|
|
|
|
24
|
|
|
12
|
|
|
|
|
485
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.20230911'; # VERSION |
5
|
|
|
|
|
|
|
# ABSTRACT: Common class for Mail::DKIM |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Copyright 2005-2007 Messiah College. All rights reserved. |
8
|
|
|
|
|
|
|
# Jason Long |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Copyright (c) 2004 Anthony D. Urso. All rights reserved. |
11
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
12
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
13
|
|
|
|
|
|
|
|
14
|
12
|
|
|
12
|
|
3808
|
use Mail::Address; |
|
12
|
|
|
|
|
20111
|
|
|
12
|
|
|
|
|
393
|
|
15
|
|
|
|
|
|
|
|
16
|
12
|
|
|
12
|
|
73
|
use base 'Mail::DKIM::MessageParser'; |
|
12
|
|
|
|
|
25
|
|
|
12
|
|
|
|
|
1186
|
|
17
|
12
|
|
|
12
|
|
79
|
use Carp; |
|
12
|
|
|
|
|
24
|
|
|
12
|
|
|
|
|
13744
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
295
|
|
|
295
|
0
|
187999
|
my $class = shift; |
21
|
295
|
|
|
|
|
1210
|
return $class->new_object(@_); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub add_header { |
25
|
3386
|
|
|
3386
|
0
|
4657
|
my $self = shift; |
26
|
3386
|
|
|
|
|
5347
|
my ($line) = @_; |
27
|
|
|
|
|
|
|
|
28
|
3386
|
|
|
|
|
4254
|
foreach my $algorithm ( @{ $self->{algorithms} } ) { |
|
3386
|
|
|
|
|
6859
|
|
29
|
4441
|
|
|
|
|
8546
|
$algorithm->add_header($line); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
3386
|
100
|
|
|
|
16005
|
if ( $line =~ /^([^:]+?)\s*:(.*)/s ) { |
33
|
3384
|
|
|
|
|
8955
|
my $field_name = lc $1; |
34
|
3384
|
|
|
|
|
6076
|
my $contents = $2; |
35
|
3384
|
|
|
|
|
7322
|
$self->handle_header( $field_name, $contents, $line ); |
36
|
|
|
|
|
|
|
} |
37
|
3386
|
|
|
|
|
4391
|
push @{ $self->{headers} }, $line; |
|
3386
|
|
|
|
|
8067
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub add_body { |
41
|
287
|
|
|
287
|
0
|
470
|
my $self = shift; |
42
|
287
|
50
|
|
|
|
729
|
if ( $self->{algorithm} ) { |
43
|
0
|
|
|
|
|
0
|
$self->{algorithm}->add_body(@_); |
44
|
|
|
|
|
|
|
} |
45
|
287
|
|
|
|
|
398
|
foreach my $algorithm ( @{ $self->{algorithms} } ) { |
|
287
|
|
|
|
|
634
|
|
46
|
458
|
|
|
|
|
1128
|
$algorithm->add_body(@_); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub handle_header { |
51
|
3384
|
|
|
3384
|
0
|
4887
|
my $self = shift; |
52
|
3384
|
|
|
|
|
5709
|
my ( $field_name, $contents, $line ) = @_; |
53
|
|
|
|
|
|
|
|
54
|
3384
|
|
|
|
|
4679
|
push @{ $self->{header_field_names} }, $field_name; |
|
3384
|
|
|
|
|
6991
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# TODO - detect multiple occurrences of From: or Sender: |
57
|
|
|
|
|
|
|
# header and reject them |
58
|
|
|
|
|
|
|
|
59
|
3384
|
|
|
|
|
9535
|
$self->{headers_by_name}->{$field_name} = $contents; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub init { |
63
|
296
|
|
|
296
|
0
|
464
|
my $self = shift; |
64
|
296
|
|
|
|
|
936
|
$self->SUPER::init(@_); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
#initialize variables |
67
|
296
|
|
|
|
|
714
|
$self->{headers} = []; |
68
|
296
|
|
|
|
|
616
|
$self->{headers_by_name} = {}; |
69
|
296
|
|
|
|
|
673
|
$self->{header_field_names} = []; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub load { |
73
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
74
|
0
|
|
|
|
|
0
|
my ($fh) = @_; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
while (<$fh>) { |
77
|
0
|
|
|
|
|
0
|
$self->PRINT($_); |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
0
|
$self->CLOSE; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub message_attributes { |
83
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
84
|
0
|
|
|
|
|
0
|
my @attributes; |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
0
|
if ( my $message_id = $self->message_id ) { |
87
|
0
|
|
|
|
|
0
|
push @attributes, "message-id=<$message_id>"; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
0
|
if ( my $sig = $self->signature ) { |
91
|
0
|
|
|
|
|
0
|
push @attributes, 'signer=<' . $sig->identity . '>'; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
0
|
|
|
|
0
|
if ( $self->{headers_by_name}->{sender} ) { |
|
|
0
|
|
|
|
|
|
95
|
0
|
|
|
|
|
0
|
my @list = Mail::Address->parse( $self->{headers_by_name}->{sender} ); |
96
|
0
|
0
|
|
|
|
0
|
if ( $list[0] ) { |
97
|
0
|
|
|
|
|
0
|
push @attributes, 'sender=<' . $list[0]->address . '>'; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
elsif ( $self->{headers_by_name}->{from} ) { |
101
|
0
|
|
|
|
|
0
|
my @list = Mail::Address->parse( $self->{headers_by_name}->{from} ); |
102
|
0
|
0
|
|
|
|
0
|
if ( $list[0] ) { |
103
|
0
|
|
|
|
|
0
|
push @attributes, 'from=<' . $list[0]->address . '>'; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
0
|
return @attributes; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub message_id { |
111
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
112
|
0
|
0
|
|
|
|
0
|
croak 'wrong number of arguments' unless ( @_ == 0 ); |
113
|
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
0
|
if ( my $message_id = $self->{headers_by_name}->{'message-id'} ) { |
115
|
0
|
0
|
|
|
|
0
|
if ( $message_id =~ /^\s*<(.*)>\s*$/ ) { |
116
|
0
|
|
|
|
|
0
|
return $1; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
0
|
|
|
|
|
0
|
return undef; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub message_originator { |
123
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
124
|
0
|
0
|
|
|
|
0
|
croak 'wrong number of arguments' unless ( @_ == 0 ); |
125
|
|
|
|
|
|
|
|
126
|
0
|
0
|
|
|
|
0
|
if ( $self->{headers_by_name}->{from} ) { |
127
|
0
|
|
|
|
|
0
|
my @list = Mail::Address->parse( $self->{headers_by_name}->{from} ); |
128
|
0
|
0
|
|
|
|
0
|
return $list[0] if @list; |
129
|
|
|
|
|
|
|
} |
130
|
0
|
|
|
|
|
0
|
return Mail::Address->new; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub message_sender { |
134
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
135
|
0
|
0
|
|
|
|
0
|
croak 'wrong number of arguments' unless ( @_ == 0 ); |
136
|
|
|
|
|
|
|
|
137
|
0
|
0
|
|
|
|
0
|
if ( $self->{headers_by_name}->{sender} ) { |
138
|
0
|
|
|
|
|
0
|
my @list = Mail::Address->parse( $self->{headers_by_name}->{sender} ); |
139
|
0
|
0
|
|
|
|
0
|
return $list[0] if @list; |
140
|
|
|
|
|
|
|
} |
141
|
0
|
0
|
|
|
|
0
|
if ( $self->{headers_by_name}->{from} ) { |
142
|
0
|
|
|
|
|
0
|
my @list = Mail::Address->parse( $self->{headers_by_name}->{from} ); |
143
|
0
|
0
|
|
|
|
0
|
return $list[0] if @list; |
144
|
|
|
|
|
|
|
} |
145
|
0
|
|
|
|
|
0
|
return Mail::Address->new; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub result { |
149
|
253
|
|
|
253
|
0
|
1044
|
my $self = shift; |
150
|
253
|
50
|
|
|
|
588
|
croak 'wrong number of arguments' unless ( @_ == 0 ); |
151
|
253
|
|
|
|
|
583
|
return $self->{result}; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub result_detail { |
155
|
100
|
|
|
100
|
0
|
307
|
my $self = shift; |
156
|
100
|
50
|
|
|
|
234
|
croak 'wrong number of arguments' unless ( @_ == 0 ); |
157
|
|
|
|
|
|
|
|
158
|
100
|
100
|
|
|
|
195
|
if ( $self->{details} ) { |
159
|
63
|
|
|
|
|
1788
|
return $self->{result} . ' (' . $self->{details} . ')'; |
160
|
|
|
|
|
|
|
} |
161
|
37
|
|
|
|
|
1592
|
return $self->{result}; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub signature { |
165
|
27
|
|
|
27
|
0
|
3625
|
my $self = shift; |
166
|
27
|
50
|
|
|
|
82
|
croak 'wrong number of arguments' unless ( @_ == 0 ); |
167
|
27
|
|
|
|
|
167
|
return $self->{signature}; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
__END__ |