line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::DKIM::MessageParser; |
2
|
14
|
|
|
14
|
|
108
|
use strict; |
|
14
|
|
|
|
|
33
|
|
|
14
|
|
|
|
|
377
|
|
3
|
14
|
|
|
14
|
|
73
|
use warnings; |
|
14
|
|
|
|
|
32
|
|
|
14
|
|
|
|
|
663
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.20230212'; # VERSION |
5
|
|
|
|
|
|
|
# ABSTRACT: Signs/verifies Internet mail with DKIM/DomainKey signatures |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Copyright 2005 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
|
14
|
|
|
14
|
|
100
|
use Carp; |
|
14
|
|
|
|
|
34
|
|
|
14
|
|
|
|
|
11349
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new_object { |
17
|
1214
|
|
|
1214
|
0
|
2895
|
my $class = shift; |
18
|
1214
|
|
|
|
|
2546
|
return $class->TIEHANDLE(@_); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new_handle { |
22
|
0
|
|
|
0
|
0
|
0
|
my $class = shift; |
23
|
0
|
|
|
|
|
0
|
local *TMP; |
24
|
0
|
|
|
|
|
0
|
tie *TMP, $class, @_; |
25
|
0
|
|
|
|
|
0
|
return *TMP; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub TIEHANDLE { |
29
|
1214
|
|
|
1214
|
|
1726
|
my $class = shift; |
30
|
1214
|
|
|
|
|
3465
|
my %args = @_; |
31
|
1214
|
|
|
|
|
2522
|
my $self = bless \%args, $class; |
32
|
1214
|
|
|
|
|
3857
|
$self->init; |
33
|
1212
|
|
|
|
|
5120
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub init { |
37
|
1214
|
|
|
1214
|
0
|
1646
|
my $self = shift; |
38
|
|
|
|
|
|
|
|
39
|
1214
|
|
|
|
|
1797
|
my $buf = ''; |
40
|
1214
|
|
|
|
|
2280
|
$self->{buf_ref} = \$buf; |
41
|
1214
|
|
|
|
|
2735
|
$self->{in_header} = 1; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub PRINT { |
45
|
285
|
|
|
285
|
|
19906
|
my $self = shift; |
46
|
285
|
|
|
|
|
585
|
my $buf_ref = $self->{buf_ref}; |
47
|
285
|
50
|
|
|
|
1724
|
$$buf_ref .= @_ == 1 ? $_[0] : join( '', @_ ) if @_; |
|
|
50
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
285
|
50
|
|
|
|
732
|
if ( $self->{in_header} ) { |
50
|
285
|
|
|
|
|
923
|
local $1; # avoid polluting a global $1 |
51
|
285
|
|
|
|
|
746
|
while ( $$buf_ref ne '' ) { |
52
|
3606
|
100
|
|
|
|
7845
|
if ( substr( $$buf_ref, 0, 2 ) eq "\015\012" ) { |
53
|
280
|
|
|
|
|
530
|
substr( $$buf_ref, 0, 2 ) = ''; |
54
|
280
|
|
|
|
|
925
|
$self->finish_header(); |
55
|
280
|
|
|
|
|
554
|
$self->{in_header} = 0; |
56
|
280
|
|
|
|
|
921
|
last; |
57
|
|
|
|
|
|
|
} |
58
|
3326
|
100
|
|
|
|
13856
|
if ( $$buf_ref !~ /^(.+?\015\012)[^\ \t]/s ) { |
59
|
4
|
|
|
|
|
17
|
last; |
60
|
|
|
|
|
|
|
} |
61
|
3322
|
|
|
|
|
8105
|
my $header = $1; |
62
|
3322
|
|
|
|
|
8843
|
$self->add_header($header); |
63
|
3322
|
|
|
|
|
10089
|
substr( $$buf_ref, 0, length($header) ) = ''; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
285
|
100
|
|
|
|
711
|
if ( !$self->{in_header} ) { |
68
|
280
|
|
|
|
|
661
|
my $j = rindex( $$buf_ref, "\015\012" ); |
69
|
280
|
100
|
|
|
|
660
|
if ( $j >= 0 ) { |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# avoid copying a large buffer: the unterminated |
72
|
|
|
|
|
|
|
# last line is typically short compared to the rest |
73
|
|
|
|
|
|
|
|
74
|
279
|
|
|
|
|
649
|
my $carry = substr( $$buf_ref, $j + 2 ); |
75
|
279
|
|
|
|
|
647
|
substr( $$buf_ref, $j + 2 ) = ''; # shrink to last CRLF |
76
|
279
|
|
|
|
|
991
|
$self->add_body($$buf_ref); # must end on CRLF |
77
|
279
|
|
|
|
|
588
|
$$buf_ref = $carry; # restore unterminated last line |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
285
|
|
|
|
|
659
|
return 1; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub CLOSE { |
84
|
285
|
|
|
285
|
|
1140
|
my $self = shift; |
85
|
285
|
|
|
|
|
565
|
my $buf_ref = $self->{buf_ref}; |
86
|
|
|
|
|
|
|
|
87
|
285
|
100
|
|
|
|
662
|
if ( $self->{in_header} ) { |
88
|
5
|
100
|
|
|
|
26
|
if ( $$buf_ref ne '' ) { |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# A line of header text ending CRLF would not have been |
91
|
|
|
|
|
|
|
# processed yet since before we couldn't tell if it was |
92
|
|
|
|
|
|
|
# the complete header. Now that we're in CLOSE, we can |
93
|
|
|
|
|
|
|
# finish the header... |
94
|
4
|
|
|
|
|
21
|
$$buf_ref =~ s/\015\012\z//s; |
95
|
4
|
|
|
|
|
26
|
$self->add_header("$$buf_ref\015\012"); |
96
|
|
|
|
|
|
|
} |
97
|
5
|
|
|
|
|
35
|
$self->finish_header; |
98
|
5
|
|
|
|
|
13
|
$self->{in_header} = 0; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
280
|
50
|
|
|
|
680
|
if ( $$buf_ref ne '' ) { |
102
|
0
|
|
|
|
|
0
|
$self->add_body($$buf_ref); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
285
|
|
|
|
|
455
|
$$buf_ref = ''; |
106
|
285
|
|
|
|
|
942
|
$self->finish_body; |
107
|
285
|
|
|
|
|
685
|
return 1; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub add_header { |
111
|
0
|
|
|
0
|
0
|
|
die 'add_header not implemented'; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub finish_header { |
115
|
0
|
|
|
0
|
0
|
|
die 'finish_header not implemented'; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub add_body { |
119
|
0
|
|
|
0
|
0
|
|
die 'add_body not implemented'; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
0
|
0
|
|
sub finish_body { |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# do nothing by default |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub reset { |
128
|
0
|
|
|
0
|
0
|
|
carp 'reset not implemented'; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |