blib/lib/Encode/MIME/Header.pm

filter: Statementstmt 93.5% 175 / 187 Branchbran 75.4% 89 / 118 Conditioncond 70.2% 78 / 111 MC/DCmcdc 56.6% 34 / 60 Subroutinesub 90.4% 19 / 21 Podpod 100% 4 / 4 totaltotal 79.6% 399 / 501 CC 97 SCAR 44.9
CC
97
Cov
82%
decode
149.4
_encode_string
12.0
_fold_line
9.0
CRAP 89.4
« blib/lib/encoding.pm ↑ Summary blib/lib/Encode/CN/HZ.pm »
1 package Encode::MIME::Header;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 our $VERSION = '2.30';
6  
7 5 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use MIME::Base64 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 my %seed = (
12 decode_b => 1, # decodes 'B' encoding ?
13 decode_q => 1, # decodes 'Q' encoding ?
14 encode => 'B', # encode with 'B' or 'Q' ?
15 charset => 'UTF-8', # encode charset
16 bpl => 75, # bytes per line
17 );
18  
19 5 my @objs;
20  
21 5 push @objs, bless {
22 %seed,
23 Name => 'MIME-Header',
24 } => __PACKAGE__;
25  
26 5 push @objs, bless {
27 %seed,
28 decode_q => 0,
29 Name => 'MIME-B',
30 } => __PACKAGE__;
31  
32 5 push @objs, bless {
33 %seed,
34 decode_b => 0,
35 encode => 'Q',
36 Name => 'MIME-Q',
37 } => __PACKAGE__;
38  
39 5 Encode::define_encoding($_, $_->{Name}) foreach @objs;
40  
41 5 ▶use parent qw(Encode::Encoding);
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 0 ▶sub needs_lines { 1 }
Subroutine needs_lines: not called CC=1 SCAR=6.9
Pod documented
44 0 ▶sub perlio_ok { 0 }
Subroutine perlio_ok: not called CC=1 SCAR=6.9
Pod documented
45  
46 # RFC 2047 and RFC 2231 grammar
47 5 my $re_charset = qr/[!"#\$%&'+\-0-9A-Z\\\^_`a-z\{\|\}~]+/;
48 5 my $re_language = qr/[A-Za-z]{1,8}(?:-[0-9A-Za-z]{1,8})*/;
49 5 my $re_encoding = qr/[QqBb]/;
50 5 my $re_encoded_text = qr/[^\?]*/;
51 5 my $re_encoded_word = qr/=\?$re_charset(?:\*$re_language)?\?$re_encoding\?$re_encoded_text\?=/;
52 5 my $re_capture_encoded_word = qr/=\?($re_charset)((?:\*$re_language)?)\?($re_encoding\?$re_encoded_text)\?=/;
53 5 my $re_capture_encoded_word_split = qr/=\?($re_charset)((?:\*$re_language)?)\?($re_encoding)\?($re_encoded_text)\?=/;
54  
55 # in strict mode check also for valid base64 characters and also for valid quoted printable codes
56 5 my $re_encoding_strict_b = qr/[Bb]/;
57 5 my $re_encoding_strict_q = qr/[Qq]/;
58 5 my $re_encoded_text_strict_b = qr/(?:[0-9A-Za-z\+\/]{4})*(?:[0-9A-Za-z\+\/]{2}==|[0-9A-Za-z\+\/]{3}=|)/;
59 5 my $re_encoded_text_strict_q = qr/(?:[\x21-\x3C\x3E\x40-\x7E]|=[0-9A-Fa-f]{2})*/; # NOTE: first part are printable US-ASCII except ?, =, SPACE and TAB
60 5 my $re_encoded_word_strict = qr/=\?$re_charset(?:\*$re_language)?\?(?:$re_encoding_strict_b\?$re_encoded_text_strict_b|$re_encoding_strict_q\?$re_encoded_text_strict_q)\?=/;
61 5 my $re_capture_encoded_word_strict = qr/=\?($re_charset)((?:\*$re_language)?)\?($re_encoding_strict_b\?$re_encoded_text_strict_b|$re_encoding_strict_q\?$re_encoded_text_strict_q)\?=/;
62  
63 5 my $re_newline = qr/(?:\r\n|[\r\n])/;
64  
65 # in strict mode encoded words must be always separated by spaces or tabs (or folded newline)
66 # except in comments when separator between words and comment round brackets can be omitted
67 5 my $re_word_begin_strict = qr/(?:(?:[ \t]|\A)\(?|(?:[^\\]|\A)\)\()/;
68 5 my $re_word_sep_strict = qr/(?:$re_newline?[ \t])+/;
69 5 my $re_word_end_strict = qr/(?:\)\(|\)?(?:$re_newline?[ \t]|\z))/;
70  
71 5 my $re_match = qr/()((?:$re_encoded_word\s*)*$re_encoded_word)()/;
72 5 my $re_match_strict = qr/($re_word_begin_strict)((?:$re_encoded_word_strict$re_word_sep_strict)*$re_encoded_word_strict)(?=$re_word_end_strict)/;
73  
74 5 my $re_capture = qr/$re_capture_encoded_word(?:\s*)?/;
75 5 my $re_capture_strict = qr/$re_capture_encoded_word_strict$re_word_sep_strict?/;
76  
77 5 our $STRICT_DECODE = 0;
78  
79 218 ▶sub decode($$;$) {
Subroutine decode: called CC=68 SCAR=50.1
Pod documented
80 218 my ($obj, $str, $chk) = @_;
81 218 ▶ return undef unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 8 210 218
82  
83 210 ▶ my $re_match_decode = $STRICT_DECODE ? $re_match_strict : $re_match;
Branch: 1 branch
BranchTrueFalseTotal
$Encode::MIME::Header::STRICT_DECODE ? : 93 117 210
84 210 ▶ my $re_capture_decode = $STRICT_DECODE ? $re_capture_strict : $re_capture;
Branch: 1 branch
BranchTrueFalseTotal
$Encode::MIME::Header::STRICT_DECODE ? : 93 117 210
85  
86 210 my $stop = 0;
87 210 my $output = substr($str, 0, 0); # to propagate taintedness
88  
89 # decode each line separately, match whole continuous folded line at one call
90 210 ▶ 1 while not $stop and $str =~ s{^((?:[^\r\n]*(?:$re_newline[ \t])?)*)($re_newline)?}{
Branch: 1 branch
BranchTrueFalseTotal
not $stop and $str =~ s[^((?:[^\r\n]*(?:${re_newline}[ \t])?)*)($re_newline)?][my $line = $1; my $sep = defined $2 ? $2 : ""; $stop = 1 unless length $line or length $sep; '???' while not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/(=\?$re_charset(?:\*$re_language)?\?[Bb]\?)((?:[^\?]{4})*[^\?]{1,3})(\?=)/$1 . $2 . "=" x (4 - length($2) % 4) . $3;/es; '???' while not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/$re_capture_encoded_word_split\s*=\?\1\2\?\3\?($re_encoded_text)\?=/=?$1$2?$3?$4$5?=/os; '???' while not $stop and $line =~ s[^(.*?)$re_match_decode][my $begin = $1 . $2; my $words = $3; $begin =~ tr/\n\r//d; $output .= $begin; '???' while not $stop and $words =~ s[^(.*?)($re_capture_decode)][$output .= $1; my $orig = $2; my $charset = $3; () = split(/\?/, $5, 3); $text =~ tr/\n\r//d; my $enc = &Encode::find_mime_encoding($charset); unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) { $charset = "UTF-8" if lc $charset eq "utf8"; $enc = &Encode::find_encoding($charset); } ; if (not defined $enc) { Carp::croak(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } else { if (uc $mime_enc eq "B" and $obj->{"decode_b"}) { my $decoded = _decode_b($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } elsif (uc $mime_enc eq "Q" and $obj->{"decode_q"}) { my $decoded = _decode_q($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } else { Carp::croak(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } ; } ;]es; unless ($stop) { $output .= $words; $words = ""; } ; $words;]es; unless ($stop) { $line =~ tr/\n\r//d; $output .= $line . $sep; $line = ""; $sep = ""; } ; $line . $sep;]es and do { '???' } 436 210 646
Condition66%2/3
not $stop and $str =~ s[^((?:[^\r\n]*(?:${re_newline}[ \t])?)*)($re_newline)?][my $line = $1; my $sep = defined $2 ? $2 : ""; $stop = 1 unless length $line or length $sep; '???' while not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/(=\?$re_charset(?:\*$re_language)?\?[Bb]\?)((?:[^\?]{4})*[^\?]{1,3})(\?=)/$1 . $2 . "=" x (4 - length($2) % 4) . $3;/es; '???' while not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/$re_capture_encoded_word_split\s*=\?\1\2\?\3\?($re_encoded_text)\?=/=?$1$2?$3?$4$5?=/os; '???' while not $stop and $line =~ s[^(.*?)$re_match_decode][my $begin = $1 . $2; my $words = $3; $begin =~ tr/\n\r//d; $output .= $begin; '???' while not $stop and $words =~ s[^(.*?)($re_capture_decode)][$output .= $1; my $orig = $2; my $charset = $3; () = split(/\?/, $5, 3); $text =~ tr/\n\r//d; my $enc = &Encode::find_mime_encoding($charset); unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) { $charset = "UTF-8" if lc $charset eq "utf8"; $enc = &Encode::find_encoding($charset); } ; if (not defined $enc) { Carp::croak(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } else { if (uc $mime_enc eq "B" and $obj->{"decode_b"}) { my $decoded = _decode_b($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } elsif (uc $mime_enc eq "Q" and $obj->{"decode_q"}) { my $decoded = _decode_q($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } else { Carp::croak(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } ; } ;]es; unless ($stop) { $output .= $words; $words = ""; } ; $words;]es; unless ($stop) { $line =~ tr/\n\r//d; $output .= $line . $sep; $line = ""; $sep = ""; } ; $line . $sep;]es
!ll&&!rl&&r
2100436
MC/DC50%1/2
not $stop and $str =~ s[^((?:[^\r\n]*(?:${re_newline}[ \t])?)*)($re_newline)?][my $line = $1; my $sep = defined $2 ? $2 : ""; $stop = 1 unless length $line or length $sep; '???' while not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/(=\?$re_charset(?:\*$re_language)?\?[Bb]\?)((?:[^\?]{4})*[^\?]{1,3})(\?=)/$1 . $2 . "=" x (4 - length($2) % 4) . $3;/es; '???' while not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/$re_capture_encoded_word_split\s*=\?\1\2\?\3\?($re_encoded_text)\?=/=?$1$2?$3?$4$5?=/os; '???' while not $stop and $line =~ s[^(.*?)$re_match_decode][my $begin = $1 . $2; my $words = $3; $begin =~ tr/\n\r//d; $output .= $begin; '???' while not $stop and $words =~ s[^(.*?)($re_capture_decode)][$output .= $1; my $orig = $2; my $charset = $3; () = split(/\?/, $5, 3); $text =~ tr/\n\r//d; my $enc = &Encode::find_mime_encoding($charset); unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) { $charset = "UTF-8" if lc $charset eq "utf8"; $enc = &Encode::find_encoding($charset); } ; if (not defined $enc) { Carp::croak(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } else { if (uc $mime_enc eq "B" and $obj->{"decode_b"}) { my $decoded = _decode_b($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } elsif (uc $mime_enc eq "Q" and $obj->{"decode_q"}) { my $decoded = _decode_q($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } else { Carp::croak(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } ; } ;]es; unless ($stop) { $output .= $words; $words = ""; } ; $words;]es; unless ($stop) { $line =~ tr/\n\r//d; $output .= $line . $sep; $line = ""; $sep = ""; } ; $line . $sep;]es
not $stop $str =~ s[^((?:[^\r\n]*(?:${re_newline}[ \t])?)*)($re_newline)?][my $line = $1; my $sep = defined $2 ? $2 : ""; $stop = 1 unless length $line or length $sep; '???' while not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/(=\?$re_charset(?:\*$re_language)?\?[Bb]\?)((?:[^\?]{4})*[^\?]{1,3})(\?=)/$1 . $2 . "=" x (4 - length($2) % 4) . $3;/es; '???' while not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/$re_capture_encoded_word_split\s*=\?\1\2\?\3\?($re_encoded_text)\?=/=?$1$2?$3?$4$5?=/os; '???' while not $stop and $line =~ s[^(.*?)$re_match_decode][my $begin = $1 . $2; my $words = $3; $begin =~ tr/\n\r//d; $output .= $begin; '???' while not $stop and $words =~ s[^(.*?)($re_capture_decode)][$output .= $1; my $orig = $2; my $charset = $3; () = split(/\?/, $5, 3); $text =~ tr/\n\r//d; my $enc = &Encode::find_mime_encoding($charset); unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) { $charset = "UTF-8" if lc $charset eq "utf8"; $enc = &Encode::find_encoding($charset); } ; if (not defined $enc) { Carp::croak(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } else { if (uc $mime_enc eq "B" and $obj->{"decode_b"}) { my $decoded = _decode_b($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } elsif (uc $mime_enc eq "Q" and $obj->{"decode_q"}) { my $decoded = _decode_q($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } else { Carp::croak(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } ; } ;]es; unless ($stop) { $output .= $words; $words = ""; } ; $words;]es; unless ($stop) { $line =~ tr/\n\r//d; $output .= $line . $sep; $line = ""; $sep = ""; } ; $line . $sep;]es
Truth table66%2/3
not(A) and B
A= not $stopB= $str =~ s[^((?:[^\r\n]*(?:${re_newline}[ \t])?)*)($re_newline)?][my $line = $1; my $sep = defined $2 ? $2 : ""; $stop = 1 unless length $line or length $sep; '???' while not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/(=\?$re_charset(?:\*$re_language)?\?[Bb]\?)((?:[^\?]{4})*[^\?]{1,3})(\?=)/$1 . $2 . "=" x (4 - length($2) % 4) . $3;/es; '???' while not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/$re_capture_encoded_word_split\s*=\?\1\2\?\3\?($re_encoded_text)\?=/=?$1$2?$3?$4$5?=/os; '???' while not $stop and $line =~ s[^(.*?)$re_match_decode][my $begin = $1 . $2; my $words = $3; $begin =~ tr/\n\r//d; $output .= $begin; '???' while not $stop and $words =~ s[^(.*?)($re_capture_decode)][$output .= $1; my $orig = $2; my $charset = $3; () = split(/\?/, $5, 3); $text =~ tr/\n\r//d; my $enc = &Encode::find_mime_encoding($charset); unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) { $charset = "UTF-8" if lc $charset eq "utf8"; $enc = &Encode::find_encoding($charset); } ; if (not defined $enc) { Carp::croak(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } else { if (uc $mime_enc eq "B" and $obj->{"decode_b"}) { my $decoded = _decode_b($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } elsif (uc $mime_enc eq "Q" and $obj->{"decode_q"}) { my $decoded = _decode_q($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } else { Carp::croak(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } ; } ;]es; unless ($stop) { $output .= $words; $words = ""; } ; $words;]es; unless ($stop) { $line =~ tr/\n\r//d; $output .= $line . $sep; $line = ""; $sep = ""; } ; $line . $sep;]es
ABresult
0X0
100
111
91  
92 436 my $line = $1;
93 436 ▶ my $sep = defined $2 ? $2 : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 25 411 436
94  
95 436 ▶ $stop = 1 unless length($line) or length($sep);
Branch: 1 branch
BranchTrueFalseTotal
unless length $line or length $sep 206 230 436
Condition100%3/3
length $line or length $sep
l!l&&r!l&&!r
2246206
MC/DC100%2/2
length $line or length $sep
length $line length $sep
Truth table100%3/3
A or B
A= length $lineB= length $sep
ABresult
1X1
011
000
96  
97 # in non strict mode append missing '=' padding characters for b words
98 # fixes below concatenation of consecutive encoded mime words
99 436 ▶ 1 while not $STRICT_DECODE and $line =~ s/(=\?$re_charset(?:\*$re_language)?\?[Bb]\?)((?:[^\?]{4})*[^\?]{1,3})(\?=)/$1.$2.('='x(4-length($2)%4)).$3/se;
Branch: 1 branch
BranchTrueFalseTotal
not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/(=\?$re_charset(?:\*$re_language)?\?[Bb]\?)((?:[^\?]{4})*[^\?]{1,3})(\?=)/$1 . $2 . "=" x (4 - length($2) % 4) . $3;/es and do { '???' } 7 436 443
Condition100%3/3
not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/(=\?$re_charset(?:\*$re_language)?\?[Bb]\?)((?:[^\?]{4})*[^\?]{1,3})(\?=)/$1 . $2 . "=" x (4 - length($2) % 4) . $3;/es
!ll&&!rl&&r
1922447
MC/DC100%2/2
not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/(=\?$re_charset(?:\*$re_language)?\?[Bb]\?)((?:[^\?]{4})*[^\?]{1,3})(\?=)/$1 . $2 . "=" x (4 - length($2) % 4) . $3;/es
not $Encode::MIME::Header::STRICT_DECODE $line =~ s/(=\?$re_charset(?:\*$re_language)?\?[Bb]\?)((?:[^\?]{4})*[^\?]{1,3})(\?=)/$1 . $2 . "=" x (4 - length($2) % 4) . $3;/es
Truth table100%3/3
not(A) and B
A= not $Encode::MIME::Header::STRICT_DECODEB= $line =~ s/(=\?$re_charset(?:\*$re_language)?\?[Bb]\?)((?:[^\?]{4})*[^\?]{1,3})(\?=)/$1 . $2 . "=" x (4 - length($2) % 4) . $3;/es
ABresult
0X0
100
111
100  
101 # NOTE: this code partially could break $chk support
102 # in non strict mode concat consecutive encoded mime words with same charset, language and encoding
103 # fixes breaking inside multi-byte characters
104 436 ▶ 1 while not $STRICT_DECODE and $line =~ s/$re_capture_encoded_word_split\s*=\?\1\2\?\3\?($re_encoded_text)\?=/=\?$1$2\?$3\?$4$5\?=/so;
Branch: 1 branch
BranchTrueFalseTotal
not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/$re_capture_encoded_word_split\s*=\?\1\2\?\3\?($re_encoded_text)\?=/=?$1$2?$3?$4$5?=/os and do { '???' } 10054 436 10490
Condition100%3/3
not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/$re_capture_encoded_word_split\s*=\?\1\2\?\3\?($re_encoded_text)\?=/=?$1$2?$3?$4$5?=/os
!ll&&!rl&&r
19224410054
MC/DC100%2/2
not $Encode::MIME::Header::STRICT_DECODE and $line =~ s/$re_capture_encoded_word_split\s*=\?\1\2\?\3\?($re_encoded_text)\?=/=?$1$2?$3?$4$5?=/os
not $Encode::MIME::Header::STRICT_DECODE $line =~ s/$re_capture_encoded_word_split\s*=\?\1\2\?\3\?($re_encoded_text)\?=/=?$1$2?$3?$4$5?=/os
Truth table100%3/3
not(A) and B
A= not $Encode::MIME::Header::STRICT_DECODEB= $line =~ s/$re_capture_encoded_word_split\s*=\?\1\2\?\3\?($re_encoded_text)\?=/=?$1$2?$3?$4$5?=/os
ABresult
0X0
100
111
105  
106 # process sequence of encoded MIME words at once
107 436 ▶ 1 while not $stop and $line =~ s{^(.*?)$re_match_decode}{
Branch: 1 branch
BranchTrueFalseTotal
not $stop and $line =~ s[^(.*?)$re_match_decode][my $begin = $1 . $2; my $words = $3; $begin =~ tr/\n\r//d; $output .= $begin; '???' while not $stop and $words =~ s[^(.*?)($re_capture_decode)][$output .= $1; my $orig = $2; my $charset = $3; () = split(/\?/, $5, 3); $text =~ tr/\n\r//d; my $enc = &Encode::find_mime_encoding($charset); unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) { $charset = "UTF-8" if lc $charset eq "utf8"; $enc = &Encode::find_encoding($charset); } ; if (not defined $enc) { Carp::croak(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } else { if (uc $mime_enc eq "B" and $obj->{"decode_b"}) { my $decoded = _decode_b($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } elsif (uc $mime_enc eq "Q" and $obj->{"decode_q"}) { my $decoded = _decode_q($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } else { Carp::croak(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } ; } ;]es; unless ($stop) { $output .= $words; $words = ""; } ; $words;]es and do { '???' } 202 436 638
Condition100%3/3
not $stop and $line =~ s[^(.*?)$re_match_decode][my $begin = $1 . $2; my $words = $3; $begin =~ tr/\n\r//d; $output .= $begin; '???' while not $stop and $words =~ s[^(.*?)($re_capture_decode)][$output .= $1; my $orig = $2; my $charset = $3; () = split(/\?/, $5, 3); $text =~ tr/\n\r//d; my $enc = &Encode::find_mime_encoding($charset); unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) { $charset = "UTF-8" if lc $charset eq "utf8"; $enc = &Encode::find_encoding($charset); } ; if (not defined $enc) { Carp::croak(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } else { if (uc $mime_enc eq "B" and $obj->{"decode_b"}) { my $decoded = _decode_b($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } elsif (uc $mime_enc eq "Q" and $obj->{"decode_q"}) { my $decoded = _decode_q($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } else { Carp::croak(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } ; } ;]es; unless ($stop) { $output .= $words; $words = ""; } ; $words;]es
!ll&&!rl&&r
210226202
MC/DC100%2/2
not $stop and $line =~ s[^(.*?)$re_match_decode][my $begin = $1 . $2; my $words = $3; $begin =~ tr/\n\r//d; $output .= $begin; '???' while not $stop and $words =~ s[^(.*?)($re_capture_decode)][$output .= $1; my $orig = $2; my $charset = $3; () = split(/\?/, $5, 3); $text =~ tr/\n\r//d; my $enc = &Encode::find_mime_encoding($charset); unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) { $charset = "UTF-8" if lc $charset eq "utf8"; $enc = &Encode::find_encoding($charset); } ; if (not defined $enc) { Carp::croak(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } else { if (uc $mime_enc eq "B" and $obj->{"decode_b"}) { my $decoded = _decode_b($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } elsif (uc $mime_enc eq "Q" and $obj->{"decode_q"}) { my $decoded = _decode_q($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } else { Carp::croak(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } ; } ;]es; unless ($stop) { $output .= $words; $words = ""; } ; $words;]es
not $stop $line =~ s[^(.*?)$re_match_decode][my $begin = $1 . $2; my $words = $3; $begin =~ tr/\n\r//d; $output .= $begin; '???' while not $stop and $words =~ s[^(.*?)($re_capture_decode)][$output .= $1; my $orig = $2; my $charset = $3; () = split(/\?/, $5, 3); $text =~ tr/\n\r//d; my $enc = &Encode::find_mime_encoding($charset); unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) { $charset = "UTF-8" if lc $charset eq "utf8"; $enc = &Encode::find_encoding($charset); } ; if (not defined $enc) { Carp::croak(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } else { if (uc $mime_enc eq "B" and $obj->{"decode_b"}) { my $decoded = _decode_b($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } elsif (uc $mime_enc eq "Q" and $obj->{"decode_q"}) { my $decoded = _decode_q($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } else { Carp::croak(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } ; } ;]es; unless ($stop) { $output .= $words; $words = ""; } ; $words;]es
Truth table100%3/3
not(A) and B
A= not $stopB= $line =~ s[^(.*?)$re_match_decode][my $begin = $1 . $2; my $words = $3; $begin =~ tr/\n\r//d; $output .= $begin; '???' while not $stop and $words =~ s[^(.*?)($re_capture_decode)][$output .= $1; my $orig = $2; my $charset = $3; () = split(/\?/, $5, 3); $text =~ tr/\n\r//d; my $enc = &Encode::find_mime_encoding($charset); unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) { $charset = "UTF-8" if lc $charset eq "utf8"; $enc = &Encode::find_encoding($charset); } ; if (not defined $enc) { Carp::croak(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } else { if (uc $mime_enc eq "B" and $obj->{"decode_b"}) { my $decoded = _decode_b($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } elsif (uc $mime_enc eq "Q" and $obj->{"decode_q"}) { my $decoded = _decode_q($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } else { Carp::croak(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } ; } ;]es; unless ($stop) { $output .= $words; $words = ""; } ; $words;]es
ABresult
0X0
100
111
108  
109 202 my $begin = $1 . $2;
110 202 my $words = $3;
111  
112 202 $begin =~ tr/\r\n//d;
113 202 $output .= $begin;
114  
115 # decode one MIME word
116 202 ▶ 1 while not $stop and $words =~ s{^(.*?)($re_capture_decode)}{
Branch: 1 branch
BranchTrueFalseTotal
not $stop and $words =~ s[^(.*?)($re_capture_decode)][$output .= $1; my $orig = $2; my $charset = $3; () = split(/\?/, $5, 3); $text =~ tr/\n\r//d; my $enc = &Encode::find_mime_encoding($charset); unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) { $charset = "UTF-8" if lc $charset eq "utf8"; $enc = &Encode::find_encoding($charset); } ; if (not defined $enc) { Carp::croak(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } else { if (uc $mime_enc eq "B" and $obj->{"decode_b"}) { my $decoded = _decode_b($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } elsif (uc $mime_enc eq "Q" and $obj->{"decode_q"}) { my $decoded = _decode_q($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } else { Carp::croak(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } ; } ;]es and do { '???' } 50229 202 50431
Condition100%3/3
not $stop and $words =~ s[^(.*?)($re_capture_decode)][$output .= $1; my $orig = $2; my $charset = $3; () = split(/\?/, $5, 3); $text =~ tr/\n\r//d; my $enc = &Encode::find_mime_encoding($charset); unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) { $charset = "UTF-8" if lc $charset eq "utf8"; $enc = &Encode::find_encoding($charset); } ; if (not defined $enc) { Carp::croak(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } else { if (uc $mime_enc eq "B" and $obj->{"decode_b"}) { my $decoded = _decode_b($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } elsif (uc $mime_enc eq "Q" and $obj->{"decode_q"}) { my $decoded = _decode_q($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } else { Carp::croak(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } ; } ;]es
!ll&&!rl&&r
419850229
MC/DC100%2/2
not $stop and $words =~ s[^(.*?)($re_capture_decode)][$output .= $1; my $orig = $2; my $charset = $3; () = split(/\?/, $5, 3); $text =~ tr/\n\r//d; my $enc = &Encode::find_mime_encoding($charset); unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) { $charset = "UTF-8" if lc $charset eq "utf8"; $enc = &Encode::find_encoding($charset); } ; if (not defined $enc) { Carp::croak(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } else { if (uc $mime_enc eq "B" and $obj->{"decode_b"}) { my $decoded = _decode_b($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } elsif (uc $mime_enc eq "Q" and $obj->{"decode_q"}) { my $decoded = _decode_q($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } else { Carp::croak(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } ; } ;]es
not $stop $words =~ s[^(.*?)($re_capture_decode)][$output .= $1; my $orig = $2; my $charset = $3; () = split(/\?/, $5, 3); $text =~ tr/\n\r//d; my $enc = &Encode::find_mime_encoding($charset); unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) { $charset = "UTF-8" if lc $charset eq "utf8"; $enc = &Encode::find_encoding($charset); } ; if (not defined $enc) { Carp::croak(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } else { if (uc $mime_enc eq "B" and $obj->{"decode_b"}) { my $decoded = _decode_b($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } elsif (uc $mime_enc eq "Q" and $obj->{"decode_q"}) { my $decoded = _decode_q($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } else { Carp::croak(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } ; } ;]es
Truth table100%3/3
not(A) and B
A= not $stopB= $words =~ s[^(.*?)($re_capture_decode)][$output .= $1; my $orig = $2; my $charset = $3; () = split(/\?/, $5, 3); $text =~ tr/\n\r//d; my $enc = &Encode::find_mime_encoding($charset); unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) { $charset = "UTF-8" if lc $charset eq "utf8"; $enc = &Encode::find_encoding($charset); } ; if (not defined $enc) { Carp::croak(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[Unknown charset "$charset"]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } else { if (uc $mime_enc eq "B" and $obj->{"decode_b"}) { my $decoded = _decode_b($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } elsif (uc $mime_enc eq "Q" and $obj->{"decode_q"}) { my $decoded = _decode_q($enc, $text, $chk); $stop = 1 if not defined $decoded || ref $chk and $chk and $chk & 4; $output .= (defined $decoded ? $decoded : $text) unless $stop; $stop ? $orig : ""; } else { Carp::croak(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 1; Carp::carp(qq[MIME "$mime_enc" unsupported]) if not ref $chk and $chk and $chk & 2; $stop = 1 if not ref $chk and $chk and $chk & 4; $output .= ($output =~ /(?:\A|[ \t])$/ ? "" : " ") . $orig unless $stop; $stop ? $orig : ""; } ; } ;]es
ABresult
0X0
100
111
117  
118 50229 $output .= $1;
119 50229 my $orig = $2;
120 50229 my $charset = $3;
121 50229 my ($mime_enc, $text) = split /\?/, $5;
122  
123 50229 $text =~ tr/\r\n//d;
124  
125 50229 my $enc = Encode::find_mime_encoding($charset);
126  
127 # in non strict mode allow also perl encoding aliases
128 50229 ▶ if ( not defined $enc and not $STRICT_DECODE ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $enc or $Encode::MIME::Header::STRICT_DECODE) 6 50223 50229
Condition100%3/3
defined $enc or $Encode::MIME::Header::STRICT_DECODE
l!l&&r!l&&!r
50213106
MC/DC100%2/2
defined $enc or $Encode::MIME::Header::STRICT_DECODE
defined $enc $Encode::MIME::Header::STRICT_DECODE
Truth table100%3/3
A or B
A= defined $encB= $Encode::MIME::Header::STRICT_DECODE
ABresult
1X1
011
000
129 # make sure that decoded string will be always strict UTF-8
130 6 ▶ $charset = 'UTF-8' if lc($charset) eq 'utf8';
Branch: 1 branch
BranchTrueFalseTotal
if lc $charset eq "utf8" 2 4 6
131 6 $enc = Encode::find_encoding($charset);
132 }
133  
134 50229 ▶ if ( not defined $enc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $enc) { } 13 50216 50229
135 13 ▶ Carp::croak qq(Unknown charset "$charset") if not ref $chk and $chk and $chk & Encode::DIE_ON_ERR;
Branch: 1 branch
BranchTrueFalseTotal
if not ref $chk and $chk and $chk & 1 0 13 13
Condition83%5/6
not ref $chk and $chk and $chk & 1
!ll&&!rl&&r
1030
not ref $chk and $chk
!ll&&!rl&&r
193
MC/DC0%0/3
not ref $chk and $chk and $chk & 1
not ref $chk $chk $chk & 1
Truth table75%3/4
not(A) and B and C
A= not ref $chkB= $chkC= $chk & 1
ABCresult
0XX0
10X0
1100
1111
136 13 ▶ Carp::carp qq(Unknown charset "$charset") if not ref $chk and $chk and $chk & Encode::WARN_ON_ERR;
Branch: 1 branch
BranchTrueFalseTotal
if not ref $chk and $chk and $chk & 2 0 13 13
Condition83%5/6
not ref $chk and $chk and $chk & 2
!ll&&!rl&&r
1030
not ref $chk and $chk
!ll&&!rl&&r
193
MC/DC0%0/3
not ref $chk and $chk and $chk & 2
not ref $chk $chk $chk & 2
Truth table75%3/4
not(A) and B and C
A= not ref $chkB= $chkC= $chk & 2
ABCresult
0XX0
10X0
1100
1111
137 13 ▶ $stop = 1 if not ref $chk and $chk and $chk & Encode::RETURN_ON_ERR;
Branch: 1 branch
BranchTrueFalseTotal
if not ref $chk and $chk and $chk & 4 2 11 13
Condition100%6/6
not ref $chk and $chk and $chk & 4
!ll&&!rl&&r
1012
not ref $chk and $chk
!ll&&!rl&&r
193
MC/DC100%3/3
not ref $chk and $chk and $chk & 4
not ref $chk $chk $chk & 4
Truth table100%4/4
not(A) and B and C
A= not ref $chkB= $chkC= $chk & 4
ABCresult
0XX0
10X0
1100
1111
138 13 ▶ $output .= ($output =~ /(?:\A|[ \t])$/ ? '' : ' ') . $orig unless $stop; # $orig mime word is separated by whitespace
Branch: 2 branches
BranchTrueFalseTotal
unless $stop 11 2 13
$output =~ /(?:\A|[ \t])$/ ? : 5 6 11
139 13 ▶ $stop ? $orig : '';
Branch: 1 branch
BranchTrueFalseTotal
$stop ? : 2 11 13
140 } else {
141 50216 ▶ if ( uc($mime_enc) eq 'B' and $obj->{decode_b} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (uc $mime_enc eq 'B' and $obj->{'decode_b'}) { } 50 50166 50216
elsif (uc $mime_enc eq 'Q' and $obj->{'decode_q'}) { } 50166 0 50166
Condition66%2/3
uc $mime_enc eq "B" and $obj->{"decode_b"}
!ll&&!rl&&r
50166050
MC/DC50%1/2
uc $mime_enc eq "B" and $obj->{"decode_b"}
uc $mime_enc eq "B" $obj->{"decode_b"}
Truth table66%2/3
A and B
A= uc $mime_enc eq "B"B= $obj->{"decode_b"}
ABresult
0X0
100
111
142 50 my $decoded = _decode_b($enc, $text, $chk);
143 50 ▶ $stop = 1 if not defined $decoded and not ref $chk and $chk and $chk & Encode::RETURN_ON_ERR;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $decoded || ref $chk and $chk and $chk & 4 0 50 50
Condition33%3/9
not defined $decoded || ref $chk and $chk and $chk & 4
!ll&&!rl&&r
5000
not defined $decoded || ref $chk and $chk
!ll&&!rl&&r
5000
defined $decoded || ref $chk
l!l&&r!l&&!r
5000
MC/DC0%0/4
not defined $decoded || ref $chk and $chk and $chk & 4
defined $decoded ref $chk $chk $chk & 4
Truth table20%1/5
not(A || B) and C and D
A= defined $decodedB= ref $chkC= $chkD= $chk & 4
ABCDresult
1XXX0
01XX0
000X0
00100
00111
144 50 ▶ $output .= (defined $decoded ? $decoded : $text) unless $stop;
Branch: 2 branches
BranchTrueFalseTotal
unless $stop 50 0 50
defined $decoded ? : 50 0 50
145 50 ▶ $stop ? $orig : '';
Branch: 1 branch
BranchTrueFalseTotal
$stop ? : 0 50 50
146 ▶ } elsif ( uc($mime_enc) eq 'Q' and $obj->{decode_q} ) {
Condition33%1/3
uc $mime_enc eq "Q" and $obj->{"decode_q"}
!ll&&!rl&&r
0050166
MC/DC0%0/2
uc $mime_enc eq "Q" and $obj->{"decode_q"}
uc $mime_enc eq "Q" $obj->{"decode_q"}
Truth table33%1/3
A and B
A= uc $mime_enc eq "Q"B= $obj->{"decode_q"}
ABresult
0X0
100
111
147 50166 my $decoded = _decode_q($enc, $text, $chk);
148 50166 ▶ $stop = 1 if not defined $decoded and not ref $chk and $chk and $chk & Encode::RETURN_ON_ERR;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $decoded || ref $chk and $chk and $chk & 4 2 50164 50166
Condition66%6/9
not defined $decoded || ref $chk and $chk and $chk & 4
!ll&&!rl&&r
5016402
not defined $decoded || ref $chk and $chk
!ll&&!rl&&r
5016402
defined $decoded || ref $chk
l!l&&r!l&&!r
5016402
MC/DC25%1/4
not defined $decoded || ref $chk and $chk and $chk & 4
defined $decoded ref $chk $chk $chk & 4
Truth table40%2/5
not(A || B) and C and D
A= defined $decodedB= ref $chkC= $chkD= $chk & 4
ABCDresult
1XXX0
01XX0
000X0
00100
00111
149 50166 ▶ $output .= (defined $decoded ? $decoded : $text) unless $stop;
Branch: 2 branches
BranchTrueFalseTotal
unless $stop 50164 2 50166
defined $decoded ? : 50164 0 50164
150 50166 ▶ $stop ? $orig : '';
Branch: 1 branch
BranchTrueFalseTotal
$stop ? : 2 50164 50166
151 } else {
152 0 ▶ Carp::croak qq(MIME "$mime_enc" unsupported) if not ref $chk and $chk and $chk & Encode::DIE_ON_ERR;
Branch: 1 branch
BranchTrueFalseTotal
if not ref $chk and $chk and $chk & 1 0 0 0
Condition0%0/6
not ref $chk and $chk and $chk & 1
!ll&&!rl&&r
000
not ref $chk and $chk
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $chk and $chk and $chk & 1
not ref $chk $chk $chk & 1
Truth table0%0/4
not(A) and B and C
A= not ref $chkB= $chkC= $chk & 1
ABCresult
0XX0
10X0
1100
1111
153 0 ▶ Carp::carp qq(MIME "$mime_enc" unsupported) if not ref $chk and $chk and $chk & Encode::WARN_ON_ERR;
Branch: 1 branch
BranchTrueFalseTotal
if not ref $chk and $chk and $chk & 2 0 0 0
Condition0%0/6
not ref $chk and $chk and $chk & 2
!ll&&!rl&&r
000
not ref $chk and $chk
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $chk and $chk and $chk & 2
not ref $chk $chk $chk & 2
Truth table0%0/4
not(A) and B and C
A= not ref $chkB= $chkC= $chk & 2
ABCresult
0XX0
10X0
1100
1111
154 0 ▶ $stop = 1 if not ref $chk and $chk and $chk & Encode::RETURN_ON_ERR;
Branch: 1 branch
BranchTrueFalseTotal
if not ref $chk and $chk and $chk & 4 0 0 0
Condition0%0/6
not ref $chk and $chk and $chk & 4
!ll&&!rl&&r
000
not ref $chk and $chk
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $chk and $chk and $chk & 4
not ref $chk $chk $chk & 4
Truth table0%0/4
not(A) and B and C
A= not ref $chkB= $chkC= $chk & 4
ABCresult
0XX0
10X0
1100
1111
155 0 ▶ $output .= ($output =~ /(?:\A|[ \t])$/ ? '' : ' ') . $orig unless $stop; # $orig mime word is separated by whitespace
Branch: 2 branches
BranchTrueFalseTotal
unless $stop 0 0 0
$output =~ /(?:\A|[ \t])$/ ? : 0 0 0
156 0 ▶ $stop ? $orig : '';
Branch: 1 branch
BranchTrueFalseTotal
$stop ? : 0 0 0
157 }
158 }
159  
160 }se;
161  
162 202 ▶ if ( not $stop ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stop) 198 4 202
163 198 $output .= $words;
164 198 $words = '';
165 }
166  
167 202 $words;
168  
169 }se;
170  
171 436 ▶ if ( not $stop ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stop) 226 210 436
172 226 $line =~ tr/\r\n//d;
173 226 $output .= $line . $sep;
174 226 $line = '';
175 226 $sep = '';
176 }
177  
178 436 $line . $sep;
179  
180 }se;
181  
182 210 ▶ $_[1] = $str if not ref $chk and $chk and !($chk & Encode::LEAVE_SRC);
Branch: 1 branch
BranchTrueFalseTotal
if not ref $chk and $chk and not $chk & 8 3 207 210
Condition100%6/6
not ref $chk and $chk and not $chk & 8
!ll&&!rl&&r
20343
not ref $chk and $chk
!ll&&!rl&&r
32007
MC/DC100%3/3
not ref $chk and $chk and not $chk & 8
not ref $chk $chk not $chk & 8
Truth table100%4/4
not(A) and B and not(C)
A= not ref $chkB= $chkC= not $chk & 8
ABCresult
0XX0
10X0
1100
1111
183 210 return $output;
184 }
185  
186 50 ▶sub _decode_b {
Subroutine _decode_b: called CC=2 SCAR=6.9
187 50 my ($enc, $text, $chk) = @_;
188 # MIME::Base64::decode ignores everything after a '=' padding character
189 # in non strict mode split string after each sequence of padding characters and decode each substring
190 my $octets = $STRICT_DECODE ?
191 MIME::Base64::decode($text) :
192 50 ▶ join('', map { MIME::Base64::decode($_) } split /(?<==)(?=[^=])/, $text);
Branch: 1 branch
BranchTrueFalseTotal
$Encode::MIME::Header::STRICT_DECODE ? : 10 40 50
193 50 return _decode_octets($enc, $octets, $chk);
194 }
195  
196 50166 ▶sub _decode_q {
Subroutine _decode_q: called CC=1 SCAR=0.0
197 50166 my ($enc, $text, $chk) = @_;
198 50166 $text =~ s/_/ /go;
199 50166 $text =~ s/=([0-9A-Fa-f]{2})/pack('C', hex($1))/ego;
200 50166 return _decode_octets($enc, $text, $chk);
201 }
202  
203 50216 ▶sub _decode_octets {
Subroutine _decode_octets: called CC=7 SCAR=19.5
204 50216 my ($enc, $octets, $chk) = @_;
205 50216 ▶ $chk = 0 unless defined $chk;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chk 0 50216 50216
206 50216 ▶ $chk &= ~Encode::LEAVE_SRC if not ref $chk and $chk;
Branch: 1 branch
BranchTrueFalseTotal
if not ref $chk and $chk 10 50206 50216
Condition100%3/3
not ref $chk and $chk
!ll&&!rl&&r
45020210
MC/DC100%2/2
not ref $chk and $chk
not ref $chk $chk
Truth table100%3/3
not(A) and B
A= not ref $chkB= $chk
ABresult
0X0
100
111
207 50216 my $output = $enc->decode($octets, $chk);
208 50216 ▶ return undef if not ref $chk and $chk and $octets ne '';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $chk and $chk and $octets ne "" 2 50214 50216
Condition100%6/6
not ref $chk and $chk and $octets ne ""
!ll&&!rl&&r
5020682
not ref $chk and $chk
!ll&&!rl&&r
45020210
MC/DC100%3/3
not ref $chk and $chk and $octets ne ""
not ref $chk $chk $octets ne ""
Truth table100%4/4
not(A) and B and C
A= not ref $chkB= $chkC= $octets ne ""
ABCresult
0XX0
10X0
1100
1111
209 50214 return $output;
210 }
211  
212 63 ▶sub encode($$;$) {
Subroutine encode: called CC=5 SCAR=16.1
Pod documented
213 63 my ($obj, $str, $chk) = @_;
214 63 ▶ return undef unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 6 57 63
215 57 my $output = $obj->_fold_line($obj->_encode_string($str, $chk));
216 57 ▶ $_[1] = $str if not ref $chk and $chk and !($chk & Encode::LEAVE_SRC);
Branch: 1 branch
BranchTrueFalseTotal
if not ref $chk and $chk and not $chk & 8 2 55 57
Condition100%6/6
not ref $chk and $chk and not $chk & 8
!ll&&!rl&&r
5322
not ref $chk and $chk
!ll&&!rl&&r
2514
MC/DC100%3/3
not ref $chk and $chk and not $chk & 8
not ref $chk $chk not $chk & 8
Truth table100%4/4
not(A) and B and not(C)
A= not ref $chkB= $chkC= not $chk & 8
ABCresult
0XX0
10X0
1100
1111
217 57 return $output . substr($str, 0, 0); # to propagate taintedness
218 }
219  
220 57 ▶sub _fold_line {
Subroutine _fold_line: called CC=6 SCAR=21.9
221 57 my ($obj, $line) = @_;
222 57 my $bpl = $obj->{bpl};
223 57 my $output = '';
224  
225 57 ▶ while ( length($line) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $line) 114 57 171
226 114 ▶ if ( $line =~ s/^(.{0,$bpl})(\s|\z)// ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ s/^(.{0,$bpl})(\s|\z)//) { } 114 0 114
elsif ($line =~ s/(\s)(.*)$//) { } 0 0 0
227 114 $output .= $1;
228 114 ▶ $output .= "\r\n" . $2 if length($line);
Branch: 1 branch
BranchTrueFalseTotal
if length $line 57 57 114
229 } elsif ( $line =~ s/(\s)(.*)$// ) {
230 0 $output .= $line;
231 0 $line = $2;
232 0 ▶ $output .= "\r\n" . $1 if length($line);
Branch: 1 branch
BranchTrueFalseTotal
if length $line 0 0 0
233 } else {
234 0 $output .= $line;
235 0 last;
236 }
237 }
238  
239 57 return $output;
240 }
241  
242 57 ▶sub _encode_string {
Subroutine _encode_string: called CC=12 SCAR=24.9
243 57 my ($obj, $str, $chk) = @_;
244 57 ▶ my $wordlen = $obj->{bpl} > 76 ? 76 : $obj->{bpl};
Branch: 1 branch
BranchTrueFalseTotal
$obj->{'bpl'} > 76 ? : 0 57 57
245 57 my $enc = Encode::find_mime_encoding($obj->{charset});
246 57 my $enc_chk = $chk;
247 57 ▶ $enc_chk = 0 unless defined $enc_chk;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $enc_chk 0 57 57
248 57 ▶ $enc_chk |= Encode::LEAVE_SRC if not ref $enc_chk and $enc_chk;
Branch: 1 branch
BranchTrueFalseTotal
if not ref $enc_chk and $enc_chk 4 53 57
Condition100%3/3
not ref $enc_chk and $enc_chk
!ll&&!rl&&r
2514
MC/DC100%2/2
not ref $enc_chk and $enc_chk
not ref $enc_chk $enc_chk
Truth table100%3/3
not(A) and B
A= not ref $enc_chkB= $enc_chk
ABresult
0X0
100
111
249 57 my @result = ();
250 57 my $octets = '';
251 57 ▶ while ( length( my $chr = substr($str, 0, 1, '') ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length(my $chr = substr($str, 0, 1, ''))) 1256 55 1311
252 1256 my $seq = $enc->encode($chr, $enc_chk);
253 1256 ▶ if ( not length($seq) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $seq) 2 1254 1256
254 2 substr($str, 0, 0, $chr);
255 2 last;
256 }
257 1254 ▶ if ( $obj->_encoded_word_len($octets . $seq) > $wordlen ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->_encoded_word_len($octets . $seq) > $wordlen) 57 1197 1254
258 57 push @result, $obj->_encode_word($octets);
259 57 $octets = '';
260 }
261 1254 $octets .= $seq;
262 }
263 57 ▶ length($octets) and push @result, $obj->_encode_word($octets);
Branch: 1 branch
BranchTrueFalseTotal
length $octets and push @result, $obj->_encode_word($octets) 57 0 57
264 57 ▶ $_[1] = $str if not ref $chk and $chk and !($chk & Encode::LEAVE_SRC);
Branch: 1 branch
BranchTrueFalseTotal
if not ref $chk and $chk and not $chk & 8 2 55 57
Condition100%6/6
not ref $chk and $chk and not $chk & 8
!ll&&!rl&&r
5322
not ref $chk and $chk
!ll&&!rl&&r
2514
MC/DC100%3/3
not ref $chk and $chk and not $chk & 8
not ref $chk $chk not $chk & 8
Truth table100%4/4
not(A) and B and not(C)
A= not ref $chkB= $chkC= not $chk & 8
ABCresult
0XX0
10X0
1100
1111
265 57 return join(' ', @result);
266 }
267  
268 114 ▶sub _encode_word {
Subroutine _encode_word: called CC=2 SCAR=6.9
269 114 my ($obj, $octets) = @_;
270 114 my $charset = $obj->{charset};
271 114 my $encode = $obj->{encode};
272 114 ▶ my $text = $encode eq 'B' ? _encode_b($octets) : _encode_q($octets);
Branch: 1 branch
BranchTrueFalseTotal
$encode eq 'B' ? : 72 42 114
273 114 return "=?$charset?$encode?$text?=";
274 }
275  
276 1254 ▶sub _encoded_word_len {
Subroutine _encoded_word_len: called CC=2 SCAR=6.9
277 1254 my ($obj, $octets) = @_;
278 1254 my $charset = $obj->{charset};
279 1254 my $encode = $obj->{encode};
280 1254 ▶ my $text_len = $encode eq 'B' ? _encoded_b_len($octets) : _encoded_q_len($octets);
Branch: 1 branch
BranchTrueFalseTotal
$encode eq 'B' ? : 848 406 1254
281 1254 return length("=?$charset?$encode??=") + $text_len;
282 }
283  
284 72 ▶sub _encode_b {
Subroutine _encode_b: called CC=1 SCAR=0.0
285 72 my ($octets) = @_;
286 72 return MIME::Base64::encode($octets, '');
287 }
288  
289 848 ▶sub _encoded_b_len {
Subroutine _encoded_b_len: called CC=1 SCAR=0.0
290 848 my ($octets) = @_;
291 848 return ( length($octets) + 2 ) / 3 * 4;
292 }
293  
294 5 my $re_invalid_q_char = qr/[^0-9A-Za-z !*+\-\/]/;
295  
296 42 ▶sub _encode_q {
Subroutine _encode_q: called CC=1 SCAR=0.0
297 42 my ($octets) = @_;
298 42 $octets =~ s{($re_invalid_q_char)}{
299 566 join('', map { sprintf('=%02X', $_) } unpack('C*', $1))
300 }egox;
301 42 $octets =~ s/ /_/go;
302 42 return $octets;
303 }
304  
305 406 ▶sub _encoded_q_len {
Subroutine _encoded_q_len: called CC=1 SCAR=0.0
306 406 my ($octets) = @_;
307 406 my $invalid_count = () = $octets =~ /$re_invalid_q_char/sgo;
308 406 return ( $invalid_count * 3 ) + ( length($octets) - $invalid_count );
309 }
310  
311 5 1;
312 __END__
« blib/lib/encoding.pm ↑ Summary blib/lib/Encode/CN/HZ.pm »