line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::DKIM::Common; |
2
|
12
|
|
|
12
|
|
106
|
use strict; |
|
12
|
|
|
|
|
29
|
|
|
12
|
|
|
|
|
349
|
|
3
|
12
|
|
|
12
|
|
64
|
use warnings; |
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
473
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.20230212'; # 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
|
|
3534
|
use Mail::Address; |
|
12
|
|
|
|
|
19204
|
|
|
12
|
|
|
|
|
391
|
|
15
|
|
|
|
|
|
|
|
16
|
12
|
|
|
12
|
|
82
|
use base 'Mail::DKIM::MessageParser'; |
|
12
|
|
|
|
|
25
|
|
|
12
|
|
|
|
|
1213
|
|
17
|
12
|
|
|
12
|
|
82
|
use Carp; |
|
12
|
|
|
|
|
35
|
|
|
12
|
|
|
|
|
13330
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
287
|
|
|
287
|
0
|
182662
|
my $class = shift; |
21
|
287
|
|
|
|
|
1046
|
return $class->new_object(@_); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub add_header { |
25
|
3326
|
|
|
3326
|
0
|
4747
|
my $self = shift; |
26
|
3326
|
|
|
|
|
5428
|
my ($line) = @_; |
27
|
|
|
|
|
|
|
|
28
|
3326
|
|
|
|
|
4398
|
foreach my $algorithm ( @{ $self->{algorithms} } ) { |
|
3326
|
|
|
|
|
6609
|
|
29
|
4393
|
|
|
|
|
7894
|
$algorithm->add_header($line); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
3326
|
100
|
|
|
|
15462
|
if ( $line =~ /^([^:]+?)\s*:(.*)/s ) { |
33
|
3324
|
|
|
|
|
7825
|
my $field_name = lc $1; |
34
|
3324
|
|
|
|
|
6109
|
my $contents = $2; |
35
|
3324
|
|
|
|
|
7161
|
$self->handle_header( $field_name, $contents, $line ); |
36
|
|
|
|
|
|
|
} |
37
|
3326
|
|
|
|
|
4487
|
push @{ $self->{headers} }, $line; |
|
3326
|
|
|
|
|
7815
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub add_body { |
41
|
279
|
|
|
279
|
0
|
451
|
my $self = shift; |
42
|
279
|
50
|
|
|
|
648
|
if ( $self->{algorithm} ) { |
43
|
0
|
|
|
|
|
0
|
$self->{algorithm}->add_body(@_); |
44
|
|
|
|
|
|
|
} |
45
|
279
|
|
|
|
|
456
|
foreach my $algorithm ( @{ $self->{algorithms} } ) { |
|
279
|
|
|
|
|
643
|
|
46
|
450
|
|
|
|
|
1028
|
$algorithm->add_body(@_); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub handle_header { |
51
|
3324
|
|
|
3324
|
0
|
4391
|
my $self = shift; |
52
|
3324
|
|
|
|
|
5586
|
my ( $field_name, $contents, $line ) = @_; |
53
|
|
|
|
|
|
|
|
54
|
3324
|
|
|
|
|
4283
|
push @{ $self->{header_field_names} }, $field_name; |
|
3324
|
|
|
|
|
7405
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# TODO - detect multiple occurrences of From: or Sender: |
57
|
|
|
|
|
|
|
# header and reject them |
58
|
|
|
|
|
|
|
|
59
|
3324
|
|
|
|
|
9289
|
$self->{headers_by_name}->{$field_name} = $contents; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub init { |
63
|
288
|
|
|
288
|
0
|
562
|
my $self = shift; |
64
|
288
|
|
|
|
|
913
|
$self->SUPER::init(@_); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
#initialize variables |
67
|
288
|
|
|
|
|
635
|
$self->{headers} = []; |
68
|
288
|
|
|
|
|
608
|
$self->{headers_by_name} = {}; |
69
|
288
|
|
|
|
|
656
|
$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
|
247
|
|
|
247
|
0
|
1018
|
my $self = shift; |
150
|
247
|
50
|
|
|
|
648
|
croak 'wrong number of arguments' unless ( @_ == 0 ); |
151
|
247
|
|
|
|
|
595
|
return $self->{result}; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub result_detail { |
155
|
94
|
|
|
94
|
0
|
303
|
my $self = shift; |
156
|
94
|
50
|
|
|
|
194
|
croak 'wrong number of arguments' unless ( @_ == 0 ); |
157
|
|
|
|
|
|
|
|
158
|
94
|
100
|
|
|
|
209
|
if ( $self->{details} ) { |
159
|
58
|
|
|
|
|
4625
|
return $self->{result} . ' (' . $self->{details} . ')'; |
160
|
|
|
|
|
|
|
} |
161
|
36
|
|
|
|
|
4840
|
return $self->{result}; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub signature { |
165
|
25
|
|
|
25
|
0
|
2474
|
my $self = shift; |
166
|
25
|
50
|
|
|
|
76
|
croak 'wrong number of arguments' unless ( @_ == 0 ); |
167
|
25
|
|
|
|
|
161
|
return $self->{signature}; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
__END__ |