blib/lib/MIME/Mini.pm

filter: Statementstmt 89.0% 482 / 541 Branchbran 79.1% 288 / 364 Conditioncond 66.1% 174 / 263 MC/DCmcdc 46.9% 69 / 147 Subroutinesub 89.5% 60 / 67 Podpod 45.4% 25 / 55 totaltotal 76.4% 1098 / 1437 CC 287 SCAR 36.1
CC
287
Cov
81%
read_attachment_attribute
278.3
newmail
77.9
winmail
35.6
CRAP 36.9
↑ Summary
1 # MIME::Mini - Minimal code to parse/create mbox files and mail messages
2 #
3 # Copyright (C) 2005-2007, 2023-2024 raf <raf@raf.org>
4 #
5 # This is free software; you can redistribute it and/or modify it under
6 # the same terms as the Perl 5 programming language system itself.
7 #
8 # 20240424 raf <raf@raf.org>
9  
10 package MIME::Mini;
11 2 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 our $VERSION = '1.002';
16  
17 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 our @ISA = ('Exporter');
19  
20 2 our @EXPORT = ();
21 2 our @EXPORT_OK = qw(
22 formail mail2str mail2multipart mail2singlepart mail2mbox
23 insert_header append_header replace_header delete_header
24 insert_part append_part replace_part delete_part
25 header headers header_names
26 param mimetype encoding filename
27 body message parts
28 newparam newmail
29 );
30 2 our %EXPORT_TAGS = (all => [@EXPORT_OK]);
31  
32 sub formail # rfc2822 + mboxrd format (see http://www.qmail.org/man/man5/mbox.html)
33 140 ▶{
Subroutine formail: called CC=20 SCAR=30.0
Pod documented
34 sub mime # rfc2045, rfc2046
35 178 ▶ {
Subroutine mime: called CC=16 SCAR=27.8
Pod undocumented
36 178 my ($mail, $parent) = @_;
37 178 ▶ return $mail unless exists $mail->{header} && exists $mail->{header}->{'content-type'} || defined $parent && exists $parent->{mime_type} && $parent->{mime_type} =~ /^multipart\/digest$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless exists $mail->{"header"} and exists $mail->{"header"}{"content-type"} or defined $parent and exists $parent->{"mime_type"} and $parent->{"mime_type"} =~ m[^multipart/digest$]iu 42 136 178
Condition91%11/12
exists $mail->{"header"} and exists $mail->{"header"}{"content-type"} or defined $parent and exists $parent->{"mime_type"} and $parent->{"mime_type"} =~ m[^multipart/digest$]iu
l!l&&r!l&&!r
130642
exists $mail->{"header"} and exists $mail->{"header"}{"content-type"}
!ll&&!rl&&r
1830130
defined $parent and exists $parent->{"mime_type"} and $parent->{"mime_type"} =~ m[^multipart/digest$]iu
!ll&&!rl&&r
12306
defined $parent and exists $parent->{"mime_type"}
!ll&&!rl&&r
12036
MC/DC60%3/5
exists $mail->{"header"} and exists $mail->{"header"}{"content-type"} or defined $parent and exists $parent->{"mime_type"} and $parent->{"mime_type"} =~ m[^multipart/digest$]iu
exists $mail->{"header"} exists $mail->{"header"}{"content-type"} defined $parent exists $parent->{"mime_type"} $parent->{"mime_type"} =~ m[^multipart/digest$]iu
Truth table55%5/9
A and B or C and D and E
A= exists $mail->{"header"}B= exists $mail->{"header"}{"content-type"}C= defined $parentD= exists $parent->{"mime_type"}E= $parent->{"mime_type"} =~ m[^multipart/digest$]iu
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
38 136 ▶ my ($content_type) = (exists $mail->{header} && exists $mail->{header}->{'content-type'}) ? @{$mail->{header}->{'content-type'}} : "Content-Type: message/rfc822\n";
Branch: 1 branch
BranchTrueFalseTotal
exists $mail->{'header'} && exists $mail->{'header'}{'content-type'} ? : 130 6 136
Condition66%2/3
exists $mail->{"header"} and exists $mail->{"header"}{"content-type"}
!ll&&!rl&&r
60130
MC/DC50%1/2
exists $mail->{"header"} and exists $mail->{"header"}{"content-type"}
exists $mail->{"header"} exists $mail->{"header"}{"content-type"}
Truth table66%2/3
A and B
A= exists $mail->{"header"}B= exists $mail->{"header"}{"content-type"}
ABresult
0X0
100
111
39 136 my ($type) = $content_type =~ /^content-type:\s*([\w\/.-]+)/i;
40 136 ▶ my $boundary = param($mail, 'content-type', 'boundary') if $type =~ /^multipart\//i;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ m[^multipart/]iu 62 74 136
41 136 ▶ return $mail unless defined $type && ($type =~ /^multipart\//i && $boundary || $type =~ /^message\/rfc822$/i);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and $type =~ m[^multipart/]iu && $boundary || $type =~ m[^message/rfc822$]iu 54 82 136
Condition77%7/9
defined $type and $type =~ m[^multipart/]iu && $boundary || $type =~ m[^message/rfc822$]iu
!ll&&!rl&&r
05482
$type =~ m[^multipart/]iu and $boundary or $type =~ m[^message/rfc822$]iu
l!l&&r!l&&!r
622054
$type =~ m[^multipart/]iu and $boundary
!ll&&!rl&&r
74062
MC/DC50%2/4
defined $type and $type =~ m[^multipart/]iu && $boundary || $type =~ m[^message/rfc822$]iu
defined $type $type =~ m[^multipart/]iu $boundary $type =~ m[^message/rfc822$]iu
Truth table50%3/6
A and B and C or D
A= defined $typeB= $type =~ m[^multipart/]iuC= $boundaryD= $type =~ m[^message/rfc822$]iu
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
42 82 ▶ ($mail->{mime_boundary}) = $boundary =~ /^(.*\S)/ if $boundary;
Branch: 1 branch
BranchTrueFalseTotal
if $boundary 62 20 82
43 82 $mail->{mime_type} = $type;
44 82 ▶ $mail->{mime_message} = mimepart(delete $mail->{body} || '', $mail), return $mail if $type =~ /^message\/(?:rfc822|external-body)$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ m[^message/(?:rfc822|external-body)$]iu 20 62 82
Condition100%2/2
delete $mail->{'body'} || ''
l!l
182
MC/DC100%1/1
delete $mail->{'body'} || ''
delete $mail->{'body'}
Truth table100%2/2
A
A= delete $mail->{'body'}
Aresult
11
00
45 62 return tnef2mime(mimeparts($mail, $parent));
46 }
47  
48 sub mimeparts
49 62 ▶ {
Subroutine mimeparts: called CC=13 SCAR=25.7
Pod undocumented
50 62 my ($mail, $parent) = @_;
51 62 my $state = 'preamble';
52 62 my $text = '';
53  
54 62 ▶ for (split /(?<=\n)/, delete $mail->{body} || '')
Condition50%1/2
delete $mail->{'body'} || ''
l!l
620
MC/DC0%0/1
delete $mail->{'body'} || ''
delete $mail->{'body'}
Truth table50%1/2
A
A= delete $mail->{'body'}
Aresult
11
00
55 {
56 872 ▶ if (/^--\Q$mail->{mime_boundary}\E(--)?/)
Branch: 1 branch
BranchTrueFalseTotal
if (/^--\Q$mail->{"mime_boundary"}\E(--)?/u) 146 726 872
57 {
58 146 ▶ if ($state eq 'preamble')
Branch: 2 branches
BranchTrueFalseTotal
if ($state eq 'preamble') { } 62 84 146
elsif ($state eq 'part') { } 84 0 84
59 {
60 62 $state = 'part';
61 62 ▶ $mail->{mime_preamble} = $text if length $text;
Branch: 1 branch
BranchTrueFalseTotal
if length $text 46 16 62
62 }
63 elsif ($state eq 'part')
64 {
65 84 ▶ $state = 'epilogue' if defined $1 && $1 eq '--';
Branch: 1 branch
BranchTrueFalseTotal
if defined $1 and $1 eq "--" 54 30 84
Condition66%2/3
defined $1 and $1 eq "--"
!ll&&!rl&&r
30054
MC/DC50%1/2
defined $1 and $1 eq "--"
defined $1 $1 eq "--"
Truth table66%2/3
A and B
A= defined $1B= $1 eq "--"
ABresult
0X0
100
111
66 84 push @{$mail->{mime_parts}}, mimepart($text, $mail);
67 }
68  
69 146 $text = '', next;
70 }
71  
72 726 $text .= $_;
73 }
74  
75 62 ▶ push @{$mail->{mime_parts}}, mimepart($text, $mail) if $state eq 'part' && length $text;
Branch: 1 branch
BranchTrueFalseTotal
if $state eq "part" and length $text 6 56 62
Condition100%3/3
$state eq "part" and length $text
!ll&&!rl&&r
5426
MC/DC100%2/2
$state eq "part" and length $text
$state eq "part" length $text
Truth table100%3/3
A and B
A= $state eq "part"B= length $text
ABresult
0X0
100
111
76 62 ▶ $mail->{mime_epilogue} = $text if $state eq 'epilogue' && length $text;
Branch: 1 branch
BranchTrueFalseTotal
if $state eq "epilogue" and length $text 16 46 62
Condition100%3/3
$state eq "epilogue" and length $text
!ll&&!rl&&r
83816
MC/DC100%2/2
$state eq "epilogue" and length $text
$state eq "epilogue" length $text
Truth table100%3/3
A and B
A= $state eq "epilogue"B= length $text
ABresult
0X0
100
111
77 62 return $mail;
78 }
79  
80 sub mimepart
81 110 ▶ {
Subroutine mimepart: called CC=2 SCAR=6.9
Pod undocumented
82 110 my ($mail, $parent) = @_;
83 110 my @lines = split /(?<=\n)/, $mail;
84 # Needed to cope (badly) when message/rfc822 attachments incorrectly start with /^From / (thanks libpst)
85 110 ▶ @lines = ('') unless @lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @lines 2 108 110
86 110 ▶ formail(sub { shift @lines }, sub { $mail = shift }, $parent);
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
87 110 return $mail;
88 }
89  
90 140 my ($rd, $act, $parent) = @_;
91 140 my $state = 'header';
92 140 my $mail; my $last;
93  
94 140 ▶ while (defined($_ = $rd->()))
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = &$rd())) 2366 140 2506
95 {
96 2366 s/\r(?=\n)//g; #, tr/\r/\n/;
97  
98 2366 ▶ if (!defined $parent && /^From (?:\S+\s+)?\s*[a-zA-Z]+\s+[a-zA-Z]+\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\s+(?:[A-Z]+\s+)?\d{4}/) # mbox header
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $parent and /^From (?:\S+\s+)?\s*[a-zA-Z]+\s+[a-zA-Z]+\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\s+(?:[A-Z]+\s+)?\d{4}/u) 68 2298 2366
Condition100%3/3
not defined $parent and /^From (?:\S+\s+)?\s*[a-zA-Z]+\s+[a-zA-Z]+\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\s+(?:[A-Z]+\s+)?\d{4}/u
!ll&&!rl&&r
734156468
MC/DC100%2/2
not defined $parent and /^From (?:\S+\s+)?\s*[a-zA-Z]+\s+[a-zA-Z]+\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\s+(?:[A-Z]+\s+)?\d{4}/u
not defined $parent /^From (?:\S+\s+)?\s*[a-zA-Z]+\s+[a-zA-Z]+\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\s+(?:[A-Z]+\s+)?\d{4}/u
Truth table100%3/3
not(A) and B
A= not defined $parentB= /^From (?:\S+\s+)?\s*[a-zA-Z]+\s+[a-zA-Z]+\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\s+(?:[A-Z]+\s+)?\d{4}/u
ABresult
0X0
100
111
99 {
100 68 ▶ $mail->{body} =~ s/\n\n\z/\n/ if $mail && exists $mail->{mbox} && exists $mail->{body};
Branch: 1 branch
BranchTrueFalseTotal
if $mail and exists $mail->{"mbox"} and exists $mail->{"body"} 46 22 68
Condition66%4/6
$mail and exists $mail->{"mbox"} and exists $mail->{"body"}
!ll&&!rl&&r
22046
$mail and exists $mail->{"mbox"}
!ll&&!rl&&r
22046
MC/DC33%1/3
$mail and exists $mail->{"mbox"} and exists $mail->{"body"}
$mail exists $mail->{"mbox"} exists $mail->{"body"}
Truth table50%2/4
A and B and C
A= $mailB= exists $mail->{"mbox"}C= exists $mail->{"body"}
ABCresult
0XX0
10X0
1100
1111
101 68 ▶ my $mbox = $_; $act->(mime($mail, $parent)) or return if $mail;
Branch: 1 branch
BranchTrueFalseTotal
if $mail 46 22 68
Condition75%3/4
$mail && (&$act(mime($mail, $parent)) || (return))
!ll
2246
&$act(mime($mail, $parent)) or return
l!l
460
MC/DC0%0/2
$mail && (&$act(mime($mail, $parent)) || (return))
$mail &$act(mime($mail, $parent))
Truth table33%1/3
A && B
A= $mailB= &$act(mime($mail, $parent))
ABresult
0X0
100
111
102 68 $mail = { mbox => $mbox }, $state = 'header', undef $last, next;
103 }
104  
105 2298 ▶ if ($state eq 'header')
Branch: 2 branches
BranchTrueFalseTotal
if ($state eq 'header') { } 950 1348 2298
elsif ($state eq 'body') { } 1348 0 1348
106 {
107 950 ▶ if (/^([\w-]+):/) # mail header
Branch: 2 branches
BranchTrueFalseTotal
if (/^([\w-]+):/u) { } 682 268 950
elsif (/^$/u) { } 174 94 268
108 {
109 682 push @{$mail->{headers}}, $_;
110 682 push @{$mail->{header}->{$last = lc $1}}, $_;
111 }
112 elsif (/^$/) # blank line after mail headers
113 {
114 174 $mail->{body} = '', $state = 'body';
115 }
116 else # mail header continuation or error
117 {
118 94 ▶ ${$mail->{headers}}[$#{$mail->{headers}}] .= $_ if defined $last;
Branch: 1 branch
BranchTrueFalseTotal
if defined $last 94 0 94
119 94 ▶ ${$mail->{header}->{$last}}[$#{$mail->{header}->{$last}}] .= $_ if defined $last;
Branch: 1 branch
BranchTrueFalseTotal
if defined $last 94 0 94
120 }
121 }
122 elsif ($state eq 'body')
123 {
124 1348 ▶ s/^>(>*From )/$1/ if exists $mail->{mbox};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mail->{"mbox"} 912 436 1348
125 1348 $mail->{body} .= $_;
126 }
127 }
128  
129 140 ▶ $mail->{body} =~ s/\n\n\z/\n/ if $mail && exists $mail->{mbox} && exists $mail->{body};
Branch: 1 branch
BranchTrueFalseTotal
if $mail and exists $mail->{"mbox"} and exists $mail->{"body"} 20 120 140
Condition100%6/6
$mail and exists $mail->{"mbox"} and exists $mail->{"body"}
!ll&&!rl&&r
118220
$mail and exists $mail->{"mbox"}
!ll&&!rl&&r
811022
MC/DC100%3/3
$mail and exists $mail->{"mbox"} and exists $mail->{"body"}
$mail exists $mail->{"mbox"} exists $mail->{"body"}
Truth table100%4/4
A and B and C
A= $mailB= exists $mail->{"mbox"}C= exists $mail->{"body"}
ABCresult
0XX0
10X0
1100
1111
130 140 ▶ $act->(mime($mail, $parent)) if $mail;
Branch: 1 branch
BranchTrueFalseTotal
if $mail 132 8 140
131 }
132  
133 sub mail2str
134 272 ▶{
Subroutine mail2str: called CC=12 SCAR=24.8
Pod documented
135 272 my $mail = shift;
136 272 my $head = '';
137 272 ▶ $head .= $mail->{mbox} if exists $mail->{mbox};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mail->{"mbox"} 88 184 272
138 272 ▶ $head .= join '', @{$mail->{headers}} if exists $mail->{headers};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mail->{"headers"} 230 42 272
139 272 my $body = '';
140 272 ▶ $body .= $mail->{body} if exists $mail->{body};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mail->{"body"} 158 114 272
141 272 ▶ $body .= "$mail->{mime_preamble}" if exists $mail->{mime_preamble};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mail->{"mime_preamble"} 38 234 272
142 272 ▶ $body .= "--$mail->{mime_boundary}\n" if exists $mail->{mime_boundary} && !exists $mail->{mime_parts};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mail->{"mime_boundary"} and not exists $mail->{"mime_parts"} 2 270 272
Condition100%3/3
exists $mail->{"mime_boundary"} and not exists $mail->{"mime_parts"}
!ll&&!rl&&r
200702
MC/DC100%2/2
exists $mail->{"mime_boundary"} and not exists $mail->{"mime_parts"}
exists $mail->{"mime_boundary"} not exists $mail->{"mime_parts"}
Truth table100%3/3
A and not(B)
A= exists $mail->{"mime_boundary"}B= not exists $mail->{"mime_parts"}
ABresult
0X0
100
111
143 272 ▶ $body .= join('', map { "--$mail->{mime_boundary}\n" . mail2str($_) } @{$mail->{mime_parts}}) if exists $mail->{mime_parts};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mail->{"mime_parts"} 70 202 272
144 272 ▶ $body .= "--$mail->{mime_boundary}--\n" if exists $mail->{mime_boundary};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mail->{"mime_boundary"} 72 200 272
145 272 ▶ $body .= "$mail->{mime_epilogue}" if exists $mail->{mime_epilogue};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mail->{"mime_epilogue"} 16 256 272
146 272 ▶ $body .= mail2str($mail->{mime_message}) if exists $mail->{mime_message};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mail->{"mime_message"} 34 238 272
147 272 ▶ $body =~ s/^(>*From )/>$1/mg, $body =~ s/([^\n])\n?\z/$1\n\n/ if exists $mail->{mbox};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mail->{"mbox"} 88 184 272
148 272 return $head . "\n" . $body;
149 }
150  
151 2 my $bchar = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'()+_,-.\/:=?";
152 sub mail2multipart
153 24 ▶{
Subroutine mail2multipart: called CC=12 SCAR=25.0
Pod documented
154 24 my $m = shift;
155 24 ▶ return $m if exists $m->{mime_type} && $m->{mime_type} =~ /^multipart\//i;
Branch: 1 branch
BranchTrueFalseTotal
if exists $m->{"mime_type"} and $m->{"mime_type"} =~ m[^multipart/]iu 12 12 24
Condition100%3/3
exists $m->{"mime_type"} and $m->{"mime_type"} =~ m[^multipart/]iu
!ll&&!rl&&r
8412
MC/DC100%2/2
exists $m->{"mime_type"} and $m->{"mime_type"} =~ m[^multipart/]iu
exists $m->{"mime_type"} $m->{"mime_type"} =~ m[^multipart/]iu
Truth table100%3/3
A and B
A= exists $m->{"mime_type"}B= $m->{"mime_type"} =~ m[^multipart/]iu
ABresult
0X0
100
111
156 12 my $p = {};
157 12 append_header($p, $_) for grep { /^content-/i } @{$m->{headers}};
158 12 ▶ $p->{body} = delete $m->{body} if exists $m->{body};
Branch: 1 branch
BranchTrueFalseTotal
if exists $m->{"body"} 8 4 12
159 12 ▶ $p->{mime_message} = delete $m->{mime_message} if exists $m->{mime_message};
Branch: 1 branch
BranchTrueFalseTotal
if exists $m->{"mime_message"} 4 8 12
160 12 ▶ $p->{mime_type} = $m->{mime_type} if exists $m->{mime_type};
Branch: 1 branch
BranchTrueFalseTotal
if exists $m->{"mime_type"} 4 8 12
161 12 $m->{mime_type} = 'multipart/mixed';
162 12 ▶ $m->{mime_boundary} = exists $m->{mime_prev_boundary} ? delete $m->{mime_prev_boundary} : join '', map { substr $bchar, int(rand(length $bchar)), 1 } 0..30;
Branch: 1 branch
BranchTrueFalseTotal
exists $m->{'mime_prev_boundary'} ? : 0 12 12
163 12 ▶ $m->{mime_preamble} = delete $m->{mime_prev_preamble} if exists $m->{mime_prev_preamble};
Branch: 1 branch
BranchTrueFalseTotal
if exists $m->{"mime_prev_preamble"} 0 12 12
164 12 ▶ $m->{mime_epilogue} = delete $m->{mime_prev_epilogue} if exists $m->{mime_prev_epilogue};
Branch: 1 branch
BranchTrueFalseTotal
if exists $m->{"mime_prev_epilogue"} 0 12 12
165 12 delete_header($m, qr/content-[^:]*/i);
166 12 ▶ append_header($m, 'MIME-Version: 1.0') unless exists $m->{header} && exists $m->{header}->{'mime-version'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $m->{"header"} and exists $m->{"header"}{"mime-version"} 4 8 12
Condition66%2/3
exists $m->{"header"} and exists $m->{"header"}{"mime-version"}
!ll&&!rl&&r
048
MC/DC50%1/2
exists $m->{"header"} and exists $m->{"header"}{"mime-version"}
exists $m->{"header"} exists $m->{"header"}{"mime-version"}
Truth table66%2/3
A and B
A= exists $m->{"header"}B= exists $m->{"header"}{"mime-version"}
ABresult
0X0
100
111
167 12 append_header($m, "Content-Type: $m->{mime_type}; boundary=\"$m->{mime_boundary}\"");
168 12 $m->{mime_parts} = [$p];
169 12 return $m;
170 }
171  
172 sub mail2singlepart
173 40 ▶{
Subroutine mail2singlepart: called CC=18 SCAR=29.0
Pod documented
174 40 my $m = shift;
175 40 ▶ $m->{mime_message} = mail2singlepart($m->{mime_message}), return $m if exists $m->{mime_type} && $m->{mime_type} =~ /^message\//i;
Branch: 1 branch
BranchTrueFalseTotal
if exists $m->{"mime_type"} and $m->{"mime_type"} =~ m[^message/]iu 4 36 40
Condition100%3/3
exists $m->{"mime_type"} and $m->{"mime_type"} =~ m[^message/]iu
!ll&&!rl&&r
16204
MC/DC100%2/2
exists $m->{"mime_type"} and $m->{"mime_type"} =~ m[^message/]iu
exists $m->{"mime_type"} $m->{"mime_type"} =~ m[^message/]iu
Truth table100%3/3
A and B
A= exists $m->{"mime_type"}B= $m->{"mime_type"} =~ m[^message/]iu
ABresult
0X0
100
111
176 36 ▶ return $m unless exists $m->{mime_type} && $m->{mime_type} =~ /^multipart\//i && @{$m->{mime_parts}} <= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless exists $m->{"mime_type"} and $m->{"mime_type"} =~ m[^multipart/]iu and @{$m->{"mime_parts"};} <= 1 20 16 36
Condition83%5/6
exists $m->{"mime_type"} and $m->{"mime_type"} =~ m[^multipart/]iu and @{$m->{"mime_parts"};} <= 1
!ll&&!rl&&r
16416
exists $m->{"mime_type"} and $m->{"mime_type"} =~ m[^multipart/]iu
!ll&&!rl&&r
16020
MC/DC66%2/3
exists $m->{"mime_type"} and $m->{"mime_type"} =~ m[^multipart/]iu and @{$m->{"mime_parts"};} <= 1
exists $m->{"mime_type"} $m->{"mime_type"} =~ m[^multipart/]iu @{$m->{"mime_parts"};} <= 1
Truth table75%3/4
A and B and C
A= exists $m->{"mime_type"}B= $m->{"mime_type"} =~ m[^multipart/]iuC= @{$m->{"mime_parts"};} <= 1
ABCresult
0XX0
10X0
1100
1111
177 16 my $p = shift @{$m->{mime_parts}};
178 16 ▶ $m->{mime_prev_boundary} = delete $m->{mime_boundary} if exists $m->{mime_boundary};
Branch: 1 branch
BranchTrueFalseTotal
if exists $m->{"mime_boundary"} 16 0 16
179 16 ▶ $m->{mime_prev_preamble} = delete $m->{mime_preamble} if exists $m->{mime_preamble};
Branch: 1 branch
BranchTrueFalseTotal
if exists $m->{"mime_preamble"} 8 8 16
180 16 ▶ $m->{mime_prev_epilogue} = delete $m->{mime_epilogue} if exists $m->{mime_epilogue};
Branch: 1 branch
BranchTrueFalseTotal
if exists $m->{"mime_epilogue"} 0 16 16
181 16 ▶ $m->{body} = $p->{body} if exists $p->{body};
Branch: 1 branch
BranchTrueFalseTotal
if exists $p->{"body"} 10 6 16
182 16 ▶ $m->{mime_message} = $p->{mime_message} if exists $p->{mime_message};
Branch: 1 branch
BranchTrueFalseTotal
if exists $p->{"mime_message"} 2 14 16
183 16 ▶ delete $m->{mime_type}; $m->{mime_type} = $p->{mime_type} if exists $p->{mime_type};
Branch: 1 branch
BranchTrueFalseTotal
if exists $p->{"mime_type"} 6 10 16
184 16 ▶ delete $m->{mime_parts}; $m->{mime_parts} = $p->{mime_parts} if exists $p->{mime_parts};
Branch: 1 branch
BranchTrueFalseTotal
if exists $p->{"mime_parts"} 4 12 16
185 16 ▶ $m->{mime_boundary} = $p->{mime_boundary} if exists $p->{mime_boundary};
Branch: 1 branch
BranchTrueFalseTotal
if exists $p->{"mime_boundary"} 4 12 16
186 16 ▶ $m->{mime_preamble} = $p->{mime_preamble} if exists $p->{mime_preamble};
Branch: 1 branch
BranchTrueFalseTotal
if exists $p->{"mime_preamble"} 0 16 16
187 16 ▶ $m->{mime_epilogue} = $p->{mime_epilogue} if exists $p->{mime_epilogue};
Branch: 1 branch
BranchTrueFalseTotal
if exists $p->{"mime_epilogue"} 0 16 16
188 16 my $explicit = 0;
189 16 delete_header($m, qr/content-[^:]*/i);
190 16 append_header($m, $_), ++$explicit for grep { /^content-/i } @{$p->{headers}};
191 16 ▶ delete_header($m, 'mime-version') unless $explicit;
Branch: 1 branch
BranchTrueFalseTotal
unless $explicit 2 14 16
192 16 return mail2singlepart($m);
193 }
194  
195 sub mail2mbox
196 58 ▶{
Subroutine mail2mbox: called CC=5 SCAR=16.3
Pod documented
197 58 my $m = shift;
198 58 ▶ return $m if exists $m->{mbox};
Branch: 1 branch
BranchTrueFalseTotal
if exists $m->{"mbox"} 38 20 58
199 20 my ($f) = header($m, 'sender');
200 20 ▶ ($f) = header($m, 'from') unless defined $f;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f 20 0 20
201 20 ▶ $f =~ s/"(?:\\[^\r\n]|[^\\"])*"//g, $f =~ s/\s*;.*//, $f =~s/^[^:]+:\s*//, $f =~ s/\s*,.*$//, $f =~ s/^[^<]*<\s*//, $f =~ s/\s*>.*$// if defined $f;
Branch: 1 branch
BranchTrueFalseTotal
if defined $f 20 0 20
202 20 ▶ $f = 'unknown' unless defined $f;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f 0 20 20
203 2 ▶ use POSIX; $m->{mbox} = "From $f " . ctime(time());
Subroutine BEGIN: called CC=1 SCAR=0.0
204 20 return $m;
205 }
206  
207 sub insert_header
208 4 ▶{
Subroutine insert_header: called CC=1 SCAR=0.0
Pod documented
209 4 my ($m, $h, $l, $c) = @_;
210 4 $h = header_format($h, $l, $c);
211 4 my ($n) = $h =~ /^([^:]+):/;
212 4 unshift @{$m->{headers}}, $h;
213 4 unshift @{$m->{header}->{lc $n}}, $h;
214 }
215  
216 sub append_header
217 305 ▶{
Subroutine append_header: called CC=1 SCAR=0.0
Pod documented
218 305 my ($m, $h, $l, $c) = @_;
219 305 $h = header_format($h, $l, $c);
220 305 my ($n) = $h =~ /^([^:]+):/;
221 305 push @{$m->{headers}}, $h;
222 305 push @{$m->{header}->{lc $n}}, $h;
223 }
224  
225 sub replace_header
226 20 ▶{
Subroutine replace_header: called CC=3 SCAR=11.0
Pod documented
227 20 my ($m, $h, $l, $c) = @_;
228 20 $h = header_format($h, $l, $c);
229 20 my ($n) = $h =~ /^([^:]+):/;
230 20 ▶ my $seen = 0; @{$m->{headers}} = grep { defined $_ } map { /^\Q$n\E:/i ? $seen ? undef : do { ++$seen; $h } : $_ } @{$m->{headers}};
Branch: 2 branches
BranchTrueFalseTotal
/^\Q$n\E:/iu ? : 6 14 20
$seen ? : 0 6 6
231 20 splice @{$m->{header}->{lc $n}};
232 20 push @{$m->{header}->{lc $n}}, $h;
233 }
234  
235 sub delete_header
236 46 ▶{
Subroutine delete_header: called CC=8 SCAR=20.8
Pod documented
237 46 my ($m, $h, $r) = @_;
238 46 ▶ return undef unless exists $m->{header};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $m->{"header"} 2 44 46
239 44 @{$m->{headers}} = grep { !/^$h:/i } @{$m->{headers}};
240 44 delete $m->{header}->{$_} for grep { /^$h$/i } keys %{$m->{header}};
241 44 ▶ if ($r && exists $m->{mime_parts}) { delete_header($_, $h, $r) for @{$m->{mime_parts}} }
Branch: 1 branch
BranchTrueFalseTotal
if ($r and exists $m->{"mime_parts"}) 2 42 44
Condition100%3/3
$r and exists $m->{"mime_parts"}
!ll&&!rl&&r
3662
MC/DC100%2/2
$r and exists $m->{"mime_parts"}
$r exists $m->{"mime_parts"}
Truth table100%3/3
A and B
A= $rB= exists $m->{"mime_parts"}
ABresult
0X0
100
111
242 44 ▶ if ($r && exists $m->{mime_message}) { delete_header($m->{mime_message}, $h, $r) }
Branch: 1 branch
BranchTrueFalseTotal
if ($r and exists $m->{"mime_message"}) 2 42 44
Condition100%3/3
$r and exists $m->{"mime_message"}
!ll&&!rl&&r
3662
MC/DC100%2/2
$r and exists $m->{"mime_message"}
$r exists $m->{"mime_message"}
Truth table100%3/3
A and B
A= $rB= exists $m->{"mime_message"}
ABresult
0X0
100
111
243 }
244  
245 sub insert_part
246 2 ▶{
Subroutine insert_part: called CC=2 SCAR=7.1
Pod documented
247 2 my ($m, $p, $i) = @_;
248 2 ▶ splice @{$m->{mime_parts}}, $i || 0, 0, $p;
Condition50%1/2
$i || 0
l!l
20
MC/DC0%0/1
$i || 0
$i
Truth table50%1/2
A
A= $i
Aresult
11
00
249 }
250  
251 sub append_part
252 10 ▶{
Subroutine append_part: called CC=1 SCAR=0.0
Pod documented
253 10 my ($m, $p) = @_;
254 10 push @{$m->{mime_parts}}, $p;
255 }
256  
257 sub replace_part
258 2 ▶{
Subroutine replace_part: called CC=1 SCAR=0.0
Pod documented
259 2 my ($m, $p, $i) = @_;
260 2 splice @{$m->{mime_parts}}, $i, 1, $p;
261 }
262  
263 sub delete_part
264 2 ▶{
Subroutine delete_part: called CC=1 SCAR=0.0
Pod documented
265 2 my ($m, $i) = @_;
266 2 splice @{$m->{mime_parts}}, $i, 1;
267 }
268  
269 sub header
270 359 ▶{
Subroutine header: called CC=3 SCAR=11.0
Pod documented
271 359 my ($m, $h) = @_;
272 359 ▶ return () unless exists $m->{header} && exists $m->{header}->{lc $h};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $m->{"header"} and exists $m->{"header"}{lc $h} 102 257 359
Condition100%3/3
exists $m->{"header"} and exists $m->{"header"}{lc $h}
!ll&&!rl&&r
3666257
MC/DC100%2/2
exists $m->{"header"} and exists $m->{"header"}{lc $h}
exists $m->{"header"} exists $m->{"header"}{lc $h}
Truth table100%3/3
A and B
A= exists $m->{"header"}B= exists $m->{"header"}{lc $h}
ABresult
0X0
100
111
273 257 return map { s/\n\s+/ /g; header_display($_) =~ /^$h:\s*(.*)\s*$/i; $1 } @{$m->{header}->{lc $h}};
274 }
275  
276 sub headers
277 2 ▶{
Subroutine headers: called CC=2 SCAR=7.0
Pod documented
278 2 my $m = shift;
279 2 ▶ return () unless exists $m->{headers};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $m->{"headers"} 0 2 2
280 2 return map { s/\n\s+/ /g; header_display($_) =~ /^([\w-]+:.*)\s*$/; $1 } @{$m->{headers}};
281 }
282  
283 sub header_names
284 2 ▶{
Subroutine header_names: called CC=2 SCAR=7.0
Pod documented
285 2 my $m = shift;
286 2 ▶ return () unless exists $m->{header};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $m->{"header"} 0 2 2
287 2 return keys %{$m->{header}};
288 }
289  
290 2 my $encword = qr/=\?([^*?]+)(?:\*\w+)?\?(q|b)\?([^? ]+)\?=/i; # encoded words to display
291 sub header_display # rfc2047, rfc2231
292 273 ▶{
Subroutine header_display: called CC=5 SCAR=16.1
Pod undocumented
293 2 ▶ use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
294 return join '',
295 525 map { tr/ \t/ /s; $_ } # finally, squeeze multiple whitespace
296 525 map { tr/\x00-\x08\x0b-\x1f\x7f//d; $_ } # strip control characters
297 525 ▶ map { s/$encword/(defined Encode::find_encoding($1)) ? Encode::decode($1, (lc $2 eq 'q') ? decode_quoted_printable($3, 1) : decode_base64($3)) : $&/ieg; $_ } # decode encoded words if possible
Branch: 2 branches
BranchTrueFalseTotal
defined &Encode::find_encoding($1) ? : 29 0 29
lc $2 eq 'q' ? : 19 10 29
298 525 ▶ map { s/($encword)\s+($encword)/$1$5/g while /$encword\s+$encword/; $_ } # strip space between encoded words that we're about to decode
Branch: 1 branch
BranchTrueFalseTotal
/$encword\s+$encword/u and do { s/($encword)\s+($encword)/$1$5/gu } 10 525 535
299 273 ▶ map { s/\((?:\\[^\r\n]|[^\\()])*\)//g unless /^".*"$/; $_ } # strip (comments) outside "quoted strings"
Branch: 1 branch
BranchTrueFalseTotal
unless /^".*"$/u 399 126 525
300 split /("(?:\\[^\r\n]|[^\\"])*")/, shift; # split on "quoted strings"
301 }
302  
303 sub charsetof
304 87 ▶{
Subroutine charsetof: called CC=7 SCAR=20.5
Pod undocumented
305 87 my $s = shift;
306 87 ▶ return 'us-ascii' if !defined $s || $s =~ /^[\x00-\x7f]*$/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $s or $s =~ /^[\x00-\x7f]*$/u 54 33 87
Condition100%3/3
not defined $s or $s =~ /^[\x00-\x7f]*$/u
l!l&&r!l&&!r
183633
MC/DC100%2/2
not defined $s or $s =~ /^[\x00-\x7f]*$/u
not defined $s $s =~ /^[\x00-\x7f]*$/u
Truth table100%3/3
not(A) or B
A= not defined $sB= $s =~ /^[\x00-\x7f]*$/u
ABresult
1X1
011
000
307 #return 'utf-8' if $s =~ /^(?:[\x00-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf4][\x80-\xbf]{3})+$/; # This won't work until perl v5.38
308 33 ▶ return 'utf-8' if defined eval { Encode::decode 'UTF-8', $s, Encode::FB_CROAK };
Branch: 1 branch
BranchTrueFalseTotal
if defined eval { do { &Encode::decode("UTF-8", $s, 1) } } 1 32 33
309 32 ▶ return (defined $ENV{LANG} && $ENV{LANG} =~ /^.+\.(.+)$/) && $1 ne 'UTF-8' ? lc $1 : 'iso-8859-1'; # Make something up
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'LANG'} && $ENV{'LANG'} =~ /^.+\.(.+)$/u && $1 ne 'UTF-8' ? : 0 32 32
Condition33%2/6
defined $ENV{"LANG"} and $ENV{"LANG"} =~ /^.+\.(.+)$/u and $1 ne "UTF-8"
!ll&&!rl&&r
3200
defined $ENV{"LANG"} and $ENV{"LANG"} =~ /^.+\.(.+)$/u
!ll&&!rl&&r
3200
MC/DC0%0/3
defined $ENV{"LANG"} and $ENV{"LANG"} =~ /^.+\.(.+)$/u and $1 ne "UTF-8"
defined $ENV{"LANG"} $ENV{"LANG"} =~ /^.+\.(.+)$/u $1 ne "UTF-8"
Truth table25%1/4
A and B and C
A= defined $ENV{"LANG"}B= $ENV{"LANG"} =~ /^.+\.(.+)$/uC= $1 ne "UTF-8"
ABCresult
0XX0
10X0
1100
1111
310 }
311  
312 sub header_format # rfc2822, rfc2047
313 329 ▶{
Subroutine header_format: called CC=16 SCAR=28.4
Pod undocumented
314 329 my ($h, $l, $c) = @_;
315 329 $h =~ s/^\s+//, $h =~ s/\s+$//, $h =~ tr/ \t\n\r/ /s;
316 2 ▶ use Encode (); $h = Encode::encode('UTF-8', $h) if grep { ord > 255 } split //, $h;
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if grep {ord $_ > 255;} split(//u, $h, 0) 1 328 329
317 329 ▶ $h = join ' ', map { /^".*"$/ ? $_ : !tr/\x80-\xff// ? $_ : tr/a-zA-Z0-9!*\/+-//c > length >> 1 ? join(' ', map { '=?' . ($c || charsetof($h)) . ($l ? "*$l" : '') . '?b?' . substr(encode_base64($_), 0, -1) . '?=' } (split /\n/, (s/([^\r\n]{38})/$1\n/g, $_))) : join(' ', map { '=?' . ($c || charsetof($h)) . ($l ? "*$l" : '') . '?q?' . substr(encode_quoted_printable($_, 1), 0, -1) . '?=' } (split /\n/, (s/([^\r\n]{17})/$1\n/g, $_))) } map { /^[^\s"]*".*"[^\s"]*$/ ? $_ : split / / } split /(\S*"(?:\\[^\r\n]|[^\\"])*"\S*)/, $h;
Branch: 6 branches
BranchTrueFalseTotal
/^".*"$/u ? : 0 1023 1023
!tr/\200-\377// ? : 1012 11 1023
tr[!*+\-/-9A-Za-z][]c > length($_) >> 1 ? : 4 7 11
$l ? : 0 6 6
$l ? : 0 13 13
/^[^\s"]*".*"[^\s"]*$/u ? : 45 347 392
Condition33%2/6
$c || charsetof($h)
l!l&&r!l&&!r
060
$c || charsetof($h)
l!l&&r!l&&!r
0130
MC/DC0%0/2
$c || charsetof($h)
$c charsetof($h)
MC/DC0%0/2
$c || charsetof($h)
$c charsetof($h)
Truth table33%1/3
A || B
A= $cB= charsetof($h)
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $cB= charsetof($h)
ABresult
1X1
011
000
318 329 ▶ my ($f, $p, $lf) = ('', 0); $lf = length $f, $f .= ($lf && $lf + ($lf ? 1 : 0) + length($_) - $p > 78) ? ($p = $lf, "\n") : '', $f .= $f ? ' ' : '', $f .= $_ for map { /^\S*".*"\S*$/ ? $_ : grep { length } split / / } split /(\S*"(?:\\[^\r\n]|[^\\"\r\n])*"\S*)/, $h; # fold
Branch: 4 branches
BranchTrueFalseTotal
/^\S*".*"\S*$/u ? : 45 347 392
$lf && $lf + ($lf ? 1 : 0) + length($_) - $p > 78 ? : 45 978 1023
$lf ? : 694 0 694
$f ? : 694 329 1023
Condition100%3/3
$lf and $lf + ($lf ? 1 : 0) + length($_) - $p > 78
!ll&&!rl&&r
32964945
MC/DC100%2/2
$lf and $lf + ($lf ? 1 : 0) + length($_) - $p > 78
$lf $lf + ($lf ? 1 : 0) + length($_) - $p > 78
Truth table100%3/3
A and B
A= $lfB= $lf + ($lf ? 1 : 0) + length($_) - $p > 78
ABresult
0X0
100
111
319 329 return $f . "\n";
320 }
321  
322 sub param # rfc2231, rfc2045
323 80 ▶{
Subroutine param: called CC=7 SCAR=19.5
Pod documented
324 80 my ($m, $h, $p) = @_;
325 80 my @p; my $decode = 0;
326  
327 80 for (header($m, $h))
328 {
329 80 ▶ while (/(\b\Q$p\E(?:\*|\*\d\*?)?)=("(?:\\[^\n]|[^"\n])*"|[^\x00-\x20()<>@,;:\\"\/\[\]?=]+)/ig)
Branch: 1 branch
BranchTrueFalseTotal
if (m((\b\Q$p\E(?:\*|\*\d\*?)?)=("(?:\\[^\n]|[^"\n])*"|[^\x00-\x20()<>\@,;:\\"/\[\]?=]+))giu) 98 80 178
330 {
331 98 my ($n, $v) = ($1, $2);
332 98 ▶ $v =~ s/^"//, $v =~ s/"$//, $v =~ s/\\(.)/$1/g if $v =~ /^".*"$/;
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /^".*"$/u 50 48 98
333 98 ▶ $v =~ s/^(?:us-ascii|utf-8|iso-8859-\d{1,2})'\w+'//i and $decode = 1;
Branch: 1 branch
BranchTrueFalseTotal
$v =~ s/^(?:us-ascii|utf-8|iso-8859-\d{1,2})'\w+'//iu and $decode = 1 8 90 98
334 98 ▶ $v =~ s/%([\da-fA-f]{2})/chr hex $1/eg if $decode && substr($n, -1) eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $decode and substr($n, -1) eq "*" 16 82 98
Condition100%3/3
$decode and substr($n, -1) eq "*"
!ll&&!rl&&r
80216
MC/DC100%2/2
$decode and substr($n, -1) eq "*"
$decode substr($n, -1) eq "*"
Truth table100%3/3
A and B
A= $decodeB= substr($n, -1) eq "*"
ABresult
0X0
100
111
335 98 push @p, [lc $n, $v];
336 }
337 }
338  
339 80 return join '', map { $_->[1] } sort { my ($ad) = $a->[0] =~ /(\d+)/; my ($bd) = $b->[0] =~ /(\d+)/; $ad <=> $bd } @p;
340 }
341  
342 sub mimetype # rfc2045, rfc2046
343 100 ▶{
Subroutine mimetype: called CC=9 SCAR=22.0
Pod documented
344 100 my ($m, $p) = @_;
345 100 my ($e) = header($m, 'content-transfer-encoding');
346 100 ▶ return 'application/octet-stream' if defined $e && $e !~ /^(?:[78]bit|binary|quoted-printable|base64)$/i;
Branch: 1 branch
BranchTrueFalseTotal
if defined $e and not $e =~ /^(?:[78]bit|binary|quoted-printable|base64)$/iu 2 98 100
Condition100%3/3
defined $e and not $e =~ /^(?:[78]bit|binary|quoted-printable|base64)$/iu
!ll&&!rl&&r
56422
MC/DC100%2/2
defined $e and not $e =~ /^(?:[78]bit|binary|quoted-printable|base64)$/iu
defined $e not $e =~ /^(?:[78]bit|binary|quoted-printable|base64)$/iu
Truth table100%3/3
A and not(B)
A= defined $eB= not $e =~ /^(?:[78]bit|binary|quoted-printable|base64)$/iu
ABresult
0X0
100
111
347 98 my ($type) = header($m, 'content-type');
348 98 ▶ return lc $1 if defined $type && $type =~ /^((?:text|image|audio|video|application|message|multipart)\/[^\s;]+)/i;
Branch: 1 branch
BranchTrueFalseTotal
if defined $type and $type =~ m[^((?:text|image|audio|video|application|message|multipart)/[^\s;]+)]iu 76 22 98
Condition100%3/3
defined $type and $type =~ m[^((?:text|image|audio|video|application|message|multipart)/[^\s;]+)]iu
!ll&&!rl&&r
20276
MC/DC100%2/2
defined $type and $type =~ m[^((?:text|image|audio|video|application|message|multipart)/[^\s;]+)]iu
defined $type $type =~ m[^((?:text|image|audio|video|application|message|multipart)/[^\s;]+)]iu
Truth table100%3/3
A and B
A= defined $typeB= $type =~ m[^((?:text|image|audio|video|application|message|multipart)/[^\s;]+)]iu
ABresult
0X0
100
111
349 22 ▶ return 'message/rfc822' if !defined $type && defined $p && exists $p->{mime_type} && $p->{mime_type} =~ /^multipart\/digest/i;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $type and defined $p and exists $p->{"mime_type"} and $p->{"mime_type"} =~ m[^multipart/digest]iu 2 20 22
Condition77%7/9
not defined $type and defined $p and exists $p->{"mime_type"} and $p->{"mime_type"} =~ m[^multipart/digest]iu
!ll&&!rl&&r
2002
not defined $type and defined $p and exists $p->{"mime_type"}
!ll&&!rl&&r
2002
not defined $type and defined $p
!ll&&!rl&&r
2182
MC/DC50%2/4
not defined $type and defined $p and exists $p->{"mime_type"} and $p->{"mime_type"} =~ m[^multipart/digest]iu
not defined $type defined $p exists $p->{"mime_type"} $p->{"mime_type"} =~ m[^multipart/digest]iu
Truth table60%3/5
not(A) and B and C and D
A= not defined $typeB= defined $pC= exists $p->{"mime_type"}D= $p->{"mime_type"} =~ m[^multipart/digest]iu
ABCDresult
0XXX0
10XX0
110X0
11100
11111
350 20 return 'text/plain';
351 }
352  
353 sub encoding # rfc2045
354 22 ▶{
Subroutine encoding: called CC=5 SCAR=16.1
Pod documented
355 22 my $m = shift;
356 22 my ($e) = header($m, 'content-transfer-encoding');
357 22 ▶ return (defined $e && $e =~ /^([78]bit|binary|quoted-printable|base64)$/i) ? lc $1 : (exists $m->{body} && $m->{body} =~ tr/\x80-\xff//) ? '8bit' : '7bit';
Branch: 2 branches
BranchTrueFalseTotal
defined $e && $e =~ /^([78]bit|binary|quoted-printable|base64)$/iu ? : 12 10 22
exists $m->{'body'} && $m->{'body'} =~ tr/\200-\377// ? : 4 6 10
Condition83%5/6
defined $e and $e =~ /^([78]bit|binary|quoted-printable|base64)$/iu
!ll&&!rl&&r
6412
exists $m->{"body"} and $m->{"body"} =~ tr/\200-\377//
!ll&&!rl&&r
064
MC/DC100%2/2
defined $e and $e =~ /^([78]bit|binary|quoted-printable|base64)$/iu
defined $e $e =~ /^([78]bit|binary|quoted-printable|base64)$/iu
MC/DC50%1/2
exists $m->{"body"} and $m->{"body"} =~ tr/\200-\377//
exists $m->{"body"} $m->{"body"} =~ tr/\200-\377//
Truth table100%3/3
A and B
A= defined $eB= $e =~ /^([78]bit|binary|quoted-printable|base64)$/iu
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= exists $m->{"body"}B= $m->{"body"} =~ tr/\200-\377//
ABresult
0X0
100
111
358 }
359  
360 2 my $filename_counter;
361 sub filename # rfc2183, rfc2045?
362 4 ▶{
Subroutine filename: called CC=3 SCAR=12.0
Pod documented
363 4 my $p = shift;
364 4 ▶ my $fn = param($p, 'content-disposition', 'filename') || param($p, 'content-type', 'name') || 'attachment' . ++$filename_counter;
Condition40%2/5
param($p, 'content-disposition', 'filename') || param($p, 'content-type', 'name') || 'attachment' . ++$filename_counter
l!l
40
param($p, "content-disposition", "filename") or param($p, "content-type", "name")
l!l&&r!l&&!r
400
MC/DC0%0/2
param($p, 'content-disposition', 'filename') || param($p, 'content-type', 'name') || 'attachment' . ++$filename_counter
param($p, "content-disposition", "filename") param($p, "content-type", "name")
Truth table33%1/3
A or B
A= param($p, "content-disposition", "filename")B= param($p, "content-type", "name")
ABresult
1X1
011
000
365 4 $fn =~ s/^.*[\\\/]//, $fn =~ tr/\x00-\x1f !"#\$%&'()*\/:;<=>?@[\\]^`{|}~\x7f/_/s;
366 4 return $fn;
367 }
368  
369 sub body
370 8 ▶{
Subroutine body: called CC=2 SCAR=6.9
Pod documented
371 8 my $m = shift;
372 8 ▶ return exists $m->{body} ? decode($m->{body}, encoding($m)) : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $m->{'body'} ? : 4 4 8
373 }
374  
375 sub message
376 6 ▶{
Subroutine message: called CC=2 SCAR=6.9
Pod documented
377 6 my $m = shift;
378 6 ▶ return exists $m->{mime_message} ? $m->{mime_message} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $m->{'mime_message'} ? : 2 4 6
379 }
380  
381 sub parts
382 12 ▶{
Subroutine parts: called CC=3 SCAR=11.0
Pod documented
383 12 my ($m, $p) = @_;
384 12 ▶ return exists $m->{mime_parts} ? [@{$m->{mime_parts}}] : [] unless defined $p;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $p 10 2 12
exists $m->{'mime_parts'} ? : 6 4 10
385 2 $m->{mime_parts} = [@{$p}];
386 }
387  
388 sub newparam # rfc2231, rfc2045
389 46 ▶{
Subroutine newparam: called CC=12 SCAR=24.9
Pod documented
390 46 my ($n, $v, $l, $c) = (@_, '', '');
391 46 my $high = $v =~ tr/\x80-\xff//;
392 46 my $ctrl = $v =~ tr/\x00-\x06\x0e-\x1f\x7f//;
393 46 ▶ my $enc = $high || $ctrl ? '*' : '';
Branch: 1 branch
BranchTrueFalseTotal
$high || $ctrl ? : 4 42 46
Condition66%2/3
$high or $ctrl
l!l&&r!l&&!r
4042
MC/DC50%1/2
$high or $ctrl
$high $ctrl
Truth table66%2/3
A or B
A= $highB= $ctrl
ABresult
1X1
011
000
394 46 ▶ $c = charsetof($v) if $enc && !$c;
Branch: 1 branch
BranchTrueFalseTotal
if $enc and not $c 4 42 46
Condition66%2/3
$enc and not $c
!ll&&!rl&&r
4204
MC/DC50%1/2
$enc and not $c
$enc not $c
Truth table66%2/3
A and not(B)
A= $encB= not $c
ABresult
0X0
100
111
395 46 ▶ $l = 'en' if $c && !$l;
Branch: 1 branch
BranchTrueFalseTotal
if $c and not $l 2 44 46
Condition100%3/3
$c and not $l
!ll&&!rl&&r
4222
MC/DC100%2/2
$c and not $l
$c not $l
Truth table100%3/3
A and not(B)
A= $cB= not $l
ABresult
0X0
100
111
396 46 ▶ $v = "$c'$l'$v" if $enc;
Branch: 1 branch
BranchTrueFalseTotal
if $enc 4 42 46
397 46 ▶ my @p; push @p, $_ while $_ = substr $v, 0, 40, '';
Branch: 1 branch
BranchTrueFalseTotal
$_ = substr($v, 0, 40, '') and do { push @p, $_ } 58 46 104
398 46 s/([\x00-\x20\x7f-\xff])/sprintf '%%%02X', ord $1/eg for grep { tr/\x00-\x06\x0e-\x1f\x7f-\xff// } @p;
399 46 s/"/\\"/g, s/^/"/g, s/$/"/g for grep { tr/\x00-\x06\x0e-\x1f\x7f ()<>@,;:\\"\/[]?=// } @p;
400 46 ▶ return "; $n$enc=$p[0]" if @p == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @p == 1 40 6 46
401 6 return join '', map { "; $n*$_$enc=$p[$_]" } 0..$#p;
402 }
403  
404 my $messageid_counter;
405 sub newmail # rfc2822, rfc2045, rfc2046, rfc2183 (also rfc3282, rfc3066, rfc2424, rfc2557, rfc2110, rfc3297, rfc2912, rfc2533, rfc1864)
406 64 ▶{
Subroutine newmail: called CC=58 SCAR=43.6
Pod documented
407 64 my @a = @_; my %a = @_; my $m = {};
408 2 ▶ sub rfc822date { use POSIX; return strftime '%a, %d %b %Y %H:%M:%S +0000', gmtime shift; }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine rfc822date: called CC=1 SCAR=0.0
Pod undocumented
409 64 ▶ my $type = $a{type} || (exists $a{parts} ? 'multipart/mixed' : exists $a{message} ? 'message/rfc822' : 'text/plain');
Branch: 2 branches
BranchTrueFalseTotal
exists $a{'parts'} ? : 4 58 62
exists $a{'message'} ? : 12 46 58
Condition66%2/3
$a{'type'} || (exists $a{'parts'} ? 'multipart/mixed' : (exists $a{'message'} ? 'message/rfc822' : 'text/plain'))
l!l&&r!l&&!r
2620
MC/DC0%0/2
$a{'type'} || (exists $a{'parts'} ? 'multipart/mixed' : (exists $a{'message'} ? 'message/rfc822' : 'text/plain'))
$a{'type'} (exists $a{'parts'} ? 'multipart/mixed' : (exists $a{'message'} ? 'message/rfc822' : 'text/plain'))
Truth table66%2/3
A || B
A= $a{'type'}B= (exists $a{'parts'} ? 'multipart/mixed' : (exists $a{'message'} ? 'message/rfc822' : 'text/plain'))
ABresult
1X1
011
000
410 64 my $multi = $type =~ /^multipart\//i;
411 64 my $msg = $type =~ /^message\/rfc822$/i;
412 64 ▶ if (exists $a{filename} && !exists $a{body} && !exists $a{message} && !exists $a{parts} && -r $a{filename} && stat($a{filename}) && open my $fh, '<', $a{filename})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $a{"filename"} and not exists $a{"body"} and not exists $a{"message"} and not exists $a{"parts"} and -r $a{"filename"} and stat $a{"filename"} and open my $fh, "<", $a{"filename"}) 2 62 64
Condition72%13/18
exists $a{"filename"} and not exists $a{"body"} and not exists $a{"message"} and not exists $a{"parts"} and -r $a{"filename"} and stat $a{"filename"} and open my $fh, "<", $a{"filename"}
!ll&&!rl&&r
6202
exists $a{"filename"} and not exists $a{"body"} and not exists $a{"message"} and not exists $a{"parts"} and -r $a{"filename"} and stat $a{"filename"}
!ll&&!rl&&r
6202
exists $a{"filename"} and not exists $a{"body"} and not exists $a{"message"} and not exists $a{"parts"} and -r $a{"filename"}
!ll&&!rl&&r
6202
exists $a{"filename"} and not exists $a{"body"} and not exists $a{"message"} and not exists $a{"parts"}
!ll&&!rl&&r
6202
exists $a{"filename"} and not exists $a{"body"} and not exists $a{"message"}
!ll&&!rl&&r
6202
exists $a{"filename"} and not exists $a{"body"}
!ll&&!rl&&r
5482
MC/DC28%2/7
exists $a{"filename"} and not exists $a{"body"} and not exists $a{"message"} and not exists $a{"parts"} and -r $a{"filename"} and stat $a{"filename"} and open my $fh, "<", $a{"filename"}
exists $a{"filename"} not exists $a{"body"} not exists $a{"message"} not exists $a{"parts"} -r $a{"filename"} stat $a{"filename"} open my $fh, "<", $a{"filename"}
Truth table37%3/8
A and not(B) and not(C) and not(D) and E and F and G
A= exists $a{"filename"}B= not exists $a{"body"}C= not exists $a{"message"}D= not exists $a{"parts"}E= -r $a{"filename"}F= stat $a{"filename"}G= open my $fh, "<", $a{"filename"}
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
413 {
414 2 $a{body} = do { local $/; my $b = <$fh>; close $fh; $b };
415 2 ▶ $a{created} = (exists $a{created}) ? $a{created} : rfc822date((stat _)[9]);
Branch: 1 branch
BranchTrueFalseTotal
exists $a{'created'} ? : 0 2 2
416 2 ▶ $a{modified} = (exists $a{modified}) ? $a{modified} : rfc822date((stat _)[9]);
Branch: 1 branch
BranchTrueFalseTotal
exists $a{'modified'} ? : 0 2 2
417 2 ▶ $a{read} = (exists $a{read}) ? $a{read} : rfc822date((stat _)[8]);
Branch: 1 branch
BranchTrueFalseTotal
exists $a{'read'} ? : 0 2 2
418 2 $a{size} = (stat _)[7];
419 }
420 64 ▶ ($a{filename}) = $a{filename} =~ /([^\\\/]+)$/ if $a{filename};
Branch: 1 branch
BranchTrueFalseTotal
if $a{"filename"} 10 54 64
421 64 ▶ my $bound = $multi ? join '', map { substr $bchar, int(rand(length $bchar)), 1 } 0..30 : '';
Branch: 1 branch
BranchTrueFalseTotal
$multi ? : 6 58 64
422 64 ▶ my $disp = $a{disposition} || ($type =~ /^(?:text\/|message\/rfc822)/i ? 'inline' : 'attachment');
Branch: 1 branch
BranchTrueFalseTotal
$type =~ m[^(?:text/|message/rfc822)]iu ? : 58 6 64
Condition33%1/3
$a{'disposition'} || ($type =~ m[^(?:text/|message/rfc822)]iu ? 'inline' : 'attachment')
l!l&&r!l&&!r
0640
MC/DC0%0/2
$a{'disposition'} || ($type =~ m[^(?:text/|message/rfc822)]iu ? 'inline' : 'attachment')
$a{'disposition'} ($type =~ m[^(?:text/|message/rfc822)]iu ? 'inline' : 'attachment')
Truth table33%1/3
A || B
A= $a{'disposition'}B= ($type =~ m[^(?:text/|message/rfc822)]iu ? 'inline' : 'attachment')
ABresult
1X1
011
000
423 64 ▶ my $char = $a{charset} || charsetof($a{body});
Condition33%1/3
$a{'charset'} || charsetof($a{'body'})
l!l&&r!l&&!r
0640
MC/DC0%0/2
$a{'charset'} || charsetof($a{'body'})
$a{'charset'} charsetof($a{'body'})
Truth table33%1/3
A || B
A= $a{'charset'}B= charsetof($a{'body'})
ABresult
1X1
011
000
424 64 ▶ my $enc = $a{encoding} || ($multi || $msg ? '7bit' : $a{body} ? choose_encoding($a{body}) : '7bit');
Branch: 2 branches
BranchTrueFalseTotal
$multi || $msg ? : 18 46 64
$a{'body'} ? : 46 0 46
Condition66%4/6
$a{'encoding'} || ($multi || $msg ? '7bit' : ($a{'body'} ? choose_encoding($a{'body'}) : '7bit'))
l!l&&r!l&&!r
0640
$multi or $msg
l!l&&r!l&&!r
61246
MC/DC66%2/3
$a{'encoding'} || ($multi || $msg ? '7bit' : ($a{'body'} ? choose_encoding($a{'body'}) : '7bit'))
$a{'encoding'} $multi $msg
Truth table75%3/4
A || B or C
A= $a{'encoding'}B= $multiC= $msg
ABCresult
1XX1
01X1
0011
0000
425 64 ▶ append_header($m, $a[$_] . ': ' . $a[$_ + 1]) for grep { $_ % 2 == 0 && $a[$_] =~ /^[A-Z]/ } 0..$#a;
Condition100%3/3
$_ % 2 == 0 && $a[$_] =~ /^[A-Z]/u
!ll&&!rl&&r
1607486
MC/DC100%2/2
$_ % 2 == 0 && $a[$_] =~ /^[A-Z]/u
$_ % 2 == 0 $a[$_] =~ /^[A-Z]/u
Truth table100%3/3
A && B
A= $_ % 2 == 0B= $a[$_] =~ /^[A-Z]/u
ABresult
0X0
100
111
426 64 ▶ append_header($m, 'Date: ' . rfc822date(time)) if grep { /^(?:date|from|sender|reply-to)$/i } keys %a and !grep { /^date$/i } keys %a;
Branch: 1 branch
BranchTrueFalseTotal
if grep {/^(?:date|from|sender|reply-to)$/iu;} keys %a and not grep({/^date$/iu;} keys %a) 30 34 64
Condition66%2/3
grep {/^(?:date|from|sender|reply-to)$/iu;} keys %a and not grep({/^date$/iu;} keys %a)
!ll&&!rl&&r
34030
MC/DC50%1/2
grep {/^(?:date|from|sender|reply-to)$/iu;} keys %a and not grep({/^date$/iu;} keys %a)
grep {/^(?:date|from|sender|reply-to)$/iu;} keys %a not grep({/^date$/iu;} keys %a)
Truth table66%2/3
A and not(B)
A= grep {/^(?:date|from|sender|reply-to)$/iu;} keys %aB= not grep({/^date$/iu;} keys %a)
ABresult
0X0
100
111
427 64 ▶ append_header($m, 'MIME-Version: 1.0') if grep { /^(?:date|from|sender|reply-to)$/i } keys %a and !grep { /^mime-version$/ } keys %a;
Branch: 1 branch
BranchTrueFalseTotal
if grep {/^(?:date|from|sender|reply-to)$/iu;} keys %a and not grep({/^mime-version$/u;} keys %a) 30 34 64
Condition66%2/3
grep {/^(?:date|from|sender|reply-to)$/iu;} keys %a and not grep({/^mime-version$/u;} keys %a)
!ll&&!rl&&r
34030
MC/DC50%1/2
grep {/^(?:date|from|sender|reply-to)$/iu;} keys %a and not grep({/^mime-version$/u;} keys %a)
grep {/^(?:date|from|sender|reply-to)$/iu;} keys %a not grep({/^mime-version$/u;} keys %a)
Truth table66%2/3
A and not(B)
A= grep {/^(?:date|from|sender|reply-to)$/iu;} keys %aB= not grep({/^mime-version$/u;} keys %a)
ABresult
0X0
100
111
428 2 ▶ use Sys::Hostname; append_header($m, "Message-ID: <@{[time]}.$$.@{[++$messageid_counter]}\@@{[hostname]}>") if grep { /^(?:date|from|sender|reply-to)$/i } keys %a and !grep { /^message-id$/i } keys %a;
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if grep {/^(?:date|from|sender|reply-to)$/iu;} keys %a and not grep({/^message-id$/iu;} keys %a) 30 34 64
Condition66%2/3
grep {/^(?:date|from|sender|reply-to)$/iu;} keys %a and not grep({/^message-id$/iu;} keys %a)
!ll&&!rl&&r
34030
MC/DC50%1/2
grep {/^(?:date|from|sender|reply-to)$/iu;} keys %a and not grep({/^message-id$/iu;} keys %a)
grep {/^(?:date|from|sender|reply-to)$/iu;} keys %a not grep({/^message-id$/iu;} keys %a)
Truth table66%2/3
A and not(B)
A= grep {/^(?:date|from|sender|reply-to)$/iu;} keys %aB= not grep({/^message-id$/iu;} keys %a)
ABresult
0X0
100
111
429 64 ▶ append_header($m, "Content-Type: $type" . ($bound ? newparam('boundary', $bound) : '') . ($char =~ /^us-ascii$/i ? '' : newparam('charset', $char))) unless $type =~ /^text\/plain$/i && $char =~ /^us-ascii$/i;
Branch: 3 branches
BranchTrueFalseTotal
unless $type =~ m[^text/plain$]iu and $char =~ /^us-ascii$/iu 28 36 64
$bound ? : 6 22 28
$char =~ /^us-ascii$/iu ? : 18 10 28
Condition100%3/3
$type =~ m[^text/plain$]iu and $char =~ /^us-ascii$/iu
!ll&&!rl&&r
181036
MC/DC100%2/2
$type =~ m[^text/plain$]iu and $char =~ /^us-ascii$/iu
$type =~ m[^text/plain$]iu $char =~ /^us-ascii$/iu
Truth table100%3/3
A and B
A= $type =~ m[^text/plain$]iuB= $char =~ /^us-ascii$/iu
ABresult
0X0
100
111
430 64 ▶ append_header($m, "Content-Transfer-Encoding: $enc") unless $enc =~ /^7bit$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $enc =~ /^7bit$/iu 20 44 64
431 64 ▶ append_header($m, "Content-Disposition: $disp" . ($a{filename} ? newparam('filename', $a{filename}) : '') . ($a{size} ? newparam('size', $a{size}) : '') . ($a{created} ? newparam('creation-date', $a{created}) : '') . ($a{modified} ? newparam('modification-date', $a{modified}) : '') . ($a{read} ? newparam('read-date', $a{read}) : '')) if $a{filename} || $a{size} || $a{created} || $a{modified} || $a{read};
Branch: 6 branches
BranchTrueFalseTotal
if $a{"filename"} or $a{"size"} or $a{"created"} or $a{"modified"} or $a{"read"} 10 54 64
$a{'filename'} ? : 10 0 10
$a{'size'} ? : 2 8 10
$a{'created'} ? : 2 8 10
$a{'modified'} ? : 2 8 10
$a{'read'} ? : 2 8 10
Condition66%8/12
$a{"filename"} or $a{"size"} or $a{"created"} or $a{"modified"} or $a{"read"}
l!l&&r!l&&!r
10054
$a{"filename"} or $a{"size"} or $a{"created"} or $a{"modified"}
l!l&&r!l&&!r
10054
$a{"filename"} or $a{"size"} or $a{"created"}
l!l&&r!l&&!r
10054
$a{"filename"} or $a{"size"}
l!l&&r!l&&!r
10054
MC/DC20%1/5
$a{"filename"} or $a{"size"} or $a{"created"} or $a{"modified"} or $a{"read"}
$a{"filename"} $a{"size"} $a{"created"} $a{"modified"} $a{"read"}
Truth table33%2/6
A or B or C or D or E
A= $a{"filename"}B= $a{"size"}C= $a{"created"}D= $a{"modified"}E= $a{"read"}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
432 0 append_header($m, "Content-@{[ucfirst $_]}: $a{$_}") for grep { $a{$_} } qw(description language duration location base features alternative);
433 0 append_header($m, "Content-@{[uc $_]}: $a{$_}") for grep { $a{$_} } qw(id md5);
434 64 ▶ ($m->{mime_type}, $m->{mime_boundary}, $m->{mime_parts}) = ($type =~ /^\s*([\w\/.-]+)/, $bound, $a{parts} || []) if $multi;
Branch: 1 branch
BranchTrueFalseTotal
if $multi 6 58 64
Condition50%1/2
$a{'parts'} || []
l!l
60
MC/DC0%0/1
$a{'parts'} || []
$a{'parts'}
Truth table50%1/2
A
A= $a{'parts'}
Aresult
11
00
435 64 ▶ ($m->{mime_type}, $m->{mime_message}) = ($type =~ /^\s*([\w\/.-]+)/, $a{message} || {}) if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 12 52 64
Condition50%1/2
$a{'message'} || {}
l!l
120
MC/DC0%0/1
$a{'message'} || {}
$a{'message'}
Truth table50%1/2
A
A= $a{'message'}
Aresult
11
00
436 64 ▶ $m->{body} = encode($a{body} || '', $enc) unless $multi || $msg;
Branch: 1 branch
BranchTrueFalseTotal
unless $multi or $msg 46 18 64
Condition80%4/5
$multi or $msg
l!l&&r!l&&!r
61246
$a{'body'} || ''
l!l
460
MC/DC100%2/2
$multi or $msg
$multi $msg
MC/DC0%0/1
$a{'body'} || ''
$a{'body'}
Truth table100%3/3
A or B
A= $multiB= $msg
ABresult
1X1
011
000
Truth table50%1/2
A
A= $a{'body'}
Aresult
11
00
437 64 ▶ $m->{mbox} = $a{mbox} if exists $a{mbox} && defined $a{mbox} && length $a{mbox};
Branch: 1 branch
BranchTrueFalseTotal
if exists $a{"mbox"} and defined $a{"mbox"} and length $a{"mbox"} 0 64 64
Condition33%2/6
exists $a{"mbox"} and defined $a{"mbox"} and length $a{"mbox"}
!ll&&!rl&&r
6400
exists $a{"mbox"} and defined $a{"mbox"}
!ll&&!rl&&r
6400
MC/DC0%0/3
exists $a{"mbox"} and defined $a{"mbox"} and length $a{"mbox"}
exists $a{"mbox"} defined $a{"mbox"} length $a{"mbox"}
Truth table25%1/4
A and B and C
A= exists $a{"mbox"}B= defined $a{"mbox"}C= length $a{"mbox"}
ABCresult
0XX0
10X0
1100
1111
438 64 return $m;
439 }
440  
441 sub decode
442 4 ▶{
Subroutine decode: called CC=3 SCAR=11.1
Pod undocumented
443 4 my ($d, $e) = @_;
444 4 ▶ return $e =~ /^base64$/i ? decode_base64($d) : $e =~ /^quoted-printable$/i ? decode_quoted_printable($d) : substr($d, 0, -1);
Branch: 2 branches
BranchTrueFalseTotal
$e =~ /^base64$/iu ? : 2 2 4
$e =~ /^quoted-printable$/iu ? : 0 2 2
445 }
446  
447 sub encode
448 46 ▶{
Subroutine encode: called CC=3 SCAR=11.0
Pod undocumented
449 46 my ($d, $e) = @_;
450 46 ▶ return $e =~ /^base64$/i ? encode_base64($d) : $e =~ /^quoted-printable$/i ? encode_quoted_printable($d) : $d . "\n";
Branch: 2 branches
BranchTrueFalseTotal
$e =~ /^base64$/iu ? : 8 38 46
$e =~ /^quoted-printable$/iu ? : 12 26 38
451 }
452  
453 sub choose_encoding # rfc2822, rfc2045
454 46 ▶{
Subroutine choose_encoding: called CC=9 SCAR=22.3
Pod undocumented
455 46 my $len = length $_[0];
456 46 my $high = $_[0] =~ tr/\x80-\xff//;
457 46 my $ctrl = $_[0] =~ tr/\x00-\x06\x0e-\x1f\x7f//;
458 46 my ($maxlen, $pos, $next) = (0, 0, 0);
459  
460 46 ▶ for (; ($next = index($_[0], "\n", $pos)) != -1; $pos = $next + 1)
Branch: 1 branch
BranchTrueFalseTotal
if (($next = index($_[0], "\n", $pos)) != -1) 38 46 84
461 {
462 38 ▶ $maxlen = $next - $pos if $next - $pos > $maxlen;
Branch: 1 branch
BranchTrueFalseTotal
if $next - $pos > $maxlen 38 0 38
463 }
464  
465 46 ▶ $maxlen = $len - $pos if $len - $pos > $maxlen;
Branch: 1 branch
BranchTrueFalseTotal
if $len - $pos > $maxlen 8 38 46
466 46 ▶ return $ctrl ? 'base64' : $high ? $len > 1024 && $high > $len * 0.167 ? 'base64' : 'quoted-printable' : $maxlen > 998 ? 'quoted-printable' : '7bit';
Branch: 4 branches
BranchTrueFalseTotal
$ctrl ? : 8 38 46
$high ? : 10 28 38
$len > 1024 && $high > $len * 0.167 ? : 0 10 10
$maxlen > 998 ? : 2 26 28
Condition33%1/3
$len > 1024 and $high > $len * "0.167"
!ll&&!rl&&r
1000
MC/DC0%0/2
$len > 1024 and $high > $len * "0.167"
$len > 1024 $high > $len * "0.167"
Truth table33%1/3
A and B
A= $len > 1024B= $high > $len * "0.167"
ABresult
0X0
100
111
467 }
468  
469 sub encode_base64 # MIME::Base64 (Gisle Aas)
470 14 ▶{
Subroutine encode_base64: called CC=2 SCAR=6.9
Pod undocumented
471 14 pos $_[0] = 0; # Note: Text must be in canonical form (i.e. with "\r\n")
472 14 my $padlen = (3 - length($_[0]) % 3) % 3;
473 14 my $encoded = join '', map { pack('u', $_) =~ /^.(\S*)/ } $_[0] =~ /(.{1,45})/gs;
474 14 $encoded =~ tr{` -_}{AA-Za-z0-9+/};
475 14 ▶ $encoded =~ s/.{$padlen}$/'=' x $padlen/e if $padlen;
Branch: 1 branch
BranchTrueFalseTotal
if $padlen 12 2 14
476 14 $encoded =~ s/(.{1,76})/$1\n/g;
477 14 return $encoded;
478 }
479  
480 sub decode_base64 # MIME::Base64 (Gisle Aas)
481 12 ▶{
Subroutine decode_base64: called CC=1 SCAR=0.0
Pod undocumented
482 12 my $data = shift;
483 12 $data =~ tr{A-Za-z0-9+=/}{}cd;
484 12 $data =~ s/=+$//;
485 12 $data =~ tr{A-Za-z0-9+/}{ -_};
486 12 return join '', map { unpack('u', chr(32 + length($_) * 3 / 4) . $_) } $data =~ /(.{1,60})/gs;
487 }
488  
489 sub encode_quoted_printable
490 25 ▶{
Subroutine encode_quoted_printable: called CC=3 SCAR=11.0
Pod undocumented
491 25 my $quoted = shift;
492 25 my $qcode = shift;
493 25 ▶ my $binary = ($quoted =~ tr/\x00-\x06\x0e-\x1f\x7f//) ? '' : '\r\n';
Branch: 1 branch
BranchTrueFalseTotal
$quoted =~ tr/\000-\cF\cN-\037\177// ? : 0 25 25
494 25 $quoted =~ s/([^!-<>-~ \t$binary])/sprintf '=%02X', ord $1/eg;
495 25 ▶ $quoted =~ s/([?_])/sprintf '=%02X', ord $1/eg if $qcode;
Branch: 1 branch
BranchTrueFalseTotal
if $qcode 13 12 25
496 25 $quoted =~ s/((?:[^\r\n]{73,75})(?=[=])|(?:[^\r\n]{75}(?=[ \t]))|(?:[^\r\n]{75})(?=[^\r\n]{2})|(?:[^\r\n]{75})(?=[^\r\n]$))/$1=\n/g;
497 0 $quoted =~ s/([ \t])$/sprintf '=%02X', ord $1/emg;
498 # Python and mutt both behave as though this is wrong
499 #$quoted .= "=\n" unless $quoted =~ /\n$/;
500 25 $quoted .= "\n";
501 25 return $quoted;
502 }
503  
504 sub decode_quoted_printable
505 19 ▶{
Subroutine decode_quoted_printable: called CC=2 SCAR=7.0
Pod undocumented
506 19 my $quoted = shift;
507 19 my $qcode = shift;
508 19 $quoted =~ tr/\x00-\x08\x0b-\x0c\x0e-\x1f\x7f-\xff//d;
509 19 $quoted =~ s/=\n//g;
510 19 ▶ $quoted =~ s/_/ /g if $qcode;
Branch: 1 branch
BranchTrueFalseTotal
if $qcode 19 0 19
511 19 $quoted =~ s/=([0-9A-Fa-f]{2})/chr hex $1/eg;
512 19 return $quoted;
513 }
514  
515 2 my %mimetype =
516 (
517 txt => 'text/plain', csv => 'text/csv', htm => 'text/html', html => 'text/html', vcf => 'text/vcard', ics => 'text/calendar',
518 gif => 'image/gif', jpg => 'image/jpeg', jpeg => 'image/jpeg', jpe => 'image/jpeg', png => 'image/png', bmp => 'image/bmp', tiff => 'image/tiff', tif => 'image/tiff', jp2 => 'image/jp2', jpf => 'image/jpx', jpm => 'image/jpm',
519 mp2 => 'audio/mpeg', mp3 => 'audio/mpeg', au => 'audio/au', aif => 'audio/x-aiff', wav => 'audio/wav',
520 mpeg => 'video/mpeg', mpg => 'video/mpeg', mpe => 'video/mpeg', qt => 'video/quicktime', mov => 'video/quicktime', avi => 'video/x-msvideo', mj2 => 'video/mj2',
521 rtf => 'application/rtf', wri => 'application/vnd.ms-word', pdf => 'application/pdf', ps => 'application/ps', eps => 'application/ps', zip => 'application/zip', other => 'application/octet-stream',
522 doc => 'application/msword',
523 dot => 'application/msword',
524 docx => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
525 dotx => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
526 docm => 'application/vnd.ms-word.document.macroEnabled.12',
527 dotm => 'application/vnd.ms-word.template.macroEnabled.12',
528 xls => 'application/vnd.ms-excel',
529 xlt => 'application/vnd.ms-excel',
530 xla => 'application/vnd.ms-excel',
531 xlsx => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
532 xltx => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
533 xlsm => 'application/vnd.ms-excel.sheet.macroEnabled.12',
534 xltm => 'application/vnd.ms-excel.template.macroEnabled.12',
535 xlam => 'application/vnd.ms-excel.addin.macroEnabled.12',
536 xlsb => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
537 ppt => 'application/vnd.ms-powerpoint',
538 pot => 'application/vnd.ms-powerpoint',
539 pps => 'application/vnd.ms-powerpoint',
540 ppa => 'application/vnd.ms-powerpoint',
541 pptx => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
542 potx => 'application/vnd.openxmlformats-officedocument.presentationml.template',
543 ppsx => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
544 ppam => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
545 pptm => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
546 potm => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
547 ppsm => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'
548 );
549  
550 2 my $add_mimetypes;
551 sub add_mimetypes
552 62 ▶{
Subroutine add_mimetypes: called CC=7 SCAR=32.8
Pod undocumented
553 62 ▶ return if $add_mimetypes++;
Branch: 1 branch
BranchTrueFalseTotal
if $add_mimetypes++ 60 2 62
554 2 ▶ open my $fh, '<', '/etc/mime.types' or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", "/etc/mime.types" or return 0 2 2
555  
556 0 ▶ while (<$fh>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
557 {
558 0 ▶ s/#.*$//, s/^\s+//, s/\s+$//; next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 0 0
559 0 ▶ my ($mimetype, $ext) = /^(\S+)\s+(.*)$/; next unless $ext;
Branch: 1 branch
BranchTrueFalseTotal
unless $ext 0 0 0
560 0 $mimetype{$_} = $mimetype for split /\s+/, $ext;
561 }
562  
563 0 close $fh;
564 }
565  
566 sub tnef2mime
567 62 ▶{
Subroutine tnef2mime: called CC=6 SCAR=18.3
Pod undocumented
568 62 my $m = shift;
569 62 ▶ return $m unless exists $m->{mime_type} && $m->{mime_type} =~ /^multipart\//i && exists $m->{mime_parts};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $m->{"mime_type"} and $m->{"mime_type"} =~ m[^multipart/]iu and exists $m->{"mime_parts"} 2 60 62
Condition50%3/6
exists $m->{"mime_type"} and $m->{"mime_type"} =~ m[^multipart/]iu and exists $m->{"mime_parts"}
!ll&&!rl&&r
0260
exists $m->{"mime_type"} and $m->{"mime_type"} =~ m[^multipart/]iu
!ll&&!rl&&r
0062
MC/DC33%1/3
exists $m->{"mime_type"} and $m->{"mime_type"} =~ m[^multipart/]iu and exists $m->{"mime_parts"}
exists $m->{"mime_type"} $m->{"mime_type"} =~ m[^multipart/]iu exists $m->{"mime_parts"}
Truth table50%2/4
A and B and C
A= exists $m->{"mime_type"}B= $m->{"mime_type"} =~ m[^multipart/]iuC= exists $m->{"mime_parts"}
ABCresult
0XX0
10X0
1100
1111
570 60 add_mimetypes();
571 60 ▶ @{$m->{mime_parts}} = grep { defined $_ } map { (mimetype($_) =~ /^application\/ms-tnef/i && filename($_) =~ /winmail\.dat$/i) ? winmail($_) : $_ } @{$m->{mime_parts}};
Branch: 1 branch
BranchTrueFalseTotal
mimetype($_) =~ m[^application/ms-tnef]iu && filename($_) =~ /winmail\.dat$/iu ? : 2 88 90
Condition66%2/3
mimetype($_) =~ m[^application/ms-tnef]iu and filename($_) =~ /winmail\.dat$/iu
!ll&&!rl&&r
8802
MC/DC50%1/2
mimetype($_) =~ m[^application/ms-tnef]iu and filename($_) =~ /winmail\.dat$/iu
mimetype($_) =~ m[^application/ms-tnef]iu filename($_) =~ /winmail\.dat$/iu
Truth table66%2/3
A and B
A= mimetype($_) =~ m[^application/ms-tnef]iuB= filename($_) =~ /winmail\.dat$/iu
ABresult
0X0
100
111
572 60 return $m;
573 }
574  
575 18 ▶sub MESSAGE { 1 }
Subroutine MESSAGE: called CC=1 SCAR=0.0
Pod undocumented
576 2 ▶sub ATTACHMENT { 2 }
Subroutine ATTACHMENT: called CC=1 SCAR=0.0
Pod undocumented
577 2 ▶sub MESSAGE_CLASS { 0x00078008 }
Subroutine MESSAGE_CLASS: called CC=1 SCAR=0.0
Pod undocumented
578 0 ▶sub ATTACH_ATTACHMENT { 0x00069005 }
Subroutine ATTACH_ATTACHMENT: not called CC=1 SCAR=6.9
Pod undocumented
579 0 ▶sub ATTACH_DATA { 0x0006800f }
Subroutine ATTACH_DATA: not called CC=1 SCAR=6.9
Pod undocumented
580 0 ▶sub ATTACH_FILENAME { 0x00018010 }
Subroutine ATTACH_FILENAME: not called CC=1 SCAR=6.9
Pod undocumented
581 0 ▶sub ATTACH_RENDDATA { 0x00069002 }
Subroutine ATTACH_RENDDATA: not called CC=1 SCAR=6.9
Pod undocumented
582 0 ▶sub ATTACH_MODIFIED { 0x00038013 }
Subroutine ATTACH_MODIFIED: not called CC=1 SCAR=6.9
Pod undocumented
583 2 my $data; my @attachment; my $attachment; my $pos; my $badtnef;
584  
585 sub winmail
586 2 ▶{
Subroutine winmail: called CC=10 SCAR=35.7
Pod undocumented
587 sub read_message_attribute
588 14 ▶ {
Subroutine read_message_attribute: called CC=5 SCAR=16.1
Pod undocumented
589 14 my $type = unpack 'C', substr $data, $pos, 1;
590 14 ▶ return 0 unless defined $type && $type == MESSAGE; ++$pos;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and $type == MESSAGE() 2 12 14
Condition66%2/3
defined $type and $type == MESSAGE()
!ll&&!rl&&r
0212
MC/DC50%1/2
defined $type and $type == MESSAGE()
defined $type $type == MESSAGE()
Truth table66%2/3
A and B
A= defined $typeB= $type == MESSAGE()
ABresult
0X0
100
111
591 12 my $id = unpack 'V', substr $data, $pos, 4; $pos += 4;
592 12 my $len = unpack 'V', substr $data, $pos, 4; $pos += 4;
593 12 ▶ ++$badtnef, return 0 if $pos + $len > length $data;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + $len > length $data 2 10 12
594 10 my $buf = substr $data, $pos, $len; $pos += $len;
595 10 my $chk = unpack 'v', substr $data, $pos, 2; $pos += 2;
596 10 my $tot = unpack '%16C*', $buf;
597 10 ▶ ++$badtnef unless $chk == $tot;
Branch: 1 branch
BranchTrueFalseTotal
unless $chk == $tot 0 10 10
598 10 return $chk == $tot;
599 }
600  
601 sub read_attribute_message_class
602 2 ▶ {
Subroutine read_attribute_message_class: called CC=6 SCAR=33.1
Pod undocumented
603 2 my $type = unpack 'C', substr $data, $pos, 1;
604 2 ▶ return unless defined $type && $type == MESSAGE;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and $type == MESSAGE() 2 0 2
Condition33%1/3
defined $type and $type == MESSAGE()
!ll&&!rl&&r
020
MC/DC0%0/2
defined $type and $type == MESSAGE()
defined $type $type == MESSAGE()
Truth table33%1/3
A and B
A= defined $typeB= $type == MESSAGE()
ABresult
0X0
100
111
605 0 my $id = unpack 'V', substr $data, $pos + 1, 4;
606 0 ▶ return unless $id == MESSAGE_CLASS; $pos += 5;
Branch: 1 branch
BranchTrueFalseTotal
unless $id == MESSAGE_CLASS() 0 0 0
607 0 my $len = unpack 'V', substr $data, $pos, 4; $pos += 4;
608 0 ▶ ++$badtnef, return if $pos + $len > length $data;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + $len > length $data 0 0 0
609 0 my $buf = substr $data, $pos, $len; $pos += $len;
610 0 my $chk = unpack 'v', substr $data, $pos, 2; $pos += 2;
611 0 my $tot = unpack '%16C*', $buf;
612 0 ▶ ++$badtnef unless $chk == $tot;
Branch: 1 branch
BranchTrueFalseTotal
unless $chk == $tot 0 0 0
613 }
614  
615 sub read_attachment_attribute
616 2 ▶ {
Subroutine read_attachment_attribute: called CC=19 SCAR=56.3
Pod undocumented
617 2 my $type = unpack 'C', substr $data, $pos, 1;
618 0 ▶ return 0 unless defined $type && $type == ATTACHMENT; ++$pos;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and $type == ATTACHMENT() 2 0 2
Condition33%1/3
defined $type and $type == ATTACHMENT()
!ll&&!rl&&r
020
MC/DC0%0/2
defined $type and $type == ATTACHMENT()
defined $type $type == ATTACHMENT()
Truth table33%1/3
A and B
A= defined $typeB= $type == ATTACHMENT()
ABresult
0X0
100
111
619 0 my $id = unpack 'V', substr $data, $pos, 4; $pos += 4;
620 0 ▶ ++$badtnef if $id == ATTACH_RENDDATA && @attachment && !exists $attachment->{body};
Branch: 1 branch
BranchTrueFalseTotal
if $id == ATTACH_RENDDATA() and @attachment and not exists $attachment->{"body"} 0 0 0
Condition0%0/6
$id == ATTACH_RENDDATA() and @attachment and not exists $attachment->{"body"}
!ll&&!rl&&r
000
$id == ATTACH_RENDDATA() and @attachment
!ll&&!rl&&r
000
MC/DC0%0/3
$id == ATTACH_RENDDATA() and @attachment and not exists $attachment->{"body"}
$id == ATTACH_RENDDATA() @attachment not exists $attachment->{"body"}
Truth table0%0/4
A and B and not(C)
A= $id == ATTACH_RENDDATA()B= @attachmentC= not exists $attachment->{"body"}
ABCresult
0XX0
10X0
1100
1111
621 0 ▶ push @attachment, $attachment = {} if $id == ATTACH_RENDDATA;
Branch: 1 branch
BranchTrueFalseTotal
if $id == ATTACH_RENDDATA() 0 0 0
622 0 my $len = unpack 'V', substr $data, $pos, 4; $pos += 4;
623 0 ▶ ++$badtnef, return 0 if $pos + $len > length $data;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + $len > length $data 0 0 0
624 0 my $buf = substr $data, $pos, $len; $pos += $len;
625 0 my $chk = unpack 'v', substr $data, $pos, 2; $pos += 2;
626 0 my $tot = unpack '%16C*', $buf;
627 0 ▶ ++$badtnef, return 0 unless $chk == $tot;
Branch: 1 branch
BranchTrueFalseTotal
unless $chk == $tot 0 0 0
628 0 ▶ $attachment->{body} = $buf, $attachment->{size} = length $buf if $id == ATTACH_DATA;
Branch: 1 branch
BranchTrueFalseTotal
if $id == ATTACH_DATA() 0 0 0
629 0 ▶ $buf =~ s/\x00+$//, $attachment->{filename} = $buf, $attachment->{type} = $mimetype{($attachment->{filename} =~ /\.([^.]+)$/) || 'other'} || 'application/octet-stream' if $id == ATTACH_FILENAME && !exists $attachment->{filename};
Branch: 1 branch
BranchTrueFalseTotal
if $id == ATTACH_FILENAME() and not exists $attachment->{"filename"} 0 0 0
Condition0%0/7
$id == ATTACH_FILENAME() and not exists $attachment->{"filename"}
!ll&&!rl&&r
000
$mimetype{$attachment->{'filename'} =~ /\.([^.]+)$/u or 'other'} || 'application/octet-stream'
l!l
00
$attachment->{'filename'} =~ /\.([^.]+)$/u || 'other'
l!l
00
MC/DC0%0/2
$id == ATTACH_FILENAME() and not exists $attachment->{"filename"}
$id == ATTACH_FILENAME() not exists $attachment->{"filename"}
MC/DC0%0/1
$mimetype{$attachment->{'filename'} =~ /\.([^.]+)$/u or 'other'} || 'application/octet-stream'
$mimetype{$attachment->{'filename'} =~ /\.([^.]+)$/u or 'other'}
MC/DC0%0/1
$attachment->{'filename'} =~ /\.([^.]+)$/u || 'other'
$attachment->{'filename'} =~ /\.([^.]+)$/u
Truth table0%0/3
A and not(B)
A= $id == ATTACH_FILENAME()B= not exists $attachment->{"filename"}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $mimetype{$attachment->{'filename'} =~ /\.([^.]+)$/u or 'other'}
Aresult
11
00
Truth table0%0/2
A
A= $attachment->{'filename'} =~ /\.([^.]+)$/u
Aresult
11
00
630 0 ▶ my $fname; $attachment->{filename} = $fname, $attachment->{type} = $mimetype{($attachment->{filename} =~ /\.([^.]+)$/) || 'other'} || 'application/octet-stream' if $id == ATTACH_ATTACHMENT && ($fname = realname($buf));
Branch: 1 branch
BranchTrueFalseTotal
if $id == ATTACH_ATTACHMENT() and $fname = realname($buf) 0 0 0
Condition0%0/7
$id == ATTACH_ATTACHMENT() and $fname = realname($buf)
!ll&&!rl&&r
000
$mimetype{$attachment->{'filename'} =~ /\.([^.]+)$/u or 'other'} || 'application/octet-stream'
l!l
00
$attachment->{'filename'} =~ /\.([^.]+)$/u || 'other'
l!l
00
MC/DC0%0/2
$id == ATTACH_ATTACHMENT() and $fname = realname($buf)
$id == ATTACH_ATTACHMENT() $fname = realname($buf)
MC/DC0%0/1
$mimetype{$attachment->{'filename'} =~ /\.([^.]+)$/u or 'other'} || 'application/octet-stream'
$mimetype{$attachment->{'filename'} =~ /\.([^.]+)$/u or 'other'}
MC/DC0%0/1
$attachment->{'filename'} =~ /\.([^.]+)$/u || 'other'
$attachment->{'filename'} =~ /\.([^.]+)$/u
Truth table0%0/3
A and B
A= $id == ATTACH_ATTACHMENT()B= $fname = realname($buf)
ABresult
0X0
100
111
Truth table0%0/2
A
A= $mimetype{$attachment->{'filename'} =~ /\.([^.]+)$/u or 'other'}
Aresult
11
00
Truth table0%0/2
A
A= $attachment->{'filename'} =~ /\.([^.]+)$/u
Aresult
11
00
631 0 ▶ use POSIX; sub word { unpack 'v', substr($_[0], $_[1] * 2, 2) }
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine word: not called CC=1 SCAR=0.2
Pod undocumented
632 0 ▶ $attachment->{modified} = strftime '%a, %d %b %Y %H:%M:%S +0000', gmtime mktime word($buf, 5), word($buf, 4), word($buf, 3), word($buf, 2), word($buf, 1) - 1, word($buf, 0) - 1900 if $id == ATTACH_MODIFIED;
Branch: 1 branch
BranchTrueFalseTotal
if $id == ATTACH_MODIFIED() 0 0 0
633 0 return 1;
634 }
635  
636 sub realname
637 0 ▶ {
Subroutine realname: not called CC=3 SCAR=24.8
Pod undocumented
638 0 my $buf = shift;
639 0 ▶ my $pos = index $buf, "\x1e\x00\x01\x30\x01"; return unless $pos >= 0; $pos += 8;
Branch: 1 branch
BranchTrueFalseTotal
unless $pos >= 0 0 0 0
640 0 my $len = unpack 'V', substr($buf, $pos, 4); $pos += 4;
641 0 ▶ my $name = substr($buf, $pos, $len) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $name = substr($buf, $pos, $len) or return 0 0 0
642 0 $name =~ s/\x00+$//;
643 0 return $name;
644 }
645  
646 2 my $m = shift;
647 2 add_mimetypes();
648 2 $pos = 0; $data = body($m); @attachment = (); $badtnef = 0;
649 2 my $signature = unpack 'V', substr($data, $pos, 4); $pos += 4;
650 2 ▶ return $m unless $signature == 0x223E9F78;
Branch: 1 branch
BranchTrueFalseTotal
unless $signature == 574529400 0 2 2
651 2 my $key = unpack 'v', substr($data, $pos, 2); $pos += 2;
652 2 my $type = unpack 'C', substr($data, $pos, 1);
653 2 ▶ return $m unless $type == MESSAGE || $type == ATTACHMENT;
Branch: 1 branch
BranchTrueFalseTotal
unless $type == MESSAGE() or $type == ATTACHMENT() 0 2 2
Condition33%1/3
$type == MESSAGE() or $type == ATTACHMENT()
l!l&&r!l&&!r
200
MC/DC0%0/2
$type == MESSAGE() or $type == ATTACHMENT()
$type == MESSAGE() $type == ATTACHMENT()
Truth table33%1/3
A or B
A= $type == MESSAGE()B= $type == ATTACHMENT()
ABresult
1X1
011
000
654 2 ▶ do {} while read_message_attribute();
Branch: 1 branch
BranchTrueFalseTotal
read_message_attribute() and do { do { () } } 10 2 12
655 2 read_attribute_message_class();
656 2 ▶ do {} while read_message_attribute();
Branch: 1 branch
BranchTrueFalseTotal
read_message_attribute() and do { do { () } } 0 2 2
657 2 ▶ do {} while read_attachment_attribute();
Branch: 1 branch
BranchTrueFalseTotal
read_attachment_attribute() and do { do { () } } 0 2 2
658 2 ▶ ++$badtnef if @attachment && !exists $attachment->{body};
Branch: 1 branch
BranchTrueFalseTotal
if @attachment and not exists $attachment->{"body"} 0 2 2
Condition33%1/3
@attachment and not exists $attachment->{"body"}
!ll&&!rl&&r
200
MC/DC0%0/2
@attachment and not exists $attachment->{"body"}
@attachment not exists $attachment->{"body"}
Truth table33%1/3
A and not(B)
A= @attachmentB= not exists $attachment->{"body"}
ABresult
0X0
100
111
659 0 ▶ return ($badtnef) ? $m : map { newmail(%{$_}) } @attachment;
Branch: 1 branch
BranchTrueFalseTotal
$badtnef ? : 2 0 2
660 }
661  
662 2 1;
663  
664 # vi:set ts=4 sw=4:
↑ Summary