IMAPClient/BodyStructure.pm

filter: Statementstmt 83.3% 105 / 126 Branchbran 48.2% 28 / 58 Conditioncond 44.1% 19 / 43 MC/DCmcdc 15.3% 4 / 26 Subroutinesub 80.0% 20 / 25 Podpod 50.0% 2 / 4 totaltotal 63.1% 178 / 282 CC 51 SCAR 26.2
CC
51
Cov
67%
_get_thingy
34.8
id
27.5
bodystructure
17.7
CRAP 13.7
« IMAPClient/Thread.pm ↑ Summary IMAPClient/MessageSet.pm »
1 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Mail::IMAPClient::BodyStructure;
5 1 ▶use Mail::IMAPClient::BodyStructure::Parse;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # BUG?: old code used name "HEAD" instead of "HEADER", change?
8 1 my $HEAD = "HEAD";
9  
10 # my has file scope, not limited to package!
11 1 ▶my $parser = Mail::IMAPClient::BodyStructure::Parse->new
Branch: 1 branch
BranchTrueFalseTotal
my $parser = "Mail::IMAPClient::BodyStructure::Parse"->new or die "Cannot parse rules: $@\n" . "Try remaking Mail::IMAPClient::BodyStructure::Parse.\n" 1 0 1
12 or die "Cannot parse rules: $@\n"
13 . "Try remaking Mail::IMAPClient::BodyStructure::Parse.\n";
14  
15 10 ▶sub new {
Subroutine new: called CC=4 SCAR=14.2
Pod documented
16 10 my $class = shift;
17 10 my $bodystructure = shift;
18  
19 10 ▶ my $self = $parser->start($bodystructure)
Branch: 1 branch
BranchTrueFalseTotal
my $self = $parser->start($bodystructure) or return undef 10 0 10
20 or return undef;
21  
22 10 $self->{_prefix} = "";
23 10 ▶ $self->{_id} = exists $self->{bodystructure} ? $HEAD : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'bodystructure'} ? : 9 1 10
24 10 $self->{_top} = 1;
25  
26 10 ▶ bless $self, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0100
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
27 }
28  
29 91 ▶sub _get_thingy {
Subroutine _get_thingy: called CC=10 SCAR=35.5
30 91 my $thingy = shift;
31 91 ▶ my $object = shift || ( ref $thingy ? $thingy : undef );
Branch: 1 branch
BranchTrueFalseTotal
ref $thingy ? : 0 0 0
Condition33%1/3
shift() || (ref $thingy ? $thingy : undef)
l!l&&r!l&&!r
9100
MC/DC0%0/2
shift() || (ref $thingy ? $thingy : undef)
shift() (ref $thingy ? $thingy : undef)
Truth table33%1/3
A || B
A= shift()B= (ref $thingy ? $thingy : undef)
ABresult
1X1
011
000
32  
33 91 ▶ unless ( $object && ref $object ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($object and ref $object) 0 91 91
Condition33%1/3
$object and ref $object
!ll&&!rl&&r
0091
MC/DC0%0/2
$object and ref $object
$object ref $object
Truth table33%1/3
A and B
A= $objectB= ref $object
ABresult
0X0
100
111
34 0 warn $@ = "No argument passed to $thingy method.";
35 0 return undef;
36 }
37  
38 91 ▶ unless ( UNIVERSAL::isa( $object, 'HASH' ) && exists $object->{$thingy} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($object, "HASH") and exists $object->{$thingy}) 0 91 91
Condition33%1/3
UNIVERSAL::isa($object, "HASH") and exists $object->{$thingy}
!ll&&!rl&&r
0091
MC/DC0%0/2
UNIVERSAL::isa($object, "HASH") and exists $object->{$thingy}
UNIVERSAL::isa($object, "HASH") exists $object->{$thingy}
Truth table33%1/3
A and B
A= UNIVERSAL::isa($object, "HASH")B= exists $object->{$thingy}
ABresult
0X0
100
111
39 0 ▶ my $a = $thingy =~ /^[aeiou]/i ? 'an' : 'a';
Branch: 1 branch
BranchTrueFalseTotal
$thingy =~ /^[aeiou]/i ? : 0 0 0
40 0 ▶ my $has = ref $object eq 'HASH' ? join( ", ", keys %$object ) : '';
Branch: 1 branch
BranchTrueFalseTotal
ref $object eq 'HASH' ? : 0 0 0
41 0 ▶ warn $@ =
Branch: 1 branch
BranchTrueFalseTotal
$has ? : 0 0 0
42 ref($object)
43 . " $object does not have $a $thingy. "
44 . ( $has ? "It has $has" : '' );
45 0 return undef;
46 }
47  
48 91 my $value = $object->{$thingy};
49 91 $value =~ s/\\ ( [\\\(\)"\x0d\x0a] )/$1/gx;
50 91 $value =~ s/^"(.*)"$/$1/;
51 91 $value;
52 }
53  
54 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
55 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
56 1 foreach my $datum (
57 qw/ bodytype bodysubtype bodyparms bodydisp bodyid bodydesc bodyenc
58 bodysize bodylang envelopestruct textlines /
59 )
60 {
61 11 ▶ *$datum = sub { _get_thingy( $datum, @_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
62 }
63 }
64  
65 7 ▶sub parts {
Subroutine parts: called CC=9 SCAR=26.5
Pod undocumented
66 7 my $self = shift;
67 0 return wantarray ? @{ $self->{PartsList} } : $self->{PartsList}
68 7 ▶ if exists $self->{PartsList};
Branch: 2 branches
BranchTrueFalseTotal
if exists $self->{"PartsList"} 0 7 7
wantarray ? : 0 0 0
69  
70 7 my @parts;
71 7 $self->{PartsList} = \@parts;
72  
73 # BUG?: should this default to ($HEAD, TEXT)
74 7 ▶ unless ( exists $self->{bodystructure} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"bodystructure"}) 0 7 7
75 0 $self->{PartsIndex}{1} = $self;
76 0 @parts = ( $HEAD, 1 );
77 0 ▶ return wantarray ? @parts : \@parts;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
78 }
79  
80 7 foreach my $p ( $self->bodystructure ) {
81 87 my $id = $p->id;
82 87 push @parts, $id;
83 87 $self->{PartsIndex}{$id} = $p;
84 87 ▶ my $type = uc $p->bodytype || '';
Condition50%1/2
uc $p->bodytype || ''
l!l
870
MC/DC0%0/1
uc $p->bodytype || ''
uc $p->bodytype
Truth table50%1/2
A
A= uc $p->bodytype
Aresult
11
00
85  
86 87 ▶ push @parts, "$id.$HEAD"
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "MESSAGE" 19 68 87
87 if $type eq 'MESSAGE';
88 }
89  
90 7 ▶ wantarray ? @parts : \@parts;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 0 7
91 }
92  
93 58 ▶sub bodystructure {
Subroutine bodystructure: called CC=16 SCAR=28.7
Pod documented
94 58 my $self = shift;
95 58 my $partno = 0;
96 58 my @parts;
97  
98 58 ▶ if ( $self->{_top} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_top"}) 7 51 58
99 7 ▶ $self->{_id} ||= $HEAD;
Condition33%1/3
$self->{"_id"} ||= $HEAD
l!l&&r!l&&!r
700
MC/DC0%0/2
$self->{"_id"} ||= $HEAD
$self->{"_id"} $HEAD
Truth table33%1/3
A ||= B
A= $self->{"_id"}B= $HEAD
ABresult
1X1
011
000
100 7 ▶ $self->{_prefix} ||= $HEAD;
Condition33%1/3
$self->{"_prefix"} ||= $HEAD
l!l&&r!l&&!r
070
MC/DC0%0/2
$self->{"_prefix"} ||= $HEAD
$self->{"_prefix"} $HEAD
Truth table33%1/3
A ||= B
A= $self->{"_prefix"}B= $HEAD
ABresult
1X1
011
000
101 7 $partno = 0;
102 7 foreach my $b ( @{ $self->{bodystructure} } ) {
103 26 $b->{_id} = ++$partno;
104 26 $b->{_prefix} = $partno;
105 26 push @parts, $b, $b->bodystructure;
106 }
107 7 ▶ return wantarray ? @parts : \@parts;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 0 7
108 }
109  
110 51 ▶ my $prefix = $self->{_prefix} || "";
Condition50%1/2
$self->{'_prefix'} || ''
l!l
510
MC/DC0%0/1
$self->{'_prefix'} || ''
$self->{'_prefix'}
Truth table50%1/2
A
A= $self->{'_prefix'}
Aresult
11
00
111 51 $prefix =~ s/\.?$/./;
112  
113 51 foreach my $p ( @{ $self->{bodystructure} } ) {
114 61 $partno++;
115  
116 # BUG?: old code didn't add .TEXT sections, should we skip these?
117 # - This code needs to be generalised (maybe it belongs in parts()?)
118 # - Should every message should have HEAD (actually MIME) and TEXT?
119 # at least dovecot and iplanet appear to allow this even for
120 # non-multipart sections
121 61 my $pno = $partno;
122 61 ▶ my $stype = $self->{bodytype} || "";
Condition50%1/2
$self->{'bodytype'} || ''
l!l
610
MC/DC0%0/1
$self->{'bodytype'} || ''
$self->{'bodytype'}
Truth table50%1/2
A
A= $self->{'bodytype'}
Aresult
11
00
123 61 ▶ my $ptype = $p->{bodytype} || "";
Condition50%1/2
$p->{'bodytype'} || ''
l!l
610
MC/DC0%0/1
$p->{'bodytype'} || ''
$p->{'bodytype'}
Truth table50%1/2
A
A= $p->{'bodytype'}
Aresult
11
00
124  
125 # a message and the multipart inside of it "collapse together"
126 61 ▶ if ( $partno == 1 and $stype eq 'MESSAGE' and $ptype eq 'MULTIPART' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($partno == 1 and $stype eq 'MESSAGE' and $ptype eq 'MULTIPART') { } 15 46 61
Condition100%6/6
$partno == 1 and $stype eq "MESSAGE" and $ptype eq "MULTIPART"
!ll&&!rl&&r
42415
$partno == 1 and $stype eq "MESSAGE"
!ll&&!rl&&r
212119
MC/DC100%3/3
$partno == 1 and $stype eq "MESSAGE" and $ptype eq "MULTIPART"
$partno == 1 $stype eq "MESSAGE" $ptype eq "MULTIPART"
Truth table100%4/4
A and B and C
A= $partno == 1B= $stype eq "MESSAGE"C= $ptype eq "MULTIPART"
ABCresult
0XX0
10X0
1100
1111
127 15 $pno = "TEXT";
128 15 $p->{_prefix} = "$prefix";
129 }
130 else {
131 46 $p->{_prefix} = "$prefix$partno";
132 }
133 61 ▶ $p->{_id} ||= "$prefix$pno";
Condition33%1/3
$p->{"_id"} ||= "$prefix$pno"
l!l&&r!l&&!r
0610
MC/DC0%0/2
$p->{"_id"} ||= "$prefix$pno"
$p->{"_id"} "$prefix$pno"
Truth table33%1/3
A ||= B
A= $p->{"_id"}B= "$prefix$pno"
ABresult
1X1
011
000
134  
135 61 ▶ push @parts, $p, $p->{bodystructure} ? $p->bodystructure : ();
Branch: 1 branch
BranchTrueFalseTotal
$p->{'bodystructure'} ? : 25 36 61
136 }
137  
138 51 ▶ wantarray ? @parts : \@parts;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 51 0 51
139 }
140  
141 87 ▶sub id {
Subroutine id: called CC=6 SCAR=33.1
Pod undocumented
142 87 my $self = shift;
143 return $self->{_id}
144 87 ▶ if exists $self->{_id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_id"} 87 0 87
145  
146 return $HEAD
147 0 ▶ if $self->{_top};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_top"} 0 0 0
148  
149 # BUG?: can this be removed? ... seems wrong
150 0 ▶ if ( $self->{bodytype} eq 'MULTIPART' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'bodytype'} eq 'MULTIPART') { } 0 0 0
151 0 ▶ my $p = $self->{_id} || $self->{_prefix};
Condition0%0/3
$self->{'_id'} || $self->{'_prefix'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_id'} || $self->{'_prefix'}
$self->{'_id'} $self->{'_prefix'}
Truth table0%0/3
A || B
A= $self->{'_id'}B= $self->{'_prefix'}
ABresult
1X1
011
000
152 0 $p =~ s/\.$//;
153 0 return $p;
154 }
155 else {
156 0 ▶ return $self->{_id} ||= 1;
Condition0%0/2
$self->{"_id"} ||= 1
l!l
00
MC/DC0%0/1
$self->{"_id"} ||= 1
$self->{"_id"}
Truth table0%0/2
A
A= $self->{"_id"}
Aresult
11
00
157 }
158 }
159  
160 package Mail::IMAPClient::BodyStructure::Part;
161 1 our @ISA = qw/Mail::IMAPClient::BodyStructure/;
162  
163 package Mail::IMAPClient::BodyStructure::Envelope;
164 1 our @ISA = qw/Mail::IMAPClient::BodyStructure/;
165  
166 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
167 1 my ( $class, $envelope ) = @_;
168 1 $parser->envelope($envelope);
169 }
170  
171 3 ▶sub parse_string {
Subroutine parse_string: called CC=2 SCAR=6.9
172 3 my ( $class, $envelope ) = @_;
173 3 ▶ $envelope = "(" . $envelope . ")" unless ( $envelope =~ /^\(/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $envelope =~ /^\(/ 1 2 3
174 3 $parser->envelopestruct($envelope);
175 }
176  
177 0 ▶sub from_addresses { shift->_addresses( from => 1 ) }
Subroutine from_addresses: not called CC=1 SCAR=6.9
178 0 ▶sub sender_addresses { shift->_addresses( sender => 1 ) }
Subroutine sender_addresses: not called CC=1 SCAR=6.9
179 0 ▶sub replyto_addresses { shift->_addresses( replyto => 1 ) }
Subroutine replyto_addresses: not called CC=1 SCAR=6.9
180 4 ▶sub to_addresses { shift->_addresses( to => 0 ) }
Subroutine to_addresses: called CC=1 SCAR=0.0
181 0 ▶sub cc_addresses { shift->_addresses( cc => 0 ) }
Subroutine cc_addresses: not called CC=1 SCAR=6.9
182 0 ▶sub bcc_addresses { shift->_addresses( bcc => 0 ) }
Subroutine bcc_addresses: not called CC=1 SCAR=6.9
183  
184 4 ▶sub _addresses($$$) {
Subroutine _addresses: called CC=7 SCAR=20.0
185 4 my ( $self, $name, $isSender ) = @_;
186 4 ▶ ref $self->{$name} eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{$name} eq "ARRAY" or return () 4 0 4
187 or return ();
188  
189 4 my @list;
190 4 foreach ( @{ $self->{$name} } ) {
191 4 my $pn = $_->personalname;
192 4 ▶ my $name = $pn && $pn ne 'NIL' ? "$pn " : '';
Branch: 1 branch
BranchTrueFalseTotal
$pn && $pn ne 'NIL' ? : 1 3 4
Condition66%2/3
$pn and $pn ne "NIL"
!ll&&!rl&&r
031
MC/DC50%1/2
$pn and $pn ne "NIL"
$pn $pn ne "NIL"
Truth table66%2/3
A and B
A= $pnB= $pn ne "NIL"
ABresult
0X0
100
111
193 4 push @list, $name . '<' . $_->mailboxname . '@' . $_->hostname . '>';
194 }
195  
196 wantarray ? @list
197 4 ▶ : $isSender ? $list[0]
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 0 4 4
$isSender ? : 0 4 4
198 : \@list;
199 }
200  
201 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
202 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
203 1 for my $datum (
204 qw(subject inreplyto from messageid bcc date
205 replyto to sender cc)
206 )
207 {
208 24 ▶ *$datum = sub { @_ > 1 ? $_[0]->{$datum} = $_[1] : $_[0]->{$datum} }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 24 24
209 10 }
210 }
211  
212 package Mail::IMAPClient::BodyStructure::Address;
213 1 our @ISA = qw/Mail::IMAPClient::BodyStructure/;
214  
215 1 for my $datum (qw(personalname mailboxname hostname sourcename)) {
216 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
217 12 ▶ *$datum = sub { shift->{$datum}; };
Subroutine __ANON__: called CC=1 SCAR=0.0
218 }
219  
220 1 1;
221  
222 __END__
« IMAPClient/Thread.pm ↑ Summary IMAPClient/MessageSet.pm »