| 1 | <?php |
|---|
| 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 |
|---|
| 19 | * Uses rcube_mime::decode_address_list() |
|---|
| 20 | */ |
|---|
| 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 |
|---|
| 35 | // comments in address (#1487673) |
|---|
| 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>', |
|---|
| 44 | // 1487939 |
|---|
| 45 | 19 => 'Test <"test test"@domain.tld>', |
|---|
| 46 | 20 => '<"test test"@domain.tld>', |
|---|
| 47 | 21 => '"test test"@domain.tld', |
|---|
| 48 | ); |
|---|
| 49 | |
|---|
| 50 | $results = array( |
|---|
| 51 | 0 => array(1, '', 'test@domain.tld'), |
|---|
| 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'), |
|---|
| 70 | 19 => array(1, 'Test', '"test test"@domain.tld'), |
|---|
| 71 | 20 => array(1, '', '"test test"@domain.tld'), |
|---|
| 72 | 21 => array(1, '', '"test test"@domain.tld'), |
|---|
| 73 | ); |
|---|
| 74 | |
|---|
| 75 | foreach ($headers as $idx => $header) { |
|---|
| 76 | $res = rcube_mime::decode_address_list($header); |
|---|
| 77 | |
|---|
| 78 | $this->assertEqual($results[$idx][0], count($res), "Rows number in result for header: " . $header); |
|---|
| 79 | $this->assertEqual($results[$idx][1], $res[1]['name'], "Name part decoding for header: " . $header); |
|---|
| 80 | $this->assertEqual($results[$idx][2], $res[1]['mailto'], "Email part decoding for header: " . $header); |
|---|
| 81 | } |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | /** |
|---|
| 85 | * Test decoding of header values |
|---|
| 86 | * Uses rcube_mime::decode_mime_string() |
|---|
| 87 | */ |
|---|
| 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) { |
|---|
| 123 | $res = rcube_mime::decode_mime_string($item['in'], 'UTF-8'); |
|---|
| 124 | $res = quoted_printable_encode($res); |
|---|
| 125 | |
|---|
| 126 | $this->assertEqual($item['out'], $res, "Header decoding for: " . $idx); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | } |
|---|
| 130 | } |
|---|