Field/ParamVal.pm

filter: Statementstmt 95.4% 166 / 174 Branchbran 82.0% 82 / 100 Conditioncond 73.5% 39 / 53 MC/DCmcdc 46.4% 13 / 28 Subroutinesub 93.3% 14 / 15 Podpod 77.7% 7 / 9 totaltotal 84.7% 321 / 379 CC 73 SCAR 39.4
CC
73
Cov
88%
parse_params
70.2
stringify
4.0
rfc2231decode
3.6
CRAP 51.5
« Parser/Reader.pm ↑ Summary Entity.pm »
1 package MIME::Field::ParamVal;
2  
3 39 ▶use MIME::Words;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =head1 NAME
6  
7 MIME::Field::ParamVal - subclass of Mail::Field, for structured MIME fields
8  
9  
10 =head1 SYNOPSIS
11  
12 # Create an object for a content-type field:
13 $field = new Mail::Field 'Content-type';
14  
15 # Set some attributes:
16 $field->param('_' => 'text/html');
17 $field->param('charset' => 'us-ascii');
18 $field->param('boundary' => '---ABC---');
19  
20 # Same:
21 $field->set('_' => 'text/html',
22 'charset' => 'us-ascii',
23 'boundary' => '---ABC---');
24  
25 # Get an attribute, or undefined if not present:
26 print "no id!" if defined($field->param('id'));
27  
28 # Same, but use empty string for missing values:
29 print "no id!" if ($field->paramstr('id') eq '');
30  
31 # Output as string:
32 print $field->stringify, "\n";
33  
34  
35 =head1 DESCRIPTION
36  
37 This is an abstract superclass of most MIME fields. It handles
38 fields with a general syntax like this:
39  
40 Content-Type: Message/Partial;
41 number=2; total=3;
42 id="oc=jpbe0M2Yt4s@thumper.bellcore.com"
43  
44 Comments are supported I<between> items, like this:
45  
46 Content-Type: Message/Partial; (a comment)
47 number=2 (another comment) ; (yet another comment) total=3;
48 id="oc=jpbe0M2Yt4s@thumper.bellcore.com"
49  
50  
51 =head1 PUBLIC INTERFACE
52  
53 =over 4
54  
55 =cut
56  
57 #------------------------------
58  
59 39 require 5.001;
60  
61 # Pragmas:
62 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 39 ▶use re 'taint';
Subroutine BEGIN: called CC=1 SCAR=0.0
64 39 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
65  
66  
67 # Other modules:
68 39 ▶use Mail::Field;
Subroutine BEGIN: called CC=1 SCAR=0.0
69  
70 # Kit modules:
71 39 ▶use MIME::Tools qw(:config :msgs);
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 39 @ISA = qw(Mail::Field);
74  
75  
76 #------------------------------
77 #
78 # Public globals...
79 #
80 #------------------------------
81  
82 # The package version, both in 1.23 style *and* usable by MakeMaker:
83 39 $VERSION = "5.522";
84  
85  
86 #------------------------------
87 #
88 # Private globals...
89 #
90 #------------------------------
91  
92 # Pattern to match parameter names (like fieldnames, but = not allowed):
93 39 my $PARAMNAME = '[^\x00-\x1f\x80-\xff :;=()]+?';
94  
95 # Pattern to match the first value on the line:
96 39 my $FIRST = '[^\s\;"(\x00-\x1f\x80-\xff]*';
97  
98 # Pattern to match an RFC 2045 token:
99 #
100 # token = 1*<any (ASCII) CHAR except SPACE, CTLs, or tspecials>
101 #
102 39 my $TSPECIAL = '()<>@,;:\</[]?="';
103  
104 #" Fix emacs highlighting...
105  
106 39 my $TOKEN = '[^ \x00-\x1f\x80-\xff' . "\Q$TSPECIAL\E" . ']+';
107  
108 39 my $QUOTED_STRING = '"([^\\\\"]*(?:\\\\.(?:[^\\\\"]*))*)"';
109  
110 # Encoded token:
111 39 my $ENCTOKEN = "=\\?[^?;\"]*\\?[A-Za-z]\\?[^?;\"]+\\?=";
112  
113 # pattern to match comments
114 # (one that holds ; or " would hide a parameter from other readers)
115 39 my $COMMENT = '\([^();"]*\)';
116  
117 # Pattern to match spaces or comments:
118 39 my $SPCZ = '(?:\s|' . $COMMENT . ')*';
119  
120 # Pattern to match non-semicolon as fallback for broken MIME
121 # produced by some viruses
122 39 my $BADTOKEN = '[^;]+';
123  
124 # Pattern to match whitespace allowed in header
125 39 my $WSP = '[\t\ ]';
126  
127 #------------------------------
128 #
129 # Class init...
130 #
131 #------------------------------
132  
133 #------------------------------
134  
135 =item set [\%PARAMHASH | KEY=>VAL,...,KEY=>VAL]
136  
137 I<Instance method.> Set this field.
138 The paramhash should contain parameter names
139 in I<all lowercase>, with the special C<"_"> parameter name
140 signifying the "default" (unnamed) parameter for the field:
141  
142 # Set up to be...
143 #
144 # Content-type: Message/Partial; number=2; total=3; id="ocj=pbe0M2"
145 #
146 $conttype->set('_' => 'Message/Partial',
147 'number' => 2,
148 'total' => 3,
149 'id' => "ocj=pbe0M2");
150  
151 Note that a single argument is taken to be a I<reference> to
152 a paramhash, while multiple args are taken to be the elements
153 of the paramhash themselves.
154  
155 Supplying undef for a hashref, or an empty set of values, effectively
156 clears the object.
157  
158 The self object is returned.
159  
160 =cut
161  
162 43189 ▶sub set {
Subroutine set: called CC=3 SCAR=11.4
Pod documented
163 43189 my $self = shift;
164 43189 ▶ my $params = ((@_ == 1) ? (shift || {}) : {@_});
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 43189 0 43189
Condition50%1/2
shift() or {}
l!l
431890
MC/DC0%0/1
shift() or {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
165 43189 %$self = %$params; # set 'em
166 43189 $self;
167 }
168  
169 #------------------------------
170  
171 =item parse_params STRING
172  
173 I<Class/instance utility method.>
174 Extract parameter info from a structured field, and return
175 it as a hash reference. For example, here is a field with parameters:
176  
177 Content-Type: Message/Partial;
178 number=2; total=3;
179 id="oc=jpbe0M2Yt4s@thumper.bellcore.com"
180  
181 Here is how you'd extract them:
182  
183 $params = $class->parse_params('content-type');
184 if ($$params{'_'} eq 'message/partial') {
185 $number = $$params{'number'};
186 $total = $$params{'total'};
187 $id = $$params{'id'};
188 }
189  
190 Like field names, parameter names are coerced to lowercase.
191 The special '_' parameter means the default parameter for the
192 field.
193  
194 B<NOTE:> This has been provided as a public method to support backwards
195 compatibility, but you probably shouldn't use it.
196  
197 =cut
198  
199 38 ▶sub rfc2231decode {
Subroutine rfc2231decode: called CC=3 SCAR=12.7
Pod undocumented
200 38 my($val) = @_;
201 38 my($enc, $lang, $rest);
202  
203 38 local($1,$2,$3);
204 38 ▶ if ($val =~ m/^([^']*)'([^']*)'(.*)\z/s) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ /^([^']*)'([^']*)'(.*)\z/s) { } 38 0 38
elsif ($val =~ /^([^']*)'([^']*)\z/s) { } 0 0 0
205 38 $enc = $1;
206 38 $lang = $2;
207 38 $rest = $3;
208 } elsif ($val =~ m/^([^']*)'([^']*)\z/s) {
209 0 $enc = $1;
210 0 $rest = $2;
211 } else {
212 0 $rest = $val;
213 # $enc remains undefined when charset/language info is missing
214 }
215 38 return ($enc, $lang, $rest);
216 }
217  
218 38 ▶sub rfc2231percent {
Subroutine rfc2231percent: called CC=1 SCAR=0.0
Pod undocumented
219 # Do percent-substitution
220 38 my($str) = @_;
221 38 local $1;
222 38 $str =~ s/%([0-9a-fA-F]{2})/pack("C", hex($1))/ge;
223 38 return $str;
224 }
225  
226 43121 ▶sub parse_params {
Subroutine parse_params: called CC=63 SCAR=42.5
Pod documented
227 43121 my ($self, $raw) = @_;
228 43121 my %params;
229 my %dup_params;
230 43121 my %empty_params;
231 43121 my %rfc2231params;
232 43121 my %rfc2231encoding_is_used;
233 43121 my $param;
234 43121 my $val;
235 43121 my $part;
236  
237 # Get raw field, and unfold it:
238 43121 ▶ defined($raw) or $raw = '';
Branch: 1 branch
BranchTrueFalseTotal
defined $raw or $raw = "" 28778 14343 43121
239 43121 $raw =~ s/\n//g;
240 43121 $raw =~ s/\s+\z//; # Strip trailing whitespace
241  
242 43121 local($1,$2,$3,$4,$5);
243 # Extract special first parameter:
244 43121 ▶ $raw =~ m/\A$SPCZ($FIRST)$SPCZ/og or return {}; # nada!
Branch: 1 branch
BranchTrueFalseTotal
$raw =~ /\A$SPCZ($FIRST)$SPCZ/go or return {} 43121 0 43121
245 43121 $params{'_'} = $1;
246  
247 43121 my $boundary_leftover = 0;
248 43121 my $saw_semicolon= 0;
249  
250 # Extract subsequent parameters.
251 # No, we can't just "split" on semicolons: they're legal in quoted strings!
252 43121 while (1) { # keep chopping away until done...
253 57199 $saw_semicolon = 0;
254 57199 ▶ $raw =~ m/\G([^;]*)(\;$SPCZ)+/ogc or last; # skip leading separator
Branch: 1 branch
BranchTrueFalseTotal
$raw =~ /\G([^;]*)(\;$SPCZ)+/cog or last 14185 43014 57199
255 14185 my $leftover = $1;
256 # a comment still open at this ";" hides it from other readers
257 14185 ▶ $params{'@unparsed_parameters'} = 1 if $leftover =~ /\([^)]*\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $leftover =~ /\([^)]*\z/ 9 14176 14185
258 # an odd '"' here makes readers that count quotes split elsewhere
259 14185 ▶ $params{'@unparsed_parameters'} = 1 if ($leftover =~ tr/"//) % 2;
Branch: 1 branch
BranchTrueFalseTotal
if $leftover =~ tr/"// % 2 18 14167 14185
260 14185 $saw_semicolon = 1;
261  
262 # the previous param was 'boundary' and we had leftover data
263 14185 ▶ if (defined($leftover) && length($leftover) > 0 && defined($param) && $param eq 'boundary') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $leftover and length $leftover > 0 and defined $param and $param eq "boundary") 0 14185 14185
Condition77%7/9
defined $leftover and length $leftover > 0 and defined $param and $param eq "boundary"
!ll&&!rl&&r
14167180
defined $leftover and length $leftover > 0 and defined $param
!ll&&!rl&&r
141521518
defined $leftover and length $leftover > 0
!ll&&!rl&&r
01415233
MC/DC0%0/4
defined $leftover and length $leftover > 0 and defined $param and $param eq "boundary"
defined $leftover length $leftover > 0 defined $param $param eq "boundary"
Truth table60%3/5
A and B and C and D
A= defined $leftoverB= length $leftover > 0C= defined $paramD= $param eq "boundary"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
264 0 $boundary_leftover = 1;
265 }
266  
267 14185 ▶ unless ($raw =~ m/\G($PARAMNAME)($COMMENT|$WSP)*=($COMMENT|$WSP)*/ogc) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($raw =~ /\G($PARAMNAME)($COMMENT|$WSP)*=($COMMENT|$WSP)*/cog) 107 14078 14185
268 # give up if not a param, noting if a later parameter is lost
269 107 ▶ $params{'@unparsed_parameters'} = 1 if substr($raw, pos($raw)) =~ /=/;
Branch: 1 branch
BranchTrueFalseTotal
if substr($raw, pos $raw) =~ /=/ 37 70 107
270 107 last;
271 }
272 14078 $param = lc($1);
273 14078 ▶ $raw =~ m/\G(?:$QUOTED_STRING|($ENCTOKEN)|($TOKEN)|($BADTOKEN)|())/gc or last;
Branch: 1 branch
BranchTrueFalseTotal
$raw =~ /\G(?:$QUOTED_STRING|($ENCTOKEN)|($TOKEN)|($BADTOKEN)|())/cg or last 14078 0 14078
274 14078 my ($qstr, $enctoken, $token, $badtoken, $empty_value) = ($1, $2, $3, $4, $5);
275 14078 ▶ if (defined($qstr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $qstr) 1139 12939 14078
276 # readers that count quotes take a final \" as escaped
277 1139 ▶ $params{'@unparsed_parameters'} = 1 if $qstr =~ /\\\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $qstr =~ /\\\z/ 10 1129 1139
278 # unescape
279 1139 $qstr =~ s/\\(.)/$1/g;
280 }
281 14078 ▶ if (defined($badtoken)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $badtoken) 11 14067 14078
282 # Strip leading/trailing whitespace from badtoken
283 11 $badtoken =~ s/^$WSP+//;
284 11 $badtoken =~ s/$WSP+\z//;
285  
286 # Only keep token parameters in badtoken;
287 # cut it off at the first non-token char. CPAN RT #105455
288 11 my $old_badtoken = $badtoken;
289 11 $badtoken =~ /^($TOKEN)*/;
290 11 $badtoken = $1;
291 11 ▶ if (defined($badtoken)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $badtoken) 0 11 11
292 # Cut it off at first whitespace too
293 0 $badtoken =~ s/\s.*//;
294 }
295  
296 # there was a leftover after the last valid token
297 11 ▶ if ($param eq 'boundary') {
Branch: 1 branch
BranchTrueFalseTotal
if ($param eq "boundary") 6 5 11
298 6 ▶ $boundary_leftover = 1 if defined($badtoken) && $badtoken ne $old_badtoken;
Branch: 1 branch
BranchTrueFalseTotal
if defined $badtoken and $badtoken ne $old_badtoken 0 6 6
Condition33%1/3
defined $badtoken and $badtoken ne $old_badtoken
!ll&&!rl&&r
600
MC/DC0%0/2
defined $badtoken and $badtoken ne $old_badtoken
defined $badtoken $badtoken ne $old_badtoken
Truth table33%1/3
A and B
A= defined $badtokenB= $badtoken ne $old_badtoken
ABresult
0X0
100
111
299 6 ▶ $boundary_leftover = 1 if !defined($badtoken) && length($old_badtoken) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $badtoken and length $old_badtoken > 0 6 0 6
Condition33%1/3
not defined $badtoken and length $old_badtoken > 0
!ll&&!rl&&r
006
MC/DC0%0/2
not defined $badtoken and length $old_badtoken > 0
not defined $badtoken length $old_badtoken > 0
Truth table33%1/3
not(A) and B
A= not defined $badtokenB= length $old_badtoken > 0
ABresult
0X0
100
111
300 }
301 }
302 14078 ▶ $val = defined($qstr) ? $qstr :
Branch: 4 branches
BranchTrueFalseTotal
defined $qstr ? : 1139 12939 14078
defined $enctoken ? : 13 12926 12939
defined $badtoken ? : 0 12926 12926
defined $token ? : 12894 32 12926
303 (defined($enctoken) ? $enctoken :
304 (defined($badtoken) ? $badtoken :
305 (defined($token) ? $token : $empty_value)));
306  
307 # Do RFC 2231 processing
308 # Pick out the parts of the parameter
309 14078 ▶ if ($param =~ /\*/ &&
Branch: 1 branch
BranchTrueFalseTotal
if ($param =~ /\*/ and $param =~ /^ ([^*]+) (?: \* ([^*]+) )? (\*)? \z/sx) { } 74 14004 14078
Condition66%2/3
$param =~ /\*/ and $param =~ /^ ([^*]+) (?: \* ([^*]+) )? (\*)? \z/sx
!ll&&!rl&&r
14004074
MC/DC50%1/2
$param =~ /\*/ and $param =~ /^ ([^*]+) (?: \* ([^*]+) )? (\*)? \z/sx
$param =~ /\*/ $param =~ /^ ([^*]+) (?: \* ([^*]+) )? (\*)? \z/sx
Truth table66%2/3
A and B
A= $param =~ /\*/B= $param =~ /^ ([^*]+) (?: \* ([^*]+) )? (\*)? \z/sx
ABresult
0X0
100
111
310 $param =~ /^ ([^*]+) (?: \* ([^*]+) )? (\*)? \z/xs) {
311 # We have param*number* or param*number or param*
312 74 ▶ my($name, $num) = ($1, $2||0);
Condition100%2/2
$2 || 0
l!l
1262
MC/DC100%1/1
$2 || 0
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
313 74 ▶ if (defined($3)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $3) 38 36 74
314 # We have param*number* or param*
315 # RFC 2231: Asterisks ("*") are reused to provide the
316 # indicator that language and character set information
317 # is present and encoding is being used
318 38 $val = rfc2231percent($val);
319 38 $rfc2231encoding_is_used{$name} = 1;
320 }
321 # A section number is digits, and "0" and "00" are the same section
322 74 ▶ if ($num !~ /\A[0-9]+\z/ || exists($rfc2231params{$name}{0 + $num})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $num =~ /\A[0-9]+\z/ or exists $rfc2231params{$name}{0 + $num}) 2 72 74
Condition66%2/3
not $num =~ /\A[0-9]+\z/ or exists $rfc2231params{$name}{0 + $num}
l!l&&r!l&&!r
0272
MC/DC50%1/2
not $num =~ /\A[0-9]+\z/ or exists $rfc2231params{$name}{0 + $num}
not $num =~ /\A[0-9]+\z/ exists $rfc2231params{$name}{0 + $num}
Truth table66%2/3
not(A) or B
A= not $num =~ /\A[0-9]+\z/B= exists $rfc2231params{$name}{0 + $num}
ABresult
1X1
011
000
323 2 $dup_params{$name} = 1;
324 }
325 74 ▶ $num = 0 + $num if $num =~ /\A[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $num =~ /\A[0-9]+\z/ 74 0 74
326 74 $rfc2231params{$name}{$num} .= $val;
327 } else {
328 # Assign non-rfc2231 value directly. If we
329 # did get a mix of rfc2231 and non-rfc2231 values,
330 # the non-rfc2231 will be blown away in the
331 # "extract reconstructed parameters" loop.
332 14004 ▶ if (defined($params{$param})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{$param}) 33 13971 14004
333 33 $dup_params{$param} = 1;
334 }
335 14004 $params{$param} = $val;
336 }
337 14078 ▶ if (($val // '') eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (($val // "") eq "") 55 14023 14078
Condition100%2/2
$val // ""
l!l
1406711
MC/DC100%1/1
$val // ""
$val
Truth table100%2/2
A
A= $val
Aresult
11
00
338 # Allow filename and name parameters to be empty
339 55 ▶ if ($param ne 'name' && $param ne 'filename') {
Branch: 1 branch
BranchTrueFalseTotal
if ($param ne "name" and $param ne "filename") 41 14 55
Condition100%3/3
$param ne "name" and $param ne "filename"
!ll&&!rl&&r
7741
MC/DC100%2/2
$param ne "name" and $param ne "filename"
$param ne "name" $param ne "filename"
Truth table100%3/3
A and B
A= $param ne "name"B= $param ne "filename"
ABresult
0X0
100
111
340 41 $empty_params{$param} = 1;
341 }
342 }
343 }
344  
345 # the last field was 'boundary' and there were non separator characters left
346 43121 my $pos = pos($raw);
347 43121 ▶ if (($param // '') eq 'boundary' && defined($pos) && $pos < length($raw) && !$saw_semicolon) {
Branch: 1 branch
BranchTrueFalseTotal
if (($param // "") eq "boundary" and defined $pos and $pos < length $raw and not $saw_semicolon) 16 43105 43121
Condition81%9/11
($param // "") eq "boundary" and defined $pos and $pos < length $raw and not $saw_semicolon
!ll&&!rl&&r
43105016
($param // "") eq "boundary" and defined $pos and $pos < length $raw
!ll&&!rl&&r
303771272816
($param // "") eq "boundary" and defined $pos
!ll&&!rl&&r
30377012744
$param // ""
l!l
1382629295
MC/DC50%2/4
($param // "") eq "boundary" and defined $pos and $pos < length $raw and not $saw_semicolon
$param defined $pos $pos < length $raw not $saw_semicolon
Truth table60%3/5
A and B and C and not(D)
A= $paramB= defined $posC= $pos < length $rawD= not $saw_semicolon
ABCDresult
0XXX0
10XX0
110X0
11100
11111
348 16 $boundary_leftover = 1;
349 }
350  
351 43121 my $boundary_is_rfc2231 = 0;
352  
353 # Extract reconstructed parameters
354 43121 foreach $param (keys %rfc2231params) {
355 # If we got any rfc-2231 parameters, then
356 # blow away any potential non-rfc-2231 parameter.
357 62 ▶ if (defined($params{$param})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{$param}) 3 59 62
358 3 $dup_params{$param} = 1;
359 }
360 62 $params{$param} = '';
361 # sections must run 0, 1, 2, ... or other readers join another value
362 62 my @parts = sort { $a <=> $b } keys %{$rfc2231params{$param}};
363 62 ▶ $dup_params{$param} = 1 if grep { $parts[$_] ne $_ } 0 .. $#parts;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$parts[$_] ne $_;} 0 .. $#parts 2 60 62
364 62 foreach $part (sort { $a <=> $b } keys %{$rfc2231params{$param}}) {
365 72 $params{$param} .= $rfc2231params{$param}{$part};
366 }
367 62 ▶ if ($rfc2231encoding_is_used{$param}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rfc2231encoding_is_used{$param}) 38 24 62
368 # there is no reason for the boundary to be encoded this way, since
369 # non-ascii characters are not allowed later anyway, so mark this
370 38 ▶ $boundary_is_rfc2231 = 1 if $param eq 'boundary';
Branch: 1 branch
BranchTrueFalseTotal
if $param eq "boundary" 9 29 38
371 38 my($enc, $lang, $val) = rfc2231decode($params{$param});
372 38 ▶ if (defined $enc) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $enc) 38 0 38
373 # an empty or malformed charset is read as US-ASCII
374 38 ▶ $enc = 'US-ASCII' unless $enc =~ /\A[A-Za-z0-9!#\$%&+^_`{}~-]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $enc =~ /\A[A-Za-z0-9!#\$%&+^_`{}~-]+\z/ 2 36 38
375 # re-encode as QP, preserving charset info
376 38 $val =~ s{([=?_\x00-\x1F\x7F-\xFF])}
377 94 {sprintf("=%02X", ord($1))}eg;
378 38 $val =~ tr/ /_/;
379 38 $params{$param} = '=?' . $enc . '?Q?' . $val . '?=';
380 }
381 }
382 62 ▶ if ($params{$param} eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{$param} eq "") 0 62 62
383 # Allow filename and name parameters to be empty
384 0 ▶ if ($param ne 'name' && $param ne 'filename') {
Branch: 1 branch
BranchTrueFalseTotal
if ($param ne "name" and $param ne "filename") 0 0 0
Condition0%0/3
$param ne "name" and $param ne "filename"
!ll&&!rl&&r
000
MC/DC0%0/2
$param ne "name" and $param ne "filename"
$param ne "name" $param ne "filename"
Truth table0%0/3
A and B
A= $param ne "name"B= $param ne "filename"
ABresult
0X0
100
111
385 0 $empty_params{$param} = 1;
386 }
387 }
388 62 debug " field param <$param> = <$params{$param}>";
389 }
390  
391 # Check the boundary as multipart_boundary() sees it, after any
392 # RFC 2231 continuations have been joined
393 43121 ▶ if (defined($params{'boundary'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"boundary"}) 12803 30318 43121
394 # Mark parse ambiguous if boundary parameter is encoded, wholly
395 # or in part, or has the "?= =?" that decode_mimewords() joins
396 12803 ▶ if ($params{'boundary'} =~ /^=\?.*\?[A-Z]\?.*\?=$/i ||
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"boundary"} =~ /^=\?.*\?[A-Z]\?.*\?=$/i or $params{"boundary"} =~ /=\?[^?]*\?[A-Z]\?[^?]*\?=/i or $params{"boundary"} =~ /\?=\s+=\?/) 34 12769 12803
Condition100%6/6
$params{"boundary"} =~ /^=\?.*\?[A-Z]\?.*\?=$/i or $params{"boundary"} =~ /=\?[^?]*\?[A-Z]\?[^?]*\?=/i or $params{"boundary"} =~ /\?=\s+=\?/
l!l&&r!l&&!r
30412769
$params{"boundary"} =~ /^=\?.*\?[A-Z]\?.*\?=$/i or $params{"boundary"} =~ /=\?[^?]*\?[A-Z]\?[^?]*\?=/i
l!l&&r!l&&!r
22812773
MC/DC100%3/3
$params{"boundary"} =~ /^=\?.*\?[A-Z]\?.*\?=$/i or $params{"boundary"} =~ /=\?[^?]*\?[A-Z]\?[^?]*\?=/i or $params{"boundary"} =~ /\?=\s+=\?/
$params{"boundary"} =~ /^=\?.*\?[A-Z]\?.*\?=$/i $params{"boundary"} =~ /=\?[^?]*\?[A-Z]\?[^?]*\?=/i $params{"boundary"} =~ /\?=\s+=\?/
Truth table100%4/4
A or B or C
A= $params{"boundary"} =~ /^=\?.*\?[A-Z]\?.*\?=$/iB= $params{"boundary"} =~ /=\?[^?]*\?[A-Z]\?[^?]*\?=/iC= $params{"boundary"} =~ /\?=\s+=\?/
ABCresult
1XX1
01X1
0011
0000
397 $params{'boundary'} =~ /=\?[^?]*\?[A-Z]\?[^?]*\?=/i ||
398 $params{'boundary'} =~ /\?=\s+=\?/) {
399 34 $params{'@boundary_ambiguous'} = 1;
400 }
401 # multipart_boundary() strips trailing whitespace per RFC 2046,
402 # so a verbatim parser sees a different boundary: mark ambiguous
403 12803 ▶ if ($params{'boundary'} =~ /\s+\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"boundary"} =~ /\s+\z/) 19 12784 12803
404 19 $params{'@boundary_ambiguous'} = 1;
405 }
406 }
407  
408 # If there are any duplicate parameters, store them in the
409 # special key '@duplicate_parameters' which should never be the
410 # name of a real parameter
411 43121 ▶ if (%dup_params) {
Branch: 1 branch
BranchTrueFalseTotal
if (%dup_params) 33 43088 43121
412 33 $params{'@duplicate_parameters'} = [ sort(keys(%dup_params)) ];
413 }
414  
415 # If there are any empty parameters, store them in the
416 # special key '@empty_parameters' which should never be the
417 # name of a real parameter
418 43121 ▶ if (%empty_params) {
Branch: 1 branch
BranchTrueFalseTotal
if (%empty_params) 36 43085 43121
419 36 $params{'@empty_parameters'} = [ sort(keys(%empty_params)) ];
420 }
421  
422 43121 ▶ if ($boundary_is_rfc2231 || $boundary_leftover) {
Branch: 1 branch
BranchTrueFalseTotal
if ($boundary_is_rfc2231 or $boundary_leftover) 31 43090 43121
Condition100%3/3
$boundary_is_rfc2231 or $boundary_leftover
l!l&&r!l&&!r
92243090
MC/DC100%2/2
$boundary_is_rfc2231 or $boundary_leftover
$boundary_is_rfc2231 $boundary_leftover
Truth table100%3/3
A or B
A= $boundary_is_rfc2231B= $boundary_leftover
ABresult
1X1
011
000
423 31 $params{'@boundary_ambiguous'} = 1;
424 }
425  
426 # Done:
427 43121 \%params;
428 }
429  
430 #------------------------------
431  
432 =item parse STRING
433  
434 I<Class/instance method.>
435 Parse the string into the instance. Any previous information is wiped.
436 The self object is returned.
437  
438 May also be used as a constructor.
439  
440 =cut
441  
442 43115 ▶sub parse {
Subroutine parse: called CC=2 SCAR=6.9
Pod documented
443 43115 my ($self, $string) = @_;
444  
445 # Allow use as constructor, for MIME::Head:
446 43115 ▶ ref($self) or $self = bless({}, $self);
Branch: 1 branch
BranchTrueFalseTotal
ref $self or $self = bless({}, $self) 5 43110 43115
447  
448 # Get params, and stuff them into the self object:
449 43115 $self->set($self->parse_params($string));
450 }
451  
452 #------------------------------
453  
454 =item param PARAMNAME,[VALUE]
455  
456 I<Instance method.>
457 Return the given parameter, or undef if it isn't there.
458 With argument, set the parameter to that VALUE.
459 The PARAMNAME is case-insensitive. A "_" refers to the "default" parameter.
460  
461 =cut
462  
463 43233 ▶sub param {
Subroutine param: called CC=2 SCAR=6.9
Pod documented
464 43233 my ($self, $paramname, $value) = @_;
465 43233 $paramname = lc($paramname);
466 43233 ▶ $self->{$paramname} = $value if (@_ > 2);
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 123 43110 43233
467 43233 $self->{$paramname}
468 }
469  
470 #------------------------------
471  
472 =item paramstr PARAMNAME,[VALUE]
473  
474 I<Instance method.>
475 Like param(): return the given parameter, or I<empty> if it isn't there.
476 With argument, set the parameter to that VALUE.
477 The PARAMNAME is case-insensitive. A "_" refers to the "default" parameter.
478  
479 =cut
480  
481 106 ▶sub paramstr {
Subroutine paramstr: called CC=2 SCAR=7.2
Pod documented
482 106 my $val = shift->param(@_);
483 106 ▶ (defined($val) ? $val : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 106 0 106
484 }
485  
486 #------------------------------
487  
488 =item stringify
489  
490 I<Instance method.>
491 Convert the field to a string, and return it.
492  
493 =cut
494  
495 83 ▶sub stringify {
Subroutine stringify: called CC=4 SCAR=13.9
Pod documented
496 83 my $self = shift;
497 83 my ($key, $val);
498  
499 83 my $str = $self->{'_'}; # default subfield
500 83 foreach $key (sort keys %$self) {
501 139 ▶ next if ($key !~ /^[a-z][a-z-_0-9]*$/); # only lowercase ones!
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ /^[a-z][a-z-_0-9]*$/ 85 54 139
502 54 ▶ defined($val = $self->{$key}) or next;
Branch: 1 branch
BranchTrueFalseTotal
defined($val = $self->{$key}) or next 54 0 54
503 54 $val =~ s/(["\\])/\\$1/g;
504 54 $str .= qq{; $key="$val"};
505 }
506 83 $str;
507 }
508  
509 #------------------------------
510  
511 =item tag
512  
513 I<Instance method, abstract.>
514 Return the tag for this field.
515  
516 =cut
517  
518 0 ▶sub tag { '' }
Subroutine tag: not called CC=1 SCAR=6.9
Pod documented
519  
520 =back
521  
522 =head1 SEE ALSO
523  
524 L<Mail::Field>
525  
526 =cut
527  
528 #------------------------------
529 39 1;
« Parser/Reader.pm ↑ Summary Entity.pm »