3 use RT::Test nodb => 1, tests => undef;
9 diag q{'=' char in a leading part before an encoded part};
11 my $str = 'key="plain"; key="=?UTF-8?B?0LzQvtC5X9GE0LDQudC7LmJpbg==?="';
14 RT::I18N::DecodeMIMEWordsToUTF8($str),
15 'key="plain"; key="мой_файл.bin"',
18 } [qr/DecodeMIMEWordsTo.*?called without field name/i];
20 RT::I18N::DecodeMIMEWordsToUTF8($str, 'content-disposition'),
21 'key="plain"; key="мой_файл.bin"',
26 diag q{not compliant with standards, but MUAs send such field when attachment has non-ascii in name};
28 my $str = 'attachment; filename="=?UTF-8?B?0LzQvtC5X9GE0LDQudC7LmJpbg==?="';
31 RT::I18N::DecodeMIMEWordsToUTF8($str),
32 'attachment; filename="мой_файл.bin"',
35 } [qr/DecodeMIMEWordsTo.*?called without field name/i];
37 RT::I18N::DecodeMIMEWordsToUTF8($str, 'content-disposition'),
38 'attachment; filename="мой_файл.bin"',
43 diag q{'=' char in a trailing part after an encoded part};
45 my $str = 'attachment; filename="=?UTF-8?B?0LzQvtC5X9GE0LDQudC7LmJpbg==?="; some_prop="value"';
48 RT::I18N::DecodeMIMEWordsToUTF8($str),
49 'attachment; filename="мой_файл.bin"; some_prop="value"',
52 } [qr/DecodeMIMEWordsTo.*?called without field name/i];
54 RT::I18N::DecodeMIMEWordsToUTF8($str, 'content-disposition'),
55 'attachment; filename="мой_файл.bin"; some_prop="value"',
60 diag q{adding quotes around mime words containing specials when word is already quoted};
62 my $str = 'attachment; filename="=?iso-8859-1?Q?foobar,_?=' . "\n" . '=?iso-8859-1?Q?barfoo.docx?="';
63 my $decoded = 'attachment; filename="foobar, barfoo.docx"';
64 is( RT::I18N::DecodeMIMEWordsToUTF8($str, 'content-disposition'), $decoded, "No added quotes" );
67 diag q{regression test for #5248 from rt3.fsck.com};
69 my $str = qq{Subject: =?ISO-8859-1?Q?Re=3A_=5BXXXXXX=23269=5D_=5BComment=5D_Frag?=}
70 . qq{\n =?ISO-8859-1?Q?e_zu_XXXXXX--xxxxxx_/_Xxxxx=FCxxxxxxxxxx?=};
72 RT::I18N::DecodeMIMEWordsToUTF8($str, 'Subject'),
73 qq{Subject: Re: [XXXXXX#269] [Comment] Frage zu XXXXXX--xxxxxx / Xxxxxüxxxxxxxxxx},
78 diag q{newline and encoded file name};
80 my $str = qq{application/vnd.ms-powerpoint;\n\tname="=?ISO-8859-1?Q?Main_presentation.ppt?="};
83 RT::I18N::DecodeMIMEWordsToUTF8($str),
84 qq{application/vnd.ms-powerpoint;\tname="Main presentation.ppt"},
87 } [qr/DecodeMIMEWordsTo.*?called without field name/i];
89 RT::I18N::DecodeMIMEWordsToUTF8($str,'content-type'),
90 qq{application/vnd.ms-powerpoint; name="Main presentation.ppt"},
98 "attachment; filename*=ISO-8859-1''%74%E9%73%74%2E%74%78%74";
100 RT::I18N::DecodeMIMEWordsToEncoding( $str, 'utf-8', 'Content-Disposition' ),
101 'attachment; filename="tést.txt"',
106 diag q{rfc2231 param continuations};
108 # XXX TODO: test various forms of the continuation stuff
109 # quotes around the values
112 filename*0*=ISO-2022-JP'ja'%1b$B%3f7$7$$%25F%25%2d%259%25H%1b%28B;
114 filename*2*=%1b$B%25I%25%2d%25e%25a%25s%25H%1b%28B;
118 RT::I18N::DecodeMIMEWordsToEncoding( $hdr, 'utf-8', 'Content-Disposition' ),
119 'inline; filename="新しいテキスト ドキュメント.txt"',
120 'decoded continuations as one string'
124 diag q{canonicalize mime word encodings like gb2312};
126 my $str = qq{Subject: =?gb2312?B?1NrKwL3nuPe12Lmy09CzrN9eX1NpbXBsaWZpZWRfQ05fR0IyMzEyYQ==?=
127 \t=?gb2312?B?dHRhY2hlbWVudCB0ZXN0IGluIENOIHNpbXBsaWZpZWQ=?=};
130 RT::I18N::DecodeMIMEWordsToUTF8($str, "Subject"),
131 qq{Subject: 在世界各地共有超過_Simplified_CN_GB2312attachement test in CN simplified},
136 diag q{Whitespace between encoded words should be removed};
139 my $str = "=?utf-8?Q?=E3=82=AD?= =?utf-8?Q?=E3=83=A3?=";
141 RT::I18N::DecodeMIMEWordsToUTF8($str),
143 "whitespace between encoded words is removed",
146 $str = "=?utf-8?Q?=E3=82=AD?= \n =?utf-8?Q?=E3=83=A3?=";
148 RT::I18N::DecodeMIMEWordsToUTF8($str),
150 "newlines between encoded words also removed",
152 } [(qr/DecodeMIMEWordsTo.*?called without field name/i) x 2];
155 diag q{Multiple octets split across QP hunks are correctly reassembled};
158 # This passes even without explicit code to handle it because utf8
159 # is perl's internal string encoding.
160 my $str = "=?utf-8?Q?=E3?= =?utf-8?Q?=82?= =?utf-8?Q?=AD?=";
162 RT::I18N::DecodeMIMEWordsToUTF8($str),
164 "UTF8 character split in three is successfully reassembled",
167 # Non-utf8 encodings thus also must be checked
168 $str = <<EOT; chomp $str;
169 =?gb2312?q?Chinese(gb2312)=20=20=C3=C0=B9=FA=C7=B0=CB=BE=B7=A8=B2=BF=B3?=
170 =?gb2312?q?=A4=C3=E6=BC=FB=C8=F8=B4=EF=C4=B7=BA=F3=B3=C6=C6=E4=D7=B4=CC=AC?=
171 =?gb2312?q?=BA=DC=BA=C3=20=20Chinese=20(gb2312)?=
174 RT::I18N::DecodeMIMEWordsToUTF8($str),
175 "Chinese(gb2312) 美国前司法部长面见萨达姆后称其状态很好 Chinese (gb2312)",
176 "gb2312 character is successfully reassembled",
178 } [(qr/DecodeMIMEWordsTo.*?called without field name/i) x 2];
181 diag "multiple mime words containing special chars already in quotes";
183 my $str = q{attachment; filename="=?ISO-2022-JP?B?Mi4bJEIlSyVlITwlOSVqJWohPCU5GyhC?= =?ISO-2022-JP?B?LnBkZg==?="};
185 RT::I18N::DecodeMIMEWordsToUTF8($str, 'Content-Disposition'),
186 q{attachment; filename="2.ニュースリリース.pdf"},
190 $str = q{attachment; filename="=?UTF-8?Q?2=2E=E3=83=8B=E3=83=A5=E3=83=BC=E3=82=B9=E3=83=AA=E3=83=AA?= =?UTF-8?Q?=E3=83=BC=E3=82=B9=2Epdf?="};
192 RT::I18N::DecodeMIMEWordsToUTF8($str, 'Content-Disposition'),
193 q{attachment; filename="2.ニュースリリース.pdf"},
198 diag "mime word combined with text in quoted filename property";
200 my $str = q{attachment; filename="=?UTF-8?B?Q2VjaSBuJ2VzdCBwYXMgdW5l?= pipe.pdf"};
202 RT::I18N::DecodeMIMEWordsToUTF8($str, 'Content-Disposition'),
203 q{attachment; filename="Ceci n'est pas une pipe.pdf"},
207 $str = q{attachment; filename="=?UTF-8?B?Q2VjaSBuJ2VzdCBwYXMgdW5lLi4u?= pipe.pdf"};
209 RT::I18N::DecodeMIMEWordsToUTF8($str, 'Content-Disposition'),
210 q{attachment; filename="Ceci n'est pas une... pipe.pdf"},
214 $str = q{attachment; filename="=?UTF-8?Q?Ceci n'est pas une?= pipe.pdf"};
216 RT::I18N::DecodeMIMEWordsToUTF8($str, 'Content-Disposition'),
217 q{attachment; filename="Ceci n'est pas une pipe.pdf"},
221 $str = q{attachment; filename="=?UTF-8?Q?Ceci n'est pas une...?= pipe.pdf"};
223 RT::I18N::DecodeMIMEWordsToUTF8($str, 'Content-Disposition'),
224 q{attachment; filename="Ceci n'est pas une... pipe.pdf"},
229 diag "quotes in filename";
231 my $str = q{attachment; filename="=?UTF-8?B?YSAicXVvdGVkIiBmaWxl?="};
233 RT::I18N::DecodeMIMEWordsToUTF8($str, 'Content-Disposition'),
234 q{attachment; filename="a \"quoted\" file"},
235 "quoted filename correctly decoded"