1--TEST--
2iconv_mime_decode()
3--EXTENSIONS--
4iconv
5--INI--
6iconv.internal_charset=iso-8859-1
7--FILE--
8<?php
9function my_error_handler($errno, $errmsg, $filename, $linenum)
10{
11    echo "$errno: $errmsg\n";
12}
13set_error_handler('my_error_handler');
14
15function do_single_test($header)
16{
17    global $mode;
18
19    $result = iconv_mime_decode($header, $mode, "UTF-8");
20    printf("(%d) \"%s\"\n", iconv_strlen($result, "UTF-8"), $result);
21}
22
23function do_regression_test()
24{
25    do_single_test(<<< HERE
26Subject: =?ISO-8859-1?Q?Pr=FCfung?=
27    =?ISO-8859-1*de_DE?Q?Pr=FCfung?=\t
28     =?ISO-8859-2?Q?k=F9=D4=F1=D3let?=
29HERE
30);
31    do_single_test(<<< HERE
32Subject: =?ISO-8859-1?Q?Pr=FCfung?= =?ISO-8859-1*de_DE?Q?=20Pr=FCfung?= \t  =?ISO-8859-2?Q?k=F9=D4=F1=D3let?=
33HERE
34);
35    do_single_test(<<< HERE
36Subject: =?ISO-8859-1?Q?Pr=FCfung?==?ISO-8859-1*de_DE?Q?Pr=FCfung?==?ISO-8859-2?Q?k=F9=D4=F1=D3let?=
37HERE
38);
39    do_single_test(<<< HERE
40Subject: =?ISO-8859-1?Q?Pr=FCfung?= =?ISO-8859-1*de_DE?Q?Pr=FCfung??   =?ISO-8859-2?X?k=F9=D4=F1=D3let?=
41HERE
42);
43    do_single_test(<<< HERE
44From: =?ISO-2022-JP?B?GyRCJTUbKEI=?=
45 =?ISO-2022-JP?B?GyRCJXMlVxsoQg==?=
46 =?ISO-2022-JP?B?GyRCJWtKOBsoQg==?=
47 =?ISO-2022-JP?B?GyRCO3pOcxsoQg==?=
48 =?ISO-2022-JP?B?GyRCJTUlcxsoQg==?=
49 =?ISO-2022-JP?B?GyRCJVclaxsoQg==?=
50 =?ISO-2022-JP?B?GyRCSjg7ehsoQg==?=
51 =?ISO-2022-JP?B?GyRCTnNGfBsoQg==?=
52 =?ISO-2022-JP?B?GyRCS1w4bBsoQg==?=
53 =?ISO-2022-JP?B?GyRCJUYlLRsoQg==?=
54 =?ISO-2022-JP?B?GyRCJTklSBsoQg==?=
55HERE
56);
57}
58
59$mode = 0;
60do_regression_test();
61$mode = ICONV_MIME_DECODE_STRICT;
62do_regression_test();
63$mode = ICONV_MIME_DECODE_CONTINUE_ON_ERROR;
64do_regression_test();
65$mode = ICONV_MIME_DECODE_STRICT | ICONV_MIME_DECODE_CONTINUE_ON_ERROR;
66do_regression_test();
67?>
68--EXPECT--
69(31) "Subject: PrüfungPrüfungkůÔńÓlet"
70(32) "Subject: Prüfung PrüfungkůÔńÓlet"
71(31) "Subject: PrüfungPrüfungkůÔńÓlet"
722: iconv_mime_decode(): Malformed string
73(0) ""
74(27) "From: サンプル文字列サンプル文字列日本語テキスト"
75(31) "Subject: PrüfungPrüfungkůÔńÓlet"
76(32) "Subject: Prüfung PrüfungkůÔńÓlet"
77(100) "Subject: =?ISO-8859-1?Q?Pr=FCfung?==?ISO-8859-1*de_DE?Q?Pr=FCfung?==?ISO-8859-2?Q?k=F9=D4=F1=D3let?="
782: iconv_mime_decode(): Malformed string
79(0) ""
80(27) "From: サンプル文字列サンプル文字列日本語テキスト"
81(31) "Subject: PrüfungPrüfungkůÔńÓlet"
82(32) "Subject: Prüfung PrüfungkůÔńÓlet"
83(31) "Subject: PrüfungPrüfungkůÔńÓlet"
84(84) "Subject: Prüfung=?ISO-8859-1*de_DE?Q?Pr=FCfung??   =?ISO-8859-2?X?k=F9=D4=F1=D3let?="
85(27) "From: サンプル文字列サンプル文字列日本語テキスト"
86(31) "Subject: PrüfungPrüfungkůÔńÓlet"
87(32) "Subject: Prüfung PrüfungkůÔńÓlet"
88(100) "Subject: =?ISO-8859-1?Q?Pr=FCfung?==?ISO-8859-1*de_DE?Q?Pr=FCfung?==?ISO-8859-2?Q?k=F9=D4=F1=D3let?="
89(84) "Subject: Prüfung=?ISO-8859-1*de_DE?Q?Pr=FCfung??   =?ISO-8859-2?X?k=F9=D4=F1=D3let?="
90(27) "From: サンプル文字列サンプル文字列日本語テキスト"
91