line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Action::Request; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
70
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
69
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
12
|
use vars '$VERSION'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
103
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.46'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
925
|
use Email::MIME; |
|
2
|
|
|
|
|
85281
|
|
|
2
|
|
|
|
|
56
|
|
10
|
2
|
|
|
2
|
|
17
|
use Email::Address; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
49
|
|
11
|
2
|
|
|
2
|
|
12
|
use Email::MIME::Modifier; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
388
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new |
14
|
|
|
|
|
|
|
{ |
15
|
26
|
|
|
26
|
1
|
68
|
my ($class, $message_text, @args) = @_; |
16
|
26
|
|
|
|
|
145
|
my $message = Email::MIME->new( $message_text ); |
17
|
26
|
|
|
|
|
14884
|
my $self = bless |
18
|
|
|
|
|
|
|
{ |
19
|
|
|
|
|
|
|
Message => $message, |
20
|
|
|
|
|
|
|
headers => {}, |
21
|
|
|
|
|
|
|
recipient => '', |
22
|
|
|
|
|
|
|
@args, |
23
|
|
|
|
|
|
|
}, $class; |
24
|
|
|
|
|
|
|
|
25
|
26
|
|
|
|
|
101
|
$self->init(); |
26
|
|
|
|
|
|
|
|
27
|
26
|
|
|
|
|
520
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub init |
31
|
|
|
|
|
|
|
{ |
32
|
26
|
|
|
26
|
1
|
52
|
my $self = shift; |
33
|
26
|
|
|
|
|
86
|
$self->add_headers(); |
34
|
26
|
|
|
|
|
108
|
$self->add_recipient(); |
35
|
26
|
|
|
|
|
80
|
$self->remove_recipient( $self->recipient_header(), $self->recipient() ); |
36
|
26
|
|
|
|
|
84
|
$self->find_key(); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub message |
40
|
|
|
|
|
|
|
{ |
41
|
89
|
|
|
89
|
1
|
129
|
my $self = shift; |
42
|
89
|
|
|
|
|
260
|
$self->{Message}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub headers |
46
|
|
|
|
|
|
|
{ |
47
|
250
|
|
|
250
|
1
|
329
|
my $self = shift; |
48
|
250
|
|
|
|
|
538
|
$self->{headers}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
BEGIN |
52
|
|
|
|
|
|
|
{ |
53
|
2
|
|
|
2
|
|
16
|
no strict 'refs'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
146
|
|
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
2
|
|
6
|
for my $attribute (qw( key recipient recipient_header )) |
56
|
|
|
|
|
|
|
{ |
57
|
6
|
|
|
|
|
1015
|
*{ $attribute } = sub |
58
|
|
|
|
|
|
|
{ |
59
|
160
|
|
|
160
|
|
1910
|
my $self = shift; |
60
|
160
|
100
|
|
|
|
470
|
$self->{$attribute} = shift if @_; |
61
|
160
|
|
|
|
|
617
|
$self->{$attribute}; |
62
|
6
|
|
|
|
|
47
|
}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub store_header |
67
|
|
|
|
|
|
|
{ |
68
|
165
|
|
|
165
|
1
|
1918
|
my ($self, $header, $value) = @_; |
69
|
165
|
|
|
|
|
387
|
my $headers = $self->headers(); |
70
|
165
|
|
|
|
|
818
|
$headers->{$header} = $value; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub recipient_headers |
74
|
|
|
|
|
|
|
{ |
75
|
51
|
|
|
51
|
1
|
129
|
return qw( Delivered-To To Cc ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub header |
79
|
|
|
|
|
|
|
{ |
80
|
82
|
|
|
82
|
1
|
160
|
my ($self, $name) = @_; |
81
|
82
|
|
|
|
|
178
|
my $headers = $self->headers(); |
82
|
|
|
|
|
|
|
|
83
|
82
|
50
|
|
|
|
357
|
return $self->message->header( $name ) unless exists $headers->{$name}; |
84
|
82
|
100
|
|
|
|
2110
|
return wantarray ? @{ $headers->{$name} } : $headers->{$name}[0]; |
|
27
|
|
|
|
|
106
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub add_headers |
88
|
|
|
|
|
|
|
{ |
89
|
26
|
|
|
26
|
1
|
44
|
my $self = shift; |
90
|
26
|
|
|
|
|
75
|
$self->find_headers(qw( Subject )); |
91
|
26
|
|
|
|
|
84
|
$self->find_address_headers(); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub find_headers |
95
|
|
|
|
|
|
|
{ |
96
|
26
|
|
|
26
|
1
|
61
|
my ($self, @headers) = @_; |
97
|
26
|
|
|
|
|
71
|
my $message = $self->message(); |
98
|
|
|
|
|
|
|
|
99
|
26
|
|
|
|
|
60
|
for my $header (map { ucfirst( lc( $_ ) ) } @headers) |
|
26
|
|
|
|
|
121
|
|
100
|
|
|
|
|
|
|
{ |
101
|
26
|
|
|
|
|
104
|
$self->store_header( $header, [ $message->header( $header ) ] ); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub find_address_headers |
106
|
|
|
|
|
|
|
{ |
107
|
26
|
|
|
26
|
1
|
44
|
my $self = shift; |
108
|
26
|
|
|
|
|
64
|
my $message = $self->message(); |
109
|
|
|
|
|
|
|
|
110
|
26
|
|
|
|
|
79
|
for my $header (map { ucfirst(lc($_)) } $self->recipient_headers(), 'From') |
|
104
|
|
|
|
|
257
|
|
111
|
|
|
|
|
|
|
{ |
112
|
104
|
|
|
|
|
335
|
my @value = map { Email::Address->parse( $_ ) } |
|
52
|
|
|
|
|
2510
|
|
113
|
|
|
|
|
|
|
$message->header( $header ); |
114
|
104
|
|
|
|
|
5573
|
$self->store_header( $header, \@value ); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub add_recipient |
119
|
|
|
|
|
|
|
{ |
120
|
26
|
|
|
26
|
1
|
42
|
my $self = shift; |
121
|
26
|
|
|
|
|
72
|
my $message = $self->message(); |
122
|
26
|
|
|
|
|
75
|
my $recipient = $self->recipient(); |
123
|
|
|
|
|
|
|
|
124
|
26
|
100
|
|
|
|
74
|
if ($recipient) |
125
|
|
|
|
|
|
|
{ |
126
|
1
|
|
|
|
|
5
|
$self->recipient_header( '' ); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
else |
129
|
|
|
|
|
|
|
{ |
130
|
25
|
|
|
|
|
65
|
for my $header (map { ucfirst( lc( $_ ) ) } $self->recipient_headers()) |
|
75
|
|
|
|
|
188
|
|
131
|
|
|
|
|
|
|
{ |
132
|
50
|
100
|
|
|
|
131
|
next unless $recipient = $self->header( $header ); |
133
|
25
|
|
|
|
|
944
|
$self->recipient_header( $header ); |
134
|
25
|
|
|
|
|
49
|
last; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
26
|
|
|
|
|
121
|
$self->recipient( ( Email::Address->parse( $recipient ) )[0] ); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub remove_recipient |
142
|
|
|
|
|
|
|
{ |
143
|
26
|
|
|
26
|
1
|
59
|
my ($self, $header, $recipient) = @_; |
144
|
2
|
|
|
2
|
|
15
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1276
|
|
145
|
26
|
50
|
|
|
|
98
|
Carp::cluck( 'no' ) unless $recipient; |
146
|
26
|
|
|
|
|
834
|
my $recip_addy = $recipient->address(); |
147
|
|
|
|
|
|
|
|
148
|
26
|
|
|
|
|
211
|
for my $remove_header ( 'To', 'Cc' ) |
149
|
|
|
|
|
|
|
{ |
150
|
27
|
|
|
|
|
44
|
my ($found, @cleaned); |
151
|
|
|
|
|
|
|
|
152
|
27
|
|
|
|
|
72
|
my @addresses = $self->header( $remove_header ); |
153
|
|
|
|
|
|
|
|
154
|
27
|
|
|
|
|
135
|
while ( my $address = shift @addresses ) |
155
|
|
|
|
|
|
|
{ |
156
|
26
|
100
|
66
|
|
|
765
|
if ( not( $found ) and $address->address() eq $recip_addy ) |
157
|
|
|
|
|
|
|
{ |
158
|
25
|
|
|
|
|
217
|
push @cleaned, @addresses; |
159
|
25
|
|
|
|
|
41
|
$found = 1; |
160
|
25
|
|
|
|
|
63
|
last; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
else |
163
|
|
|
|
|
|
|
{ |
164
|
1
|
|
|
|
|
15
|
push @cleaned, $address; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
27
|
100
|
|
|
|
92
|
next unless $found; |
169
|
25
|
|
|
|
|
80
|
$self->store_header( $remove_header, \@cleaned ); |
170
|
25
|
|
|
|
|
93
|
return; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub find_key |
175
|
|
|
|
|
|
|
{ |
176
|
26
|
|
|
26
|
1
|
45
|
my $self = shift; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# be paranoid; explicitly copy captured match variables |
179
|
26
|
50
|
|
|
|
58
|
$self->key( "$1" ) if $self->recipient() =~ /\+(\w+)/; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub process_body |
183
|
|
|
|
|
|
|
{ |
184
|
0
|
|
|
0
|
1
|
0
|
my ($self, $address) = @_; |
185
|
0
|
|
|
|
|
0
|
my $attributes = $address->attributes(); |
186
|
0
|
|
|
|
|
0
|
my $body = $self->remove_sig(); |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
0
|
|
|
0
|
while (@$body and $body->[0] =~ /^(\w+):\s*(.*)$/) |
189
|
|
|
|
|
|
|
{ |
190
|
0
|
|
|
|
|
0
|
my ($directive, $value) = (lc( $1 ), $2); |
191
|
0
|
0
|
|
|
|
0
|
$address->$directive( $value ) if exists $attributes->{ $directive }; |
192
|
0
|
|
|
|
|
0
|
shift @$body; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
0
|
return $body; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub remove_sig |
199
|
|
|
|
|
|
|
{ |
200
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
201
|
2
|
|
|
|
|
7
|
my $message = $self->message(); |
202
|
2
|
|
|
|
|
13
|
my $body = ( $message->parts() )[0]->body(); |
203
|
|
|
|
|
|
|
|
204
|
2
|
|
|
|
|
129
|
my @lines; |
205
|
|
|
|
|
|
|
|
206
|
2
|
|
|
|
|
12
|
for my $line (split(/\n/, $body)) |
207
|
|
|
|
|
|
|
{ |
208
|
7
|
100
|
|
|
|
19
|
last if $line eq '-- '; |
209
|
6
|
|
|
|
|
11
|
push @lines, $line; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
2
|
|
|
|
|
11
|
return \@lines; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub copy_headers |
216
|
|
|
|
|
|
|
{ |
217
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
218
|
0
|
|
|
|
|
|
my $message = $self->message(); |
219
|
0
|
|
|
|
|
|
my $headers = $self->headers(); |
220
|
|
|
|
|
|
|
|
221
|
0
|
|
|
|
|
|
my %copy; |
222
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
for my $header ( $message->headers() ) |
224
|
|
|
|
|
|
|
{ |
225
|
0
|
0
|
|
|
|
|
next if $header eq 'From '; |
226
|
|
|
|
|
|
|
|
227
|
0
|
0
|
|
|
|
|
my @value = exists $headers->{$header} ? |
228
|
|
|
|
|
|
|
$self->header( $header ) : |
229
|
|
|
|
|
|
|
$message->header( $header ); |
230
|
|
|
|
|
|
|
|
231
|
0
|
0
|
|
|
|
|
next unless @value; |
232
|
0
|
|
|
|
|
|
$copy{ ucfirst( lc( $header ) ) } = join(', ', @value); |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
|
return \%copy; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
1; |
239
|
|
|
|
|
|
|
__END__ |