| 1 | package MIME::Field::ParamVal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 30 | ▶ | 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 | 30 | require 5.001; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # Pragmas: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 30 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 30 | ▶ | use re 'taint'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 30 | ▶ | use vars qw($VERSION @ISA); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # Other modules: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 30 | ▶ | use Mail::Field; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # Kit modules: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 30 | ▶ | use MIME::Tools qw(:config :msgs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 30 | @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 | 30 | $VERSION = "5.520"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Private globals... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # Pattern to match parameter names (like fieldnames, but = not allowed): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 30 | my $PARAMNAME = '[^\x00-\x1f\x80-\xff :=]+?'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # Pattern to match the first value on the line: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 30 | 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 | 30 | my $TSPECIAL = '()<>@,;:\</[]?="'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | #" Fix emacs highlighting... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 30 | my $TOKEN = '[^ \x00-\x1f\x80-\xff' . "\Q$TSPECIAL\E" . ']+'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 30 | my $QUOTED_STRING = '"([^\\\\"]*(?:\\\\.(?:[^\\\\"]*))*)"'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # Encoded token: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 30 | my $ENCTOKEN = "=\\?[^?]*\\?[A-Za-z]\\?[^?]+\\?="; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # pattern to match comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 30 | my $COMMENT = '\([^\)]*\)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # Pattern to match spaces or comments: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 30 | my $SPCZ = '(?:\s|' . $COMMENT . ')*'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Pattern to match non-semicolon as fallback for broken MIME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # produced by some viruses | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 30 | my $BADTOKEN = '[^;]+'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Pattern to match whitespace allowed in header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 30 | my $WSP = '[\t\ ]'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # Class init... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | =item set [\%PARAMHASH | KEY=>VAL,...,KEY=>VAL] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | I<Instance method.> Set this field. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | The paramhash should contain parameter names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | in I<all lowercase>, with the special C<"_"> parameter name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | signifying the "default" (unnamed) parameter for the field: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # Set up to be... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # Content-type: Message/Partial; number=2; total=3; id="ocj=pbe0M2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | $conttype->set('_' => 'Message/Partial', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 'number' => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 'total' => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 'id' => "ocj=pbe0M2"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | Note that a single argument is taken to be a I<reference> to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | a paramhash, while multiple args are taken to be the elements | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | of the paramhash themselves. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | Supplying undef for a hashref, or an empty set of values, effectively | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | clears the object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | The self object is returned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 15122 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 15122 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 15122 | ▶ | my $params = ((@_ == 1) ? (shift || {}) : {@_}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
shift() or {}
MC/DC0%0/1
shift() or {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 15122 | %$self = %$params; # set 'em | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 15122 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | =item parse_params STRING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | I<Class/instance utility method.> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | Extract parameter info from a structured field, and return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | it as a hash reference. For example, here is a field with parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | Content-Type: Message/Partial; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | number=2; total=3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | id="oc=jpbe0M2Yt4s@thumper.bellcore.com" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | Here is how you'd extract them: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | $params = $class->parse_params('content-type'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | if ($$params{'_'} eq 'message/partial') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | $number = $$params{'number'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | $total = $$params{'total'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | $id = $$params{'id'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | Like field names, parameter names are coerced to lowercase. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | The special '_' parameter means the default parameter for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | field. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | B<NOTE:> This has been provided as a public method to support backwards | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | compatibility, but you probably shouldn't use it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 27 | ▶ | sub rfc2231decode { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rfc2231decode: called CC=3 SCAR=12.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 27 | my($val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 27 | my($enc, $lang, $rest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 27 | local($1,$2,$3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 27 | ▶ | if ($val =~ m/^([^']*)'([^']*)'(.*)\z/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 27 | $enc = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 27 | $lang = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 27 | $rest = $3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } elsif ($val =~ m/^([^']*)'([^']*)\z/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $enc = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $rest = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $rest = $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # $enc remains undefined when charset/language info is missing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 27 | return ($enc, $lang, $rest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 27 | ▶ | sub rfc2231percent { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rfc2231percent: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # Do percent-substitution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 27 | my($str) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 27 | local $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 27 | $str =~ s/%([0-9a-fA-F]{2})/pack("C", hex($1))/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 27 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 15054 | ▶ | sub parse_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_params: called CC=52 SCAR=40.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 15054 | my ($self, $raw) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 15054 | my %params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | my %dup_params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 15054 | my %empty_params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 15054 | my %rfc2231params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 15054 | my %rfc2231encoding_is_used; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 15054 | my $param; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 15054 | my $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 15054 | my $part; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # Get raw field, and unfold it: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 15054 | ▶ | defined($raw) or $raw = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 15054 | $raw =~ s/\n//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 15054 | $raw =~ s/\s+\z//; # Strip trailing whitespace | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 15054 | local($1,$2,$3,$4,$5); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # Extract special first parameter: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 15054 | ▶ | $raw =~ m/\A$SPCZ($FIRST)$SPCZ/og or return {}; # nada! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 15054 | $params{'_'} = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 15054 | my $boundary_leftover = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 15054 | my $saw_semicolon= 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # Extract subsequent parameters. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # No, we can't just "split" on semicolons: they're legal in quoted strings! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 15054 | while (1) { # keep chopping away until done... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 25578 | $saw_semicolon = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 25578 | ▶ | $raw =~ m/\G([^;]*)(\;$SPCZ)+/ogc or last; # skip leading separator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 10576 | my $leftover = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 10576 | $saw_semicolon = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # the previous param was 'boundary' and we had leftover data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 10576 | ▶ | if (defined($leftover) && length($leftover) > 0 && defined($param) && $param eq 'boundary') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
defined $leftover and length $leftover > 0 and defined $param and $param eq "boundary"
defined $leftover and length $leftover > 0 and defined $param
defined $leftover and length $leftover > 0
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 table40%2/5
A and B and C and D
A= defined $leftoverB= length $leftover > 0C= defined $paramD= $param eq "boundary"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $boundary_leftover = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 10576 | ▶ | $raw =~ m/\G($PARAMNAME)($COMMENT|$WSP)*=($COMMENT|$WSP)*/ogc or last; # give up if not a param | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 10524 | $param = lc($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 10524 | ▶ | $raw =~ m/\G(?:$QUOTED_STRING|($ENCTOKEN)|($TOKEN)|($BADTOKEN)|())/gc or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 10524 | my ($qstr, $enctoken, $token, $badtoken, $empty_value) = ($1, $2, $3, $4, $5); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 10524 | ▶ | if (defined($qstr)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # unescape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 891 | $qstr =~ s/\\(.)/$1/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 10524 | ▶ | if (defined($badtoken)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # Strip leading/trailing whitespace from badtoken | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 6 | $badtoken =~ s/^$WSP+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 6 | $badtoken =~ s/$WSP+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # Only keep token parameters in badtoken; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # cut it off at the first non-token char. CPAN RT #105455 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 6 | my $old_badtoken = $badtoken; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 6 | $badtoken =~ /^($TOKEN)*/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 6 | $badtoken = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 6 | ▶ | if (defined($badtoken)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # Cut it off at first whitespace too | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $badtoken =~ s/\s.*//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # there was a leftover after the last valid token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 6 | ▶ | if ($param eq 'boundary') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 6 | ▶ | $boundary_leftover = 1 if defined($badtoken) && $badtoken ne $old_badtoken; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $badtoken and $badtoken ne $old_badtoken
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 6 | ▶ | $boundary_leftover = 1 if !defined($badtoken) && length($old_badtoken) > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $badtoken and length $old_badtoken > 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 10524 | ▶ | $val = defined($qstr) ? $qstr : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | (defined($enctoken) ? $enctoken : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | (defined($badtoken) ? $badtoken : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | (defined($token) ? $token : $empty_value))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # Mark parse ambiguous if boundary parameter is encoded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 10524 | ▶ | if ($param eq 'boundary') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 9535 | ▶ | if (defined($val) && $val =~ /^=\?.*\?[A-Z]\?.*\?=$/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $val and $val =~ /^=\?.*\?[A-Z]\?.*\?=$/i
MC/DC100%2/2
defined $val and $val =~ /^=\?.*\?[A-Z]\?.*\?=$/i
defined $val
$val =~ /^=\?.*\?[A-Z]\?.*\?=$/i
Truth table100%3/3
A and B
A= defined $valB= $val =~ /^=\?.*\?[A-Z]\?.*\?=$/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 8 | $params{'@boundary_ambiguous'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # multipart_boundary() strips trailing whitespace per RFC 2046, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # so a verbatim parser sees a different boundary: mark ambiguous | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 9535 | ▶ | if (defined($val) && $val =~ /\s+\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $val and $val =~ /\s+\z/
MC/DC100%2/2
defined $val and $val =~ /\s+\z/
defined $val
$val =~ /\s+\z/
Truth table100%3/3
A and B
A= defined $valB= $val =~ /\s+\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 13 | $params{'@boundary_ambiguous'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # Do RFC 2231 processing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # Pick out the parts of the parameter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 10524 | ▶ | if ($param =~ /\*/ && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$param =~ /\*/ and $param =~ /^ ([^*]+) (?: \* ([^*]+) )? (\*)? \z/sx
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | $param =~ /^ ([^*]+) (?: \* ([^*]+) )? (\*)? \z/xs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # We have param*number* or param*number or param* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 35 | ▶ | my($name, $num) = ($1, $2||0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$2 || 0
MC/DC100%1/1
$2 || 0
$2
Truth table100%2/2
A
A= $2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 35 | ▶ | if (defined($3)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 27 | $val = rfc2231percent($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 27 | $rfc2231encoding_is_used{$name} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 35 | $rfc2231params{$name}{$num} .= $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | # Assign non-rfc2231 value directly. If we | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # did get a mix of rfc2231 and non-rfc2231 values, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # the non-rfc2231 will be blown away in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | # "extract reconstructed parameters" loop. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 10489 | ▶ | if (defined($params{$param})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 28 | $dup_params{$param} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 10489 | $params{$param} = $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 10524 | ▶ | if (($val // '') eq '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$val // ""
MC/DC100%1/1
$val // ""
$val
Truth table100%2/2
A
A= $val
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 31 | $empty_params{$param} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # the last field was 'boundary' and there were non separator characters left | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 15054 | my $pos = pos($raw); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 15054 | ▶ | if (($param // '') eq 'boundary' && defined($pos) && $pos < length($raw) && !$saw_semicolon) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition81%9/11
($param // "") eq "boundary" and defined $pos and $pos < length $raw and not $saw_semicolon
($param // "") eq "boundary" and defined $pos and $pos < length $raw
($param // "") eq "boundary" and defined $pos
$param // ""
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 14 | $boundary_leftover = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 15054 | my $boundary_is_rfc2231 = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # Extract reconstructed parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 15054 | foreach $param (keys %rfc2231params) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | # If we got any rfc-2231 parameters, then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | # blow away any potential non-rfc-2231 parameter. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 31 | ▶ | if (defined($params{$param})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 3 | $dup_params{$param} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 31 | $params{$param} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 31 | foreach $part (sort { $a <=> $b } keys %{$rfc2231params{$param}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 35 | $params{$param} .= $rfc2231params{$param}{$part}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 31 | ▶ | if ($rfc2231encoding_is_used{$param}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # there is no reason for the boundary to be encoded this way, since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # non-ascii characters are not allowed later anyway, so mark this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 27 | ▶ | $boundary_is_rfc2231 = 1 if $param eq 'boundary'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 27 | my($enc, $lang, $val) = rfc2231decode($params{$param}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 27 | ▶ | if (defined $enc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # re-encode as QP, preserving charset and language info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 27 | $val =~ s{([=?_\x00-\x1F\x7F-\xFF])} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 71 | {sprintf("=%02X", ord($1))}eg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 27 | $val =~ tr/ /_/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # RFC 2231 section 5: Language specification in Encoded Words | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 27 | ▶ | $enc .= '*' . $lang if defined $lang && $lang ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $lang and $lang ne ""
MC/DC50%1/2
defined $lang and $lang ne ""
defined $lang
$lang ne ""
Truth table66%2/3
A and B
A= defined $langB= $lang ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 27 | $params{$param} = '=?' . $enc . '?Q?' . $val . '?='; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 31 | ▶ | if ($params{$param} eq '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $empty_params{$param} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 31 | debug " field param <$param> = <$params{$param}>"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | # If there are any duplicate parameters, store them in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # special key '@duplicate_parameters' which should never be the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | # name of a real parameter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 15054 | ▶ | if (%dup_params) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 24 | $params{'@duplicate_parameters'} = [ sort(keys(%dup_params)) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | # If there are any empty parameters, store them in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # special key '@empty_parameters' which should never be the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # name of a real parameter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 15054 | ▶ | if (%empty_params) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 31 | $params{'@empty_parameters'} = [ sort(keys(%empty_params)) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 15054 | ▶ | if ($boundary_is_rfc2231 || $boundary_leftover) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$boundary_is_rfc2231 or $boundary_leftover
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 28 | $params{'@boundary_ambiguous'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # Done: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 15054 | \%params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | =item parse STRING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | I<Class/instance method.> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | Parse the string into the instance. Any previous information is wiped. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | The self object is returned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | May also be used as a constructor. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 15048 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 15048 | my ($self, $string) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # Allow use as constructor, for MIME::Head: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 15048 | ▶ | ref($self) or $self = bless({}, $self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # Get params, and stuff them into the self object: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 15048 | $self->set($self->parse_params($string)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | =item param PARAMNAME,[VALUE] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | Return the given parameter, or undef if it isn't there. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | With argument, set the parameter to that VALUE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | The PARAMNAME is case-insensitive. A "_" refers to the "default" parameter. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 15166 | ▶ | sub param { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
param: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 15166 | my ($self, $paramname, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 15166 | $paramname = lc($paramname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 15166 | ▶ | $self->{$paramname} = $value if (@_ > 2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 15166 | $self->{$paramname} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | =item paramstr PARAMNAME,[VALUE] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | Like param(): return the given parameter, or I<empty> if it isn't there. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | With argument, set the parameter to that VALUE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | The PARAMNAME is case-insensitive. A "_" refers to the "default" parameter. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 106 | ▶ | sub paramstr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
paramstr: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 106 | my $val = shift->param(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 106 | ▶ | (defined($val) ? $val : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | =item stringify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | I<Instance method.> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | Convert the field to a string, and return it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 83 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 83 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 83 | my ($key, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 83 | my $str = $self->{'_'}; # default subfield | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 83 | foreach $key (sort keys %$self) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 138 | ▶ | next if ($key !~ /^[a-z][a-z-_0-9]*$/); # only lowercase ones! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 54 | ▶ | defined($val = $self->{$key}) or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 54 | $val =~ s/(["\\])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 54 | $str .= qq{; $key="$val"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 83 | $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | =item tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | I<Instance method, abstract.> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | Return the tag for this field. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | sub tag { '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | L<Mail::Field> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 30 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||