blib/lib/Email/MIME/Attachment/Stripper.pm

filter: Statementstmt 96.0% 49 / 51 Branchbran 80.0% 16 / 20 Conditioncond 68.1% 15 / 22 MC/DCmcdc 18.1% 2 / 11 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 81.0% 94 / 116 CC 20 SCAR 20.9
CC
20
Cov
86%
_detach_all
13.2
new
7.5
attachments
3.0
CRAP 8.1
↑ Summary
1 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Email::MIME::Attachment::Stripper;
4 {
5 6 $Email::MIME::Attachment::Stripper::VERSION = '1.317';
6 }
7 # ABSTRACT: strip the attachments from an email
8  
9 6 ▶use Email::MIME 1.861; # new(\$str)
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Email::MIME::ContentType 1.016; # type/subtype
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 8 ▶sub new {
Subroutine new: called CC=5 SCAR=20.2
Pod documented
15 8 my ($class, $email, %attr) = @_;
16 8 ▶ $email = Email::MIME->new($email) if (ref($email) || 'SCALAR') eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if (ref $email || "SCALAR") eq "SCALAR" 0 8 8
Condition50%1/2
ref $email || 'SCALAR'
l!l
80
MC/DC0%0/1
ref $email || 'SCALAR'
ref $email
Truth table50%1/2
A
A= ref $email
Aresult
11
00
17  
18 8 ▶ croak "Need a message" unless ref($email) || do {
Branch: 1 branch
BranchTrueFalseTotal
unless ref $email or do { require Email::Abstract; $email = "Email::Abstract"->cast($email, "Email::MIME") } 0 8 8
Condition33%1/3
ref $email or do { require Email::Abstract; $email = "Email::Abstract"->cast($email, "Email::MIME") }
l!l&&r!l&&!r
800
MC/DC0%0/2
ref $email or do { require Email::Abstract; $email = "Email::Abstract"->cast($email, "Email::MIME") }
ref $email do { require Email::Abstract; $email = "Email::Abstract"->cast($email, "Email::MIME") }
Truth table33%1/3
A or B
A= ref $emailB= do { require Email::Abstract; $email = "Email::Abstract"->cast($email, "Email::MIME") }
ABresult
1X1
011
000
19 0 require Email::Abstract;
20 0 $email = Email::Abstract->cast($email, 'Email::MIME');
21 };
22  
23 8 bless { message => $email, attr => \%attr }, $class;
24 }
25  
26  
27 7 ▶sub message {
Subroutine message: called CC=2 SCAR=7.1
Pod documented
28 7 my ($self) = @_;
29 7 ▶ $self->_detach_all unless exists $self->{attach};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"attach"} 7 0 7
30 7 return $self->{message};
31 }
32  
33  
34 7 ▶sub attachments {
Subroutine attachments: called CC=3 SCAR=11.0
Pod documented
35 7 my $self = shift;
36 7 ▶ $self->_detach_all unless exists $self->{attach};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"attach"} 3 4 7
37 7 ▶ return $self->{attach} ? @{ $self->{attach} } : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->{'attach'} ? : 5 2 7
38 }
39  
40 11 ▶sub _detach_all {
Subroutine _detach_all: called CC=13 SCAR=25.8
41 11 my ($self, $part) = @_;
42 11 ▶ $part ||= $self->{message};
Condition66%2/3
$part ||= $self->{"message"}
l!l&&r!l&&!r
1100
MC/DC0%0/2
$part ||= $self->{"message"}
$part $self->{"message"}
Truth table66%2/3
A ||= B
A= $partB= $self->{"message"}
ABresult
1X1
011
000
43 11 ▶ return if $part->parts == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $part->parts == 1 4 7 11
44  
45 7 my @attach = ();
46 7 my @keep = ();
47 7 foreach ( $part->parts ) {
48 18 ▶ my $ct = $_->content_type || 'text/plain';
Condition50%1/2
$_->content_type || 'text/plain'
l!l
180
MC/DC0%0/1
$_->content_type || 'text/plain'
$_->content_type
Truth table50%1/2
A
A= $_->content_type
Aresult
11
00
49 18 ▶ my $dp = $_->header('Content-Disposition') || 'inline';
Condition100%2/2
$_->header('Content-Disposition') || 'inline'
l!l
153
MC/DC100%1/1
$_->header('Content-Disposition') || 'inline'
$_->header('Content-Disposition')
Truth table100%2/2
A
A= $_->header('Content-Disposition')
Aresult
11
00
50  
51 18 ▶ push(@keep, $_) and next
Branch: 1 branch
BranchTrueFalseTotal
if $ct =~ m[text/plain]i and $dp =~ /inline/i 6 12 18
Condition75%6/8
$ct =~ m[text/plain]i && $dp =~ /inline/i && (push(@keep, $_) && (next))
!ll&&!rl&&r
1260
$ct =~ m[text/plain]i and $dp =~ /inline/i
!ll&&!rl&&r
1116
push @keep, $_ and next
!ll
06
MC/DC0%0/3
$ct =~ m[text/plain]i && $dp =~ /inline/i && (push(@keep, $_) && (next))
$ct =~ m[text/plain]i $dp =~ /inline/i push @keep, $_
Truth table50%2/4
A and B && C
A= $ct =~ m[text/plain]iB= $dp =~ /inline/iC= push @keep, $_
ABCresult
0XX0
10X0
1100
1111
52 if $ct =~ m[text/plain]i && $dp =~ /inline/i;
53 12 push @attach, $_;
54 12 ▶ if ($_->parts > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->parts > 1) 1 11 12
55 1 my @kept=$self->_detach_all($_);
56 1 ▶ push(@keep,@kept) if @kept;
Branch: 1 branch
BranchTrueFalseTotal
if @kept 1 0 1
57 }
58 }
59  
60 7 $part->parts_set(\@keep);
61 7 push @{$self->{attach}}, map {;
62 12 my $content_type = parse_content_type($_->content_type);
63 {
64 12 ▶ content_type => join('/', @{$content_type}{qw[type subtype]}),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'attr'}{'force_filename'} ? : 2 10 12
Condition100%2/2
$_->filename or ""
l!l
64
MC/DC100%1/1
$_->filename or ""
$_->filename
Truth table100%2/2
A
A= $_->filename
Aresult
11
00
65 payload => $_->body,
66 filename => $self->{attr}->{force_filename}
67 12 ? $_->filename(1)
68 : ($_->filename || ''),
69 }
70 } @attach;
71  
72 7 return @keep;
73 }
74  
75  
76 6 1;
77  
78 __END__
↑ Summary