1# 2# $Id: mime-header.t,v 2.15 2017/07/18 07:15:29 dankogai Exp $ 3# This script is written in utf8 4# 5BEGIN { 6 if ($ENV{'PERL_CORE'}){ 7 chdir 't'; 8 unshift @INC, '../lib'; 9 } 10 require Config; import Config; 11 if ($Config{'extensions'} !~ /\bEncode\b/) { 12 print "1..0 # Skip: Encode was not built\n"; 13 exit 0; 14 } 15 if (ord("A") == 193) { 16 print "1..0 # Skip: EBCDIC\n"; 17 exit 0; 18 } 19 $| = 1; 20} 21 22use strict; 23 24use utf8; 25use charnames ":full"; 26 27use Test::More tests => 266; 28 29BEGIN { 30 use_ok("Encode::MIME::Header"); 31} 32 33my @decode_long_tests; 34if ($] < 5.009004) { # perl versions without Regular expressions Engine de-recursivised which cause stack overflow 35 push(@decode_long_tests, "a" x 1000000 => "a" x 1000000); 36 push(@decode_long_tests, "=?utf-8?Q?a?= " x 400 => "a" x 400 . " "); 37 push(@decode_long_tests, "=?utf-8?Q?a?= =?US-ASCII?Q?b?= " x 200 => "ab" x 200 . " "); 38} else { 39 push(@decode_long_tests, "a" x 1000000 => "a" x 1000000); 40 push(@decode_long_tests, "=?utf-8?Q?a?= " x 10000 => "a" x 10000 . " "); 41 push(@decode_long_tests, "=?utf-8?Q?a?= =?US-ASCII?Q?b?= " x 10000 => "ab" x 10000 . " "); 42} 43 44my @decode_tests = ( 45 # RFC2047 p.5 46 "=?iso-8859-1?q?this=20is=20some=20text?=" => "this is some text", 47 # RFC2047 p.10 48 "=?US-ASCII?Q?Keith_Moore?=" => "Keith Moore", 49 "=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?=" => "Keld Jørn Simonsen", 50 "=?ISO-8859-1?Q?Andr=E9?= Pirard" => "André Pirard", 51 "=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\r\n =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=" => "If you can read this you understand the example.", 52 "=?ISO-8859-1?Q?Olle_J=E4rnefors?=" => "Olle Järnefors", 53 "=?ISO-8859-1?Q?Patrik_F=E4ltstr=F6m?=" => "Patrik Fältström", 54 # RFC2047 p.11 55 "(=?iso-8859-8?b?7eXs+SDv4SDp7Oj08A==?=)" => "(םולש ןב ילטפנ)", 56 "(=?ISO-8859-1?Q?a?=)" => "(a)", 57 "(=?ISO-8859-1?Q?a?= b)" => "(a b)", 58 "(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)" => "(ab)", 59 "(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)" => "(ab)", 60 "(=?ISO-8859-1?Q?a?=\r\n\t=?ISO-8859-1?Q?b?=)" => "(ab)", 61 # RFC2047 p.12 62 "(=?ISO-8859-1?Q?a_b?=)" => '(a b)', 63 "(=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?=)" => "(a b)", 64 # RFC2231 p.6 65 "=?US-ASCII*EN?Q?Keith_Moore?=" => "Keith Moore", 66 # others 67 "=?US-ASCII*en-US?Q?Keith_Moore?=" => "Keith Moore", 68 "=?ISO-8859-1*da-DK?Q?Keld_J=F8rn_Simonsen?=" => "Keld Jørn Simonsen", 69 "=?ISO-8859-1*fr-BE?Q?Andr=E9?= Pirard" => "André Pirard", 70 "=?ISO-8859-1*en?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=" => "If you can read this you understand the example.", 71 # multiple (separated by CRLF) 72 "=?US-ASCII?Q?a?=\r\n=?US-ASCII?Q?b?=" => "a\r\nb", 73 "a\r\nb" => "a\r\nb", 74 "a\r\n\r\nb" => "a\r\n\r\nb", 75 "a\r\n\r\nb\r\n" => "a\r\n\r\nb\r\n", 76 # multiple multiline (separated by CRLF) 77 "=?US-ASCII?Q?a?=\r\n =?US-ASCII?Q?b?=\r\n=?US-ASCII?Q?c?=" => "ab\r\nc", 78 "a\r\n b\r\nc" => "a b\r\nc", 79 # RT67569 80 "foo =?us-ascii?q?bar?=" => "foo bar", 81 "foo\r\n =?us-ascii?q?bar?=" => "foo bar", 82 "=?us-ascii?q?foo?= bar" => "foo bar", 83 "=?us-ascii?q?foo?=\r\n bar" => "foo bar", 84 "foo bar" => "foo bar", 85 "foo\r\n bar" => "foo bar", 86 "=?us-ascii?q?foo?= =?us-ascii?q?bar?=" => "foobar", 87 "=?us-ascii?q?foo?=\r\n =?us-ascii?q?bar?=" => "foobar", 88 # RT40027 89 "a: b\r\n c" => "a: b c", 90 # RT104422 91 "=?utf-8?Q?pre?= =?utf-8?B?IGZvbw==?=\r\n =?utf-8?Q?bar?=" => "pre foobar", 92 # RT114034 - replace invalid UTF-8 sequence with unicode replacement character 93 "=?utf-8?Q?=f9=80=80=80=80?=" => "�", 94 "=?utf-8?Q?=28=c3=29?=" => "(�)", 95 # decode only known MIME charsets, do not crash on invalid 96 "prefix =?unknown?Q?a=20b=20c?= middle =?US-ASCII?Q?d=20e=20f?= suffix" => "prefix =?unknown?Q?a=20b=20c?= middle d e f suffix", 97 "prefix =?US-ASCII?Q?a_b_c?= =?unknown?Q?d_e_f?= suffix" => "prefix a b c =?unknown?Q?d_e_f?= suffix", 98 "prefix =?US-ASCII?Q?a_b_c?= =?unknown?Q?d_e_f?= =?US-ASCII?Q?g_h_i?= suffix" => "prefix a b c =?unknown?Q?d_e_f?= g h i suffix", 99 # long strings 100 @decode_long_tests, 101 # separators around encoded words 102 "\r\n =?US-ASCII?Q?a?=" => " a", 103 "\r\n (=?US-ASCII?Q?a?=)" => " (a)", 104 "\r\n (=?US-ASCII?Q?a?=)\r\n " => " (a) ", 105 "(=?US-ASCII?Q?a?=)\r\n " => "(a) ", 106 " (=?US-ASCII?Q?a?=) " => " (a) ", 107 "(=?US-ASCII?Q?a?=) " => "(a) ", 108 " (=?US-ASCII?Q?a?=)" => " (a)", 109 "(=?US-ASCII?Q?a?=)(=?US-ASCII?Q?b?=)" => "(a)(b)", 110 "(=?US-ASCII?Q?a?=) (=?US-ASCII?Q?b?=)" => "(a) (b)", 111 "(=?US-ASCII?Q?a?=)\r\n (=?US-ASCII?Q?b?=)" => "(a) (b)", 112 "\r\n (=?US-ASCII?Q?a?=)\r\n (=?US-ASCII?Q?b?=)\r\n " => " (a) (b) ", 113 "\r\n(=?US-ASCII?Q?a?=)\r\n(=?US-ASCII?Q?b?=)" => "\r\n(a)\r\n(b)", 114); 115 116my @decode_default_tests = ( 117 @decode_tests, 118 "=?us-ascii?q?foo bar?=" => "foo bar", 119 "=?us-ascii?q?foo\r\n bar?=" => "foo bar", 120 '=?us-ascii?q?foo=20=3cbar=40baz=2efoo=3e=20bar?=' => 'foo <bar@baz.foo> bar', 121 '"=?us-ascii?q?foo=20=3cbar=40baz=2efoo=3e=20bar?="' => '"foo <bar@baz.foo> bar"', 122 "=?us-ascii?q?foo?==?us-ascii?q?bar?=" => "foobar", 123 "foo=?us-ascii?q?bar?=" => "foobar", 124 "foo =?us-ascii?q?=20?==?us-ascii?q?bar?=" => "foo bar", 125 # Encode::MIME::Header pre 2.83 126 "[=?UTF-8?B?ZsOzcnVt?=]=?UTF-8?B?IHNwcsOhdmE=?=" => "[fórum] správa", 127 "test:=?UTF-8?B?IHNwcsOhdmE=?=" => "test: správa", 128 "=?UTF-8?B?dMOpc3Q=?=:=?UTF-8?B?IHNwcsOhdmE=?=", "tést: správa", 129 # multiple base64 parts in one b word 130 "=?us-ascii?b?Zg==Zg==?=" => "ff", 131 # b word with invalid characters 132 "=?us-ascii?b?Zm!!9!v?=" => "foo", 133 # concat consecutive words (with same parameters) and join them into one utf-8 symbol 134 "=?UTF-8?Q?=C3?= =?UTF-8?Q?=A1?=" => "á", 135 # RT114034 - use strict UTF-8 decoder for invalid MIME charsets utf8, UTF8 and utf-8-strict 136 "=?utf8?Q?=C3=A1=f9=80=80=80=80?=" => "á�", 137 "=?UTF8?Q?=C3=A1=f9=80=80=80=80?=" => "á�", 138 "=?utf-8-strict?Q?=C3=A1=f9=80=80=80=80?=" => "á�", 139 # allow non-ASCII characters in q word 140 "=?UTF-8?Q?\x{C3}\x{A1}?=" => "á", 141); 142 143my @decode_strict_tests = ( 144 @decode_tests, 145 "=?us-ascii?q?foo bar?=" => "=?us-ascii?q?foo bar?=", 146 "=?us-ascii?q?foo\r\n bar?=" => "=?us-ascii?q?foo bar?=", 147 '=?us-ascii?q?foo=20=3cbar=40baz=2efoo=3e=20bar?=' => 'foo <bar@baz.foo> bar', 148 '"=?us-ascii?q?foo=20=3cbar=40baz=2efoo=3e=20bar?="' => '"=?us-ascii?q?foo=20=3cbar=40baz=2efoo=3e=20bar?="', 149 # do not decode invalid q words 150 "=?us-ascii?q?foo=?=" => "=?us-ascii?q?foo=?=", 151 "=?us-ascii?q?foo=?= =?us-ascii?q?foo?=" => "=?us-ascii?q?foo=?= foo", 152 # do not decode invalid b words 153 "=?us-ascii?b?----?=" => "=?us-ascii?b?----?=", 154 "=?us-ascii?b?Zm8=-?= =?us-ascii?b?Zm9v?= and =?us-ascii?b?Zg==?=" => "=?us-ascii?b?Zm8=-?= foo and f", 155 "=?us-ascii?b?----?= =?us-ascii?b?Zm9v?= and =?us-ascii?b?Zg==?=" => "=?us-ascii?b?----?= foo and f", 156 # RT114034 - utf8, UTF8 and also utf-8-strict are invalid MIME charset, do not decode it 157 "=?utf8?Q?=C3=A1?=" => "=?utf8?Q?=C3=A1?=", 158 "=?UTF8?Q?=C3=A1?=" => "=?UTF8?Q?=C3=A1?=", 159 "=?utf-8-strict?Q?=C3=A1?=" => "=?utf-8-strict?Q?=C3=A1?=", 160 # do not allow non-ASCII characters in q word 161 "=?UTF-8?Q?\x{C3}\x{A1}?=" => "=?UTF-8?Q?\x{C3}\x{A1}?=", 162); 163 164my @encode_tests = ( 165 "小飼 弾" => "=?UTF-8?B?5bCP6aO8IOW8vg==?=", "=?UTF-8?Q?=E5=B0=8F=E9=A3=BC_=E5=BC=BE?=", 166 "漢字、カタカナ、ひらがなを含む、非常に長いタイトル行が一体全体どのようにしてEncodeされるのか?" => "=?UTF-8?B?5ryi5a2X44CB44Kr44K/44Kr44OK44CB44Gy44KJ44GM44Gq44KS5ZCr44KA?=\r\n =?UTF-8?B?44CB6Z2e5bi444Gr6ZW344GE44K/44Kk44OI44Or6KGM44GM5LiA5L2T5YWo?=\r\n =?UTF-8?B?5L2T44Gp44Gu44KI44GG44Gr44GX44GmRW5jb2Rl44GV44KM44KL44Gu44GL?=\r\n =?UTF-8?B?77yf?=", "=?UTF-8?Q?=E6=BC=A2=E5=AD=97=E3=80=81=E3=82=AB=E3=82=BF=E3=82=AB=E3=83=8A?=\r\n =?UTF-8?Q?=E3=80=81=E3=81=B2=E3=82=89=E3=81=8C=E3=81=AA=E3=82=92=E5=90=AB?=\r\n =?UTF-8?Q?=E3=82=80=E3=80=81=E9=9D=9E=E5=B8=B8=E3=81=AB=E9=95=B7=E3=81=84?=\r\n =?UTF-8?Q?=E3=82=BF=E3=82=A4=E3=83=88=E3=83=AB=E8=A1=8C=E3=81=8C=E4=B8=80?=\r\n =?UTF-8?Q?=E4=BD=93=E5=85=A8=E4=BD=93=E3=81=A9=E3=81=AE=E3=82=88=E3=81=86?=\r\n =?UTF-8?Q?=E3=81=AB=E3=81=97=E3=81=A6Encode=E3=81=95=E3=82=8C=E3=82=8B?=\r\n =?UTF-8?Q?=E3=81=AE=E3=81=8B=EF=BC=9F?=", 167 # double encode 168 "What is =?UTF-8?B?w4RwZmVs?= ?" => "=?UTF-8?B?V2hhdCBpcyA9P1VURi04P0I/dzRSd1ptVnM/PSA/?=", "=?UTF-8?Q?What_is_=3D=3FUTF-8=3FB=3Fw4RwZmVs=3F=3D_=3F?=", 169 # pound 1024 170 "\N{POUND SIGN}1024" => "=?UTF-8?B?wqMxMDI0?=", "=?UTF-8?Q?=C2=A31024?=", 171 # latin1 characters 172 "\x{fc}" => "=?UTF-8?B?w7w=?=", "=?UTF-8?Q?=C3=BC?=", 173 # RT42627 174 Encode::decode_utf8("\x{c2}\x{a3}xxxxxxxxxxxxxxxxxxx0") => "=?UTF-8?B?wqN4eHh4eHh4eHh4eHh4eHh4eHh4MA==?=", "=?UTF-8?Q?=C2=A3xxxxxxxxxxxxxxxxxxx0?=", 175 # RT87831 176 "0" => "=?UTF-8?B?MA==?=", "=?UTF-8?Q?0?=", 177 # RT88717 178 "Hey foo\x{2024}bar:whee" => "=?UTF-8?B?SGV5IGZvb+KApGJhcjp3aGVl?=", "=?UTF-8?Q?Hey_foo=E2=80=A4bar=3Awhee?=", 179 # valid q chars 180 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !*+-/" => "=?UTF-8?B?MDEyMzQ1Njc4OUFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaYWJjZGVmZ2hp?=\r\n =?UTF-8?B?amtsbW5vcHFyc3R1dnd4eXogISorLS8=?=", "=?UTF-8?Q?0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_?=\r\n =?UTF-8?Q?!*+-/?=", 181 # invalid q chars 182 "." => "=?UTF-8?B?Lg==?=", "=?UTF-8?Q?=2E?=", 183 "," => "=?UTF-8?B?LA==?=", "=?UTF-8?Q?=2C?=", 184 # long ascii sequence 185 "a" x 100 => "=?UTF-8?B?YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh?=\r\n =?UTF-8?B?YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh?=\r\n =?UTF-8?B?YWFhYWFhYWFhYQ==?=", "=?UTF-8?Q?aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa?=\r\n =?UTF-8?Q?aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa?=", 186 # long unicode sequence 187 "" x 100 => "=?UTF-8?B?8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIDwn5iA8J+YgPCfmIA=?=\r\n " x 9 . "=?UTF-8?B?8J+YgA==?=", join("\r\n ", ("=?UTF-8?Q?=F0=9F=98=80=F0=9F=98=80=F0=9F=98=80=F0=9F=98=80=F0=9F=98=80?=") x 20), 188); 189 190sub info { 191 my ($str, $str1, $str2) = @_; 192 substr $str1, 1000, -3, "..." if defined $str1 and length $str1 > 1000; 193 substr $str2, 1000, -3, "..." if defined $str2 and length $str2 > 1000; 194 $str .= ": $str1" if defined $str1; 195 $str .= " => $str2" if defined $str2; 196 $str = Encode::encode_utf8($str); 197 $str =~ s/\r/\\r/gs; 198 $str =~ s/\n/\\n/gs; 199 return $str; 200} 201 202sub check_length { 203 my ($str) = @_; 204 my @lines = split /\r\n /, $str; 205 my @long = grep { length($_) > 75 } @lines; 206 return scalar @long == 0; 207} 208 209my @splice; 210 211@splice = @encode_tests; 212while (my ($d, $b, $q) = splice @splice, 0, 3) { 213 is Encode::encode("MIME-Header", $d) => $b, info("encode default", $d => $b); 214 is Encode::encode("MIME-B", $d) => $b, info("encode base64", $d => $b); 215 is Encode::encode("MIME-Q", $d) => $q, info("encode qp", $d => $q); 216 is Encode::decode("MIME-B", $b) => $d, info("decode base64", $b => $d); 217 is Encode::decode("MIME-Q", $q) => $d, info("decode qp", $b => $d); 218 ok check_length($b), info("correct encoded length base64", $b); 219 ok check_length($q), info("correct encoded length qp", $q); 220} 221 222@splice = @decode_default_tests; 223while (my ($e, $d) = splice @splice, 0, 2) { 224 is Encode::decode("MIME-Header", $e) => $d, info("decode default", $e => $d); 225} 226 227local $Encode::MIME::Header::STRICT_DECODE = 1; 228 229@splice = @decode_strict_tests; 230while (my ($e, $d) = splice @splice, 0, 2) { 231 is Encode::decode("MIME-Header", $e) => $d, info("decode strict", $e => $d); 232} 233 234my $valid_unicode = "á"; 235my $invalid_unicode = "\x{1000000}"; 236{ 237 my $input = $valid_unicode; 238 my $output = Encode::encode("MIME-Header", $input, Encode::FB_QUIET); 239 is $output => Encode::encode("MIME-Header", $valid_unicode), "encode valid with FB_QUIET flag: output string is valid"; 240 is $input => "", "encode valid with FB_QUIET flag: input string is modified and empty"; 241} 242{ 243 my $input = $valid_unicode . $invalid_unicode; 244 my $output = Encode::encode("MIME-Header", $input, Encode::FB_QUIET); 245 is $output => Encode::encode("MIME-Header", $valid_unicode), "encode with FB_QUIET flag: output string stops before first invalid character"; 246 is $input => $invalid_unicode, "encode with FB_QUIET flag: input string is modified and starts with first invalid character"; 247} 248{ 249 my $input = $valid_unicode . $invalid_unicode; 250 my $output = Encode::encode("MIME-Header", $input, Encode::FB_QUIET | Encode::LEAVE_SRC); 251 is $output => Encode::encode("MIME-Header", $valid_unicode), "encode with FB_QUIET and LEAVE_SRC flags: output string stops before first invalid character"; 252 is $input => $valid_unicode . $invalid_unicode, "encode with FB_QUIET and LEAVE_SRC flags: input string is not modified"; 253} 254{ 255 my $input = $valid_unicode . $invalid_unicode; 256 my $output = Encode::encode("MIME-Header", $input, Encode::FB_PERLQQ); 257 is $output => Encode::encode("MIME-Header", $valid_unicode . '\x{1000000}'), "encode with FB_PERLQQ flag: output string contains perl qq representation of invalid character"; 258 is $input => $valid_unicode . $invalid_unicode, "encode with FB_PERLQQ flag: input string is not modified"; 259} 260{ 261 my $input = $valid_unicode; 262 my $output = Encode::encode("MIME-Header", $input, sub { sprintf("!0x%X!", $_[0]) }); 263 is $output => Encode::encode("MIME-Header", $valid_unicode), "encode valid with coderef check: output string is valid"; 264 is $input => $valid_unicode, "encode valid with coderef check: input string is not modified"; 265} 266{ 267 my $input = $valid_unicode . $invalid_unicode; 268 my $output = Encode::encode("MIME-Header", $input, sub { sprintf("!0x%X!", $_[0]) }); 269 is $output => Encode::encode("MIME-Header", $valid_unicode . '!0x1000000!'), "encode with coderef check: output string contains output from coderef"; 270 is $input => $valid_unicode . $invalid_unicode, "encode with coderef check: input string is not modified"; 271} 272 273my $valid_mime = "=?US-ASCII?Q?d=20e=20f?="; 274my $invalid_mime = "=?unknown?Q?a=20b=20c?="; 275my $invalid_mime_unicode = "=?utf-8?Q?=28=c3=29?="; 276{ 277 my $input = $valid_mime; 278 my $output = Encode::decode("MIME-Header", $input, Encode::FB_QUIET); 279 is $output => Encode::decode("MIME-Header", $valid_mime), "decode valid with FB_QUIET flag: output string is valid"; 280 is $input => "", "decode valid with FB_QUIET flag: input string is modified and empty"; 281} 282{ 283 my $input = $valid_mime . " " . $invalid_mime; 284 my $output = Encode::decode("MIME-Header", $input, Encode::FB_QUIET); 285 is $output => Encode::decode("MIME-Header", $valid_mime), "decode with FB_QUIET flag: output string stops before first mime word with unknown charset"; 286 is $input => $invalid_mime, "decode with FB_QUIET flag: input string is modified and starts with first mime word with unknown charset"; 287} 288{ 289 my $input = $valid_mime . " " . $invalid_mime_unicode; 290 my $output = Encode::decode("MIME-Header", $input, Encode::FB_QUIET); 291 is $output => Encode::decode("MIME-Header", $valid_mime), "decode with FB_QUIET flag: output string stops before first mime word with invalid unicode character"; 292 is $input => $invalid_mime_unicode, "decode with FB_QUIET flag: input string is modified and starts with first mime word with invalid unicode character"; 293} 294{ 295 my $input = $valid_mime . " " . $invalid_mime; 296 my $output = Encode::decode("MIME-Header", $input, Encode::FB_QUIET | Encode::LEAVE_SRC); 297 is $output => Encode::decode("MIME-Header", $valid_mime), "decode with FB_QUIET and LEAVE_SRC flags: output string stops before first mime word with unknown charset"; 298 is $input => $valid_mime . " " . $invalid_mime, "decode with FB_QUIET flag: input string is not modified"; 299} 300{ 301 my $input = $valid_mime . " " . $invalid_mime_unicode; 302 my $output = Encode::decode("MIME-Header", $input, Encode::FB_QUIET | Encode::LEAVE_SRC); 303 is $output => Encode::decode("MIME-Header", $valid_mime), "decode with FB_QUIET and LEAVE_SRC flags: output string stops before first mime word with invalid unicode character"; 304 is $input => $valid_mime . " " . $invalid_mime_unicode, "decode with FB_QUIET flag: input string is not modified"; 305} 306{ 307 my $input = $valid_mime . " " . $invalid_mime; 308 my $output = Encode::decode("MIME-Header", $input, Encode::FB_PERLQQ); 309 is $output => Encode::decode("MIME-Header", $valid_mime) . " " . $invalid_mime, "decode with FB_PERLQQ flag: output string contains unmodified mime word with unknown charset"; 310 is $input => $valid_mime . " " . $invalid_mime, "decode with FB_QUIET flag: input string is not modified"; 311} 312{ 313 my $input = $valid_mime . " " . $invalid_mime_unicode; 314 my $output = Encode::decode("MIME-Header", $input, Encode::FB_PERLQQ); 315 is $output => Encode::decode("MIME-Header", $valid_mime) . '(\xC3)', "decode with FB_PERLQQ flag: output string contains perl qq representation of invalid unicode character"; 316 is $input => $valid_mime . " " . $invalid_mime_unicode, "decode with FB_QUIET flag: input string is not modified"; 317} 318{ 319 my $input = $valid_mime; 320 my $output = Encode::decode("MIME-Header", $input, sub { sprintf("!0x%X!", $_[0]) }); 321 is $output => Encode::decode("MIME-Header", $valid_mime), "decode valid with coderef check: output string is valid"; 322 is $input => $valid_mime, "decode valid with coderef check: input string is not modified"; 323} 324{ 325 my $input = $valid_mime . " " . $invalid_mime; 326 my $output = Encode::decode("MIME-Header", $input, sub { sprintf("!0x%X!", $_[0]) }); 327 is $output => Encode::decode("MIME-Header", $valid_mime) . " " . $invalid_mime, "decode with coderef check: output string contains unmodified mime word with unknown charset"; 328 is $input => $valid_mime . " " . $invalid_mime, "decode with coderef check: input string is not modified"; 329} 330{ 331 my $input = $valid_mime . " " . $invalid_mime_unicode; 332 my $output = Encode::decode("MIME-Header", $input, sub { sprintf("!0x%X!", $_[0]) }); 333 is $output => Encode::decode("MIME-Header", $valid_mime) . '(!0xC3!)', "decode with coderef check: output string contains output from coderef for invalid unicode character"; 334 is $input => $valid_mime . " " . $invalid_mime_unicode, "decode with coderef check: input string is not modified"; 335} 336 337__END__ 338