line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
5
|
|
|
5
|
|
121485
|
use strict; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
206
|
|
2
|
5
|
|
|
5
|
|
31
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
412
|
|
3
|
|
|
|
|
|
|
package Email::MIME::Attachment::Stripper; |
4
|
|
|
|
|
|
|
{ |
5
|
|
|
|
|
|
|
$Email::MIME::Attachment::Stripper::VERSION = '1.317'; |
6
|
|
|
|
|
|
|
} |
7
|
|
|
|
|
|
|
# ABSTRACT: strip the attachments from an email |
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
28
|
use Email::MIME 1.861; # new(\$str) |
|
5
|
|
|
|
|
192
|
|
|
5
|
|
|
|
|
158
|
|
10
|
5
|
|
|
5
|
|
30
|
use Email::MIME::ContentType 1.016; # type/subtype |
|
5
|
|
|
|
|
92
|
|
|
5
|
|
|
|
|
357
|
|
11
|
5
|
|
|
5
|
|
29
|
use Carp; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
3381
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
8
|
|
|
8
|
1
|
57025
|
my ($class, $email, %attr) = @_; |
16
|
8
|
50
|
50
|
|
|
64
|
$email = Email::MIME->new($email) if (ref($email) || 'SCALAR') eq 'SCALAR'; |
17
|
|
|
|
|
|
|
|
18
|
8
|
0
|
33
|
|
|
49
|
croak "Need a message" unless ref($email) || do { |
19
|
0
|
|
|
|
|
0
|
require Email::Abstract; |
20
|
0
|
|
|
|
|
0
|
$email = Email::Abstract->cast($email, 'Email::MIME'); |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
8
|
|
|
|
|
77
|
bless { message => $email, attr => \%attr }, $class; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub message { |
28
|
7
|
|
|
7
|
1
|
574
|
my ($self) = @_; |
29
|
7
|
50
|
|
|
|
179
|
$self->_detach_all unless exists $self->{attach}; |
30
|
7
|
|
|
|
|
62
|
return $self->{message}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub attachments { |
35
|
7
|
|
|
7
|
1
|
3724
|
my $self = shift; |
36
|
7
|
100
|
|
|
|
41
|
$self->_detach_all unless exists $self->{attach}; |
37
|
7
|
100
|
|
|
|
52
|
return $self->{attach} ? @{ $self->{attach} } : (); |
|
5
|
|
|
|
|
39
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _detach_all { |
41
|
11
|
|
|
11
|
|
23
|
my ($self, $part) = @_; |
42
|
11
|
|
66
|
|
|
135
|
$part ||= $self->{message}; |
43
|
11
|
100
|
|
|
|
41
|
return if $part->parts == 1; |
44
|
|
|
|
|
|
|
|
45
|
7
|
|
|
|
|
78
|
my @attach = (); |
46
|
7
|
|
|
|
|
14
|
my @keep = (); |
47
|
7
|
|
|
|
|
22
|
foreach ( $part->parts ) { |
48
|
18
|
|
50
|
|
|
141
|
my $ct = $_->content_type || 'text/plain'; |
49
|
18
|
|
100
|
|
|
1046
|
my $dp = $_->header('Content-Disposition') || 'inline'; |
50
|
|
|
|
|
|
|
|
51
|
18
|
100
|
50
|
|
|
855
|
push(@keep, $_) and next |
|
|
|
100
|
|
|
|
|
52
|
|
|
|
|
|
|
if $ct =~ m[text/plain]i && $dp =~ /inline/i; |
53
|
12
|
|
|
|
|
23
|
push @attach, $_; |
54
|
12
|
100
|
|
|
|
39
|
if ($_->parts > 1) { |
55
|
1
|
|
|
|
|
22
|
my @kept=$self->_detach_all($_); |
56
|
1
|
50
|
|
|
|
8
|
push(@keep,@kept) if @kept; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
7
|
|
|
|
|
110
|
$part->parts_set(\@keep); |
61
|
7
|
|
|
|
|
6155
|
push @{$self->{attach}}, map {; |
|
7
|
|
|
|
|
24
|
|
62
|
12
|
|
|
|
|
2453
|
my $content_type = parse_content_type($_->content_type); |
63
|
|
|
|
|
|
|
{ |
64
|
12
|
100
|
100
|
|
|
9460
|
content_type => join('/', @{$content_type}{qw[type subtype]}), |
|
12
|
|
|
|
|
74
|
|
65
|
|
|
|
|
|
|
payload => $_->body, |
66
|
|
|
|
|
|
|
filename => $self->{attr}->{force_filename} |
67
|
|
|
|
|
|
|
? $_->filename(1) |
68
|
|
|
|
|
|
|
: ($_->filename || ''), |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} @attach; |
71
|
|
|
|
|
|
|
|
72
|
7
|
|
|
|
|
76486
|
return @keep; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |