alecpl
2010-12-09 ad399a95dded2a0378eb410569dcac65c3c9c44a
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     $this->app = rcmail::get_instance();
17     $this->app->imap_init(false);
18   }
19
20   /**
21    * Test decoding of single e-mail address strings
22    * Uses rcube_imap::decode_address_list()
23    */
24   function test_decode_single_address()
25   {
26     $headers = array(
27         0  => 'test@domain.tld',
28         1  => '<test@domain.tld>',
29         2  => 'Test <test@domain.tld>',
30         3  => 'Test Test <test@domain.tld>',
31         4  => 'Test Test<test@domain.tld>',
32         5  => '"Test Test" <test@domain.tld>',
33         6  => '"Test Test"<test@domain.tld>',
34         7  => '"Test \\" Test" <test@domain.tld>',
35         8  => '"Test<Test" <test@domain.tld>',
36         9  => '=?ISO-8859-1?B?VGVzdAo=?= <test@domain.tld>',
37         10 => '=?ISO-8859-1?B?VGVzdAo=?=<test@domain.tld>', // #1487068
38     );
39
40     $results = array(
41         0  => array('', 'test@domain.tld'),
42         1  => array('', 'test@domain.tld'),
43         2  => array('Test', 'test@domain.tld'),
44         3  => array('Test Test', 'test@domain.tld'),
45         4  => array('Test Test', 'test@domain.tld'),
46         5  => array('Test Test', 'test@domain.tld'),
47         6  => array('Test Test', 'test@domain.tld'),
48         7  => array('Test " Test', 'test@domain.tld'),
49         8  => array('Test<Test', 'test@domain.tld'),
50         9  => array('Test', 'test@domain.tld'),
51         10 => array('Test', 'test@domain.tld'),
52     );
53
54     foreach ($headers as $idx => $header) {
55       $res = $this->app->imap->decode_address_list($header);
56
57       $this->assertEqual(1, count($res), "Rows number in result for header: " . $header);
58       $this->assertEqual($results[$idx][0], $res[1]['name'], "Name part decoding for header: " . $header);
59       $this->assertEqual($results[$idx][1], $res[1]['mailto'], "Name part decoding for header: " . $header);
60     }
61   }
62
63 }