commit | author | age
|
13326b
|
1 |
<?php |
A |
2 |
|
|
3 |
/** |
|
4 |
* Test class to test messages decoding functions |
|
5 |
* |
|
6 |
* @package Tests |
|
7 |
*/ |
|
8 |
class rcube_test_maildecode extends UnitTestCase |
|
9 |
{ |
|
10 |
private $app; |
|
11 |
|
|
12 |
function __construct() |
|
13 |
{ |
|
14 |
$this->UnitTestCase('Mail headers decoding tests'); |
|
15 |
} |
|
16 |
|
|
17 |
/** |
|
18 |
* Test decoding of single e-mail address strings |
1c4f23
|
19 |
* Uses rcube_mime::decode_address_list() |
13326b
|
20 |
*/ |
A |
21 |
function test_decode_single_address() |
|
22 |
{ |
|
23 |
$headers = array( |
|
24 |
0 => 'test@domain.tld', |
|
25 |
1 => '<test@domain.tld>', |
|
26 |
2 => 'Test <test@domain.tld>', |
|
27 |
3 => 'Test Test <test@domain.tld>', |
|
28 |
4 => 'Test Test<test@domain.tld>', |
|
29 |
5 => '"Test Test" <test@domain.tld>', |
|
30 |
6 => '"Test Test"<test@domain.tld>', |
|
31 |
7 => '"Test \\" Test" <test@domain.tld>', |
|
32 |
8 => '"Test<Test" <test@domain.tld>', |
|
33 |
9 => '=?ISO-8859-1?B?VGVzdAo=?= <test@domain.tld>', |
|
34 |
10 => '=?ISO-8859-1?B?VGVzdAo=?=<test@domain.tld>', // #1487068 |
6c68cb
|
35 |
// comments in address (#1487673) |
A |
36 |
11 => 'Test (comment) <test@domain.tld>', |
|
37 |
12 => '"Test" (comment) <test@domain.tld>', |
|
38 |
13 => '"Test (comment)" (comment) <test@domain.tld>', |
|
39 |
14 => '(comment) <test@domain.tld>', |
|
40 |
15 => 'Test <test@(comment)domain.tld>', |
|
41 |
16 => 'Test Test ((comment)) <test@domain.tld>', |
|
42 |
17 => 'test@domain.tld (comment)', |
|
43 |
18 => '"Test,Test" <test@domain.tld>', |
6d0ada
|
44 |
// 1487939 |
A |
45 |
19 => 'Test <"test test"@domain.tld>', |
218589
|
46 |
20 => '<"test test"@domain.tld>', |
A |
47 |
21 => '"test test"@domain.tld', |
13326b
|
48 |
); |
A |
49 |
|
|
50 |
$results = array( |
6c68cb
|
51 |
0 => array(1, '', 'test@domain.tld'), |
A |
52 |
1 => array(1, '', 'test@domain.tld'), |
|
53 |
2 => array(1, 'Test', 'test@domain.tld'), |
|
54 |
3 => array(1, 'Test Test', 'test@domain.tld'), |
|
55 |
4 => array(1, 'Test Test', 'test@domain.tld'), |
|
56 |
5 => array(1, 'Test Test', 'test@domain.tld'), |
|
57 |
6 => array(1, 'Test Test', 'test@domain.tld'), |
|
58 |
7 => array(1, 'Test " Test', 'test@domain.tld'), |
|
59 |
8 => array(1, 'Test<Test', 'test@domain.tld'), |
|
60 |
9 => array(1, 'Test', 'test@domain.tld'), |
|
61 |
10 => array(1, 'Test', 'test@domain.tld'), |
|
62 |
11 => array(1, 'Test', 'test@domain.tld'), |
|
63 |
12 => array(1, 'Test', 'test@domain.tld'), |
|
64 |
13 => array(1, 'Test (comment)', 'test@domain.tld'), |
|
65 |
14 => array(1, '', 'test@domain.tld'), |
|
66 |
15 => array(1, 'Test', 'test@domain.tld'), |
|
67 |
16 => array(1, 'Test Test', 'test@domain.tld'), |
|
68 |
17 => array(1, '', 'test@domain.tld'), |
|
69 |
18 => array(1, 'Test,Test', 'test@domain.tld'), |
6d0ada
|
70 |
19 => array(1, 'Test', '"test test"@domain.tld'), |
218589
|
71 |
20 => array(1, '', '"test test"@domain.tld'), |
A |
72 |
21 => array(1, '', '"test test"@domain.tld'), |
13326b
|
73 |
); |
A |
74 |
|
|
75 |
foreach ($headers as $idx => $header) { |
1c4f23
|
76 |
$res = rcube_mime::decode_address_list($header); |
13326b
|
77 |
|
6c68cb
|
78 |
$this->assertEqual($results[$idx][0], count($res), "Rows number in result for header: " . $header); |
A |
79 |
$this->assertEqual($results[$idx][1], $res[1]['name'], "Name part decoding for header: " . $header); |
6d0ada
|
80 |
$this->assertEqual($results[$idx][2], $res[1]['mailto'], "Email part decoding for header: " . $header); |
13326b
|
81 |
} |
A |
82 |
} |
|
83 |
|
4f8be4
|
84 |
/** |
A |
85 |
* Test decoding of header values |
1c4f23
|
86 |
* Uses rcube_mime::decode_mime_string() |
4f8be4
|
87 |
*/ |
A |
88 |
function test_header_decode_qp() |
|
89 |
{ |
|
90 |
$test = array( |
|
91 |
// #1488232: invalid character "?" |
|
92 |
'quoted-printable (1)' => array( |
|
93 |
'in' => '=?utf-8?Q?Certifica=C3=A7=C3=A3??=', |
|
94 |
'out' => 'Certifica=C3=A7=C3=A3?', |
|
95 |
), |
|
96 |
'quoted-printable (2)' => array( |
|
97 |
'in' => '=?utf-8?Q?Certifica=?= =?utf-8?Q?C3=A7=C3=A3?=', |
|
98 |
'out' => 'Certifica=C3=A7=C3=A3', |
|
99 |
), |
|
100 |
'quoted-printable (3)' => array( |
|
101 |
'in' => '=?utf-8?Q??= =?utf-8?Q??=', |
|
102 |
'out' => '', |
|
103 |
), |
|
104 |
'quoted-printable (4)' => array( |
|
105 |
'in' => '=?utf-8?Q??= a =?utf-8?Q??=', |
|
106 |
'out' => ' a ', |
|
107 |
), |
|
108 |
'quoted-printable (5)' => array( |
|
109 |
'in' => '=?utf-8?Q?a?= =?utf-8?Q?b?=', |
|
110 |
'out' => 'ab', |
|
111 |
), |
|
112 |
'quoted-printable (6)' => array( |
|
113 |
'in' => '=?utf-8?Q? ?= =?utf-8?Q?a?=', |
|
114 |
'out' => ' a', |
|
115 |
), |
|
116 |
'quoted-printable (7)' => array( |
|
117 |
'in' => '=?utf-8?Q?___?= =?utf-8?Q?a?=', |
|
118 |
'out' => ' a', |
|
119 |
), |
|
120 |
); |
|
121 |
|
|
122 |
foreach ($test as $idx => $item) { |
1c4f23
|
123 |
$res = rcube_mime::decode_mime_string($item['in'], 'UTF-8'); |
4f8be4
|
124 |
$res = quoted_printable_encode($res); |
A |
125 |
|
|
126 |
$this->assertEqual($item['out'], $res, "Header decoding for: " . $idx); |
|
127 |
} |
|
128 |
|
|
129 |
} |
13326b
|
130 |
} |