| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 210 | ▶ | my $re_match_decode = $STRICT_DECODE ? $re_match_strict : $re_match; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 210 | ▶ | my $re_capture_decode = $STRICT_DECODE ? $re_capture_strict : $re_capture; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 436 | my $line = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 436 | ▶ | my $sep = defined $2 ? $2 : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 436 | ▶ | $stop = 1 unless length($line) or length($sep); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $line or length $sep
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $enc or $Encode::MIME::Header::STRICT_DECODE
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 6 | $enc = Encode::find_encoding($charset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 50229 | ▶ | if ( not defined $enc ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 13 | ▶ | Carp::croak qq(Unknown charset "$charset") if not ref $chk and $chk and $chk & Encode::DIE_ON_ERR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not ref $chk and $chk and $chk & 1
not ref $chk and $chk
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 13 | ▶ | Carp::carp qq(Unknown charset "$charset") if not ref $chk and $chk and $chk & Encode::WARN_ON_ERR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not ref $chk and $chk and $chk & 2
not ref $chk and $chk
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 13 | ▶ | $stop = 1 if not ref $chk and $chk and $chk & Encode::RETURN_ON_ERR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not ref $chk and $chk and $chk & 4
not ref $chk and $chk
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 13 | ▶ | $output .= ($output =~ /(?:\A|[ \t])$/ ? '' : ' ') . $orig unless $stop; # $orig mime word is separated by whitespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 13 | ▶ | $stop ? $orig : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 50216 | ▶ | if ( uc($mime_enc) eq 'B' and $obj->{decode_b} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
uc $mime_enc eq "B" and $obj->{"decode_b"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%3/9
not defined $decoded || ref $chk and $chk and $chk & 4
not defined $decoded || ref $chk and $chk
defined $decoded || ref $chk
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 50 | ▶ | $output .= (defined $decoded ? $decoded : $text) unless $stop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 50 | ▶ | $stop ? $orig : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | ▶ | } elsif ( uc($mime_enc) eq 'Q' and $obj->{decode_q} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
uc $mime_enc eq "Q" and $obj->{"decode_q"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%6/9
not defined $decoded || ref $chk and $chk and $chk & 4
not defined $decoded || ref $chk and $chk
defined $decoded || ref $chk
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 50166 | ▶ | $output .= (defined $decoded ? $decoded : $text) unless $stop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 50166 | ▶ | $stop ? $orig : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
not ref $chk and $chk and $chk & 1
not ref $chk and $chk
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | Carp::carp qq(MIME "$mime_enc" unsupported) if not ref $chk and $chk and $chk & Encode::WARN_ON_ERR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not ref $chk and $chk and $chk & 2
not ref $chk and $chk
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | $stop = 1 if not ref $chk and $chk and $chk & Encode::RETURN_ON_ERR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not ref $chk and $chk and $chk & 4
not ref $chk and $chk
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | $output .= ($output =~ /(?:\A|[ \t])$/ ? '' : ' ') . $orig unless $stop; # $orig mime word is separated by whitespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | $stop ? $orig : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | }se; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 202 | ▶ | if ( not $stop ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 198 | $output .= $words; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 198 | $words = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 202 | $words; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | }se; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 436 | ▶ | if ( not $stop ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
not ref $chk and $chk and not $chk & 8
not ref $chk and $chk
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 50216 | ▶ | $chk &= ~Encode::LEAVE_SRC if not ref $chk and $chk; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $chk and $chk
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 50216 | my $output = $enc->decode($octets, $chk); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 50216 | ▶ | return undef if not ref $chk and $chk and $octets ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not ref $chk and $chk and $octets ne ""
not ref $chk and $chk
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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
not ref $chk and $chk and not $chk & 8
not ref $chk and $chk
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 114 | ▶ | if ( $line =~ s/^(.{0,$bpl})(\s|\z)// ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 114 | $output .= $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 114 | ▶ | $output .= "\r\n" . $2 if length($line); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 57 | ▶ | $enc_chk |= Encode::LEAVE_SRC if not ref $enc_chk and $enc_chk; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $enc_chk and $enc_chk
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 57 | my @result = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 57 | my $octets = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 57 | ▶ | while ( length( my $chr = substr($str, 0, 1, '') ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1256 | my $seq = $enc->encode($chr, $enc_chk); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1256 | ▶ | if ( not length($seq) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 2 | substr($str, 0, 0, $chr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 2 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1254 | ▶ | if ( $obj->_encoded_word_len($octets . $seq) > $wordlen ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 57 | ▶ | $_[1] = $str if not ref $chk and $chk and !($chk & Encode::LEAVE_SRC); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not ref $chk and $chk and not $chk & 8
not ref $chk and $chk
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||