|
ferencd@0
|
1 //
|
|
ferencd@0
|
2 // VMime library (http://www.vmime.org)
|
|
ferencd@0
|
3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
|
|
ferencd@0
|
4 //
|
|
ferencd@0
|
5 // This program is free software; you can redistribute it and/or
|
|
ferencd@0
|
6 // modify it under the terms of the GNU General Public License as
|
|
ferencd@0
|
7 // published by the Free Software Foundation; either version 3 of
|
|
ferencd@0
|
8 // the License, or (at your option) any later version.
|
|
ferencd@0
|
9 //
|
|
ferencd@0
|
10 // This program is distributed in the hope that it will be useful,
|
|
ferencd@0
|
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
ferencd@0
|
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
ferencd@0
|
13 // General Public License for more details.
|
|
ferencd@0
|
14 //
|
|
ferencd@0
|
15 // You should have received a copy of the GNU General Public License along
|
|
ferencd@0
|
16 // with this program; if not, write to the Free Software Foundation, Inc.,
|
|
ferencd@0
|
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
ferencd@0
|
18 //
|
|
ferencd@0
|
19 // Linking this library statically or dynamically with other modules is making
|
|
ferencd@0
|
20 // a combined work based on this library. Thus, the terms and conditions of
|
|
ferencd@0
|
21 // the GNU General Public License cover the whole combination.
|
|
ferencd@0
|
22 //
|
|
ferencd@0
|
23
|
|
ferencd@0
|
24 #include "tests/testUtils.hpp"
|
|
ferencd@0
|
25
|
|
ferencd@0
|
26
|
|
ferencd@0
|
27 VMIME_TEST_SUITE_BEGIN(mailboxTest)
|
|
ferencd@0
|
28
|
|
ferencd@0
|
29 VMIME_TEST_LIST_BEGIN
|
|
ferencd@0
|
30 VMIME_TEST(testParse)
|
|
ferencd@0
|
31 VMIME_TEST(testEmptyEmailAddress)
|
|
ferencd@0
|
32 VMIME_TEST(testSeparatorInComment)
|
|
ferencd@0
|
33 VMIME_TEST_LIST_END
|
|
ferencd@0
|
34
|
|
ferencd@0
|
35
|
|
ferencd@0
|
36 void testParse()
|
|
ferencd@0
|
37 {
|
|
ferencd@0
|
38 static const vmime::string testSuitesParse[] =
|
|
ferencd@0
|
39 {
|
|
ferencd@0
|
40 // Test 1
|
|
ferencd@0
|
41 "My (this is a comment)name <me(another \\)comment) @ somewhere(else).com>",
|
|
ferencd@0
|
42
|
|
ferencd@0
|
43 "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=My name]]], email=me@somewhere.com]]]",
|
|
ferencd@0
|
44
|
|
ferencd@0
|
45 // Test 2
|
|
ferencd@0
|
46 "mailbox1 <mailbox@one>,;,,, ,, ,,;group1:mailbox1@group1, mailbox2@group2,,\"mailbox #3\" <mailbox3@group2>;, <mailbox@two>,,,,,,,,=?iso-8859-1?q?mailbox_number_3?= <mailbox@three>, =?abc?Q?mailbox?= =?def?Q?_number_4?= <mailbox@four>",
|
|
ferencd@0
|
47
|
|
ferencd@0
|
48 "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=mailbox1]]], email=mailbox@one],[mailbox-group: name=[text: [[word: charset=us-ascii, buffer=group1]]], list=[[mailbox: name=[text: []], email=mailbox1@group1],[mailbox: name=[text: []], email=mailbox2@group2],[mailbox: name=[text: [[word: charset=us-ascii, buffer=mailbox #3]]], email=mailbox3@group2]]],[mailbox: name=[text: []], email=mailbox@two],[mailbox: name=[text: [[word: charset=iso-8859-1, buffer=mailbox number 3]]], email=mailbox@three],[mailbox: name=[text: [[word: charset=abc, buffer=mailbox],[word: charset=def, buffer= number 4]]], email=mailbox@four]]]",
|
|
ferencd@0
|
49
|
|
ferencd@0
|
50 // Test 3
|
|
ferencd@0
|
51 "John Doe <john.doe@acme.com>",
|
|
ferencd@0
|
52
|
|
ferencd@0
|
53 "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John Doe]]], email=john.doe@acme.com]]]",
|
|
ferencd@0
|
54
|
|
ferencd@0
|
55 // Test 4
|
|
ferencd@0
|
56 "john.doe@acme.com (John Doe)",
|
|
ferencd@0
|
57
|
|
ferencd@0
|
58 "[address-list: [[mailbox: name=[text: []], email=john.doe@acme.com]]]",
|
|
ferencd@0
|
59
|
|
ferencd@0
|
60 // Test 5
|
|
ferencd@0
|
61 "John.Doe(ignore)@acme.com (John Doe)",
|
|
ferencd@0
|
62
|
|
ferencd@0
|
63 "[address-list: [[mailbox: name=[text: []], email=John.Doe@acme.com]]]",
|
|
ferencd@0
|
64
|
|
ferencd@0
|
65 // Test 6
|
|
ferencd@0
|
66 "<john.doe@acme.com>",
|
|
ferencd@0
|
67
|
|
ferencd@0
|
68 "[address-list: [[mailbox: name=[text: []], email=john.doe@acme.com]]]",
|
|
ferencd@0
|
69
|
|
ferencd@0
|
70 // Test 7
|
|
ferencd@0
|
71 "john.doe@acme.com",
|
|
ferencd@0
|
72
|
|
ferencd@0
|
73 "[address-list: [[mailbox: name=[text: []], email=john.doe@acme.com]]]",
|
|
ferencd@0
|
74
|
|
ferencd@0
|
75 // Test 8
|
|
ferencd@0
|
76 "\"John Doe\" <john.doe@acme.com>",
|
|
ferencd@0
|
77
|
|
ferencd@0
|
78 "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John Doe]]], email=john.doe@acme.com]]]",
|
|
ferencd@0
|
79
|
|
ferencd@0
|
80 // Test 9
|
|
ferencd@0
|
81 "=?us-ascii?q?John?=<john.doe@acme.com>",
|
|
ferencd@0
|
82
|
|
ferencd@0
|
83 "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John]]], email=john.doe@acme.com]]]",
|
|
ferencd@0
|
84
|
|
ferencd@0
|
85 // Test 10
|
|
ferencd@0
|
86 "\"John\"<john.doe@acme.com>",
|
|
ferencd@0
|
87
|
|
ferencd@0
|
88 "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John]]], email=john.doe@acme.com]]]",
|
|
ferencd@0
|
89
|
|
ferencd@0
|
90 // Test 11
|
|
ferencd@0
|
91 "John<john.doe@acme.com>",
|
|
ferencd@0
|
92
|
|
ferencd@0
|
93 "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John]]], email=john.doe@acme.com]]]"
|
|
ferencd@0
|
94 };
|
|
ferencd@0
|
95
|
|
ferencd@0
|
96 for (unsigned int i = 0 ; i < sizeof(testSuitesParse) / sizeof(testSuitesParse[0]) / 2 ; ++i)
|
|
ferencd@0
|
97 {
|
|
ferencd@0
|
98 vmime::string in = testSuitesParse[i * 2];
|
|
ferencd@0
|
99 vmime::string out = testSuitesParse[i * 2 + 1];
|
|
ferencd@0
|
100
|
|
ferencd@0
|
101 std::ostringstream oss;
|
|
ferencd@0
|
102 oss << "Test " << (i + 1);
|
|
ferencd@0
|
103
|
|
ferencd@0
|
104 vmime::addressList addrList;
|
|
ferencd@0
|
105 addrList.parse(in);
|
|
ferencd@0
|
106
|
|
ferencd@0
|
107 std::ostringstream cmp;
|
|
ferencd@0
|
108 cmp << addrList;
|
|
ferencd@0
|
109
|
|
ferencd@0
|
110 VASSERT_EQ(oss.str(), out, cmp.str());
|
|
ferencd@0
|
111 }
|
|
ferencd@0
|
112 }
|
|
ferencd@0
|
113
|
|
ferencd@0
|
114 void testEmptyEmailAddress()
|
|
ferencd@0
|
115 {
|
|
ferencd@0
|
116 vmime::addressList addrList;
|
|
ferencd@0
|
117 addrList.parse("\"Full Name\" <>");
|
|
ferencd@0
|
118
|
|
ferencd@0
|
119 VASSERT_EQ("count", 1, addrList.getAddressCount());
|
|
ferencd@0
|
120 VASSERT_EQ("!group", false, addrList.getAddressAt(0)->isGroup());
|
|
ferencd@0
|
121
|
|
ferencd@0
|
122 vmime::shared_ptr <vmime::mailbox> mbox =
|
|
ferencd@0
|
123 vmime::dynamicCast <vmime::mailbox>(addrList.getAddressAt(0));
|
|
ferencd@0
|
124
|
|
ferencd@0
|
125 VASSERT_EQ("name", "Full Name", mbox->getName());
|
|
ferencd@0
|
126 VASSERT_EQ("email", "", mbox->getEmail());
|
|
ferencd@0
|
127 }
|
|
ferencd@0
|
128
|
|
ferencd@0
|
129 void testSeparatorInComment()
|
|
ferencd@0
|
130 {
|
|
ferencd@0
|
131 vmime::addressList addrList;
|
|
ferencd@0
|
132 addrList.parse("aaa(comment,comment)@vmime.org, bbb@vmime.org");
|
|
ferencd@0
|
133
|
|
ferencd@0
|
134 VASSERT_EQ("count", 2, addrList.getAddressCount());
|
|
ferencd@0
|
135
|
|
ferencd@0
|
136 vmime::shared_ptr <vmime::mailbox> mbox1 =
|
|
ferencd@0
|
137 vmime::dynamicCast <vmime::mailbox>(addrList.getAddressAt(0));
|
|
ferencd@0
|
138 vmime::shared_ptr <vmime::mailbox> mbox2 =
|
|
ferencd@0
|
139 vmime::dynamicCast <vmime::mailbox>(addrList.getAddressAt(1));
|
|
ferencd@0
|
140
|
|
ferencd@0
|
141 VASSERT_EQ("name1", vmime::text(), mbox1->getName());
|
|
ferencd@0
|
142 VASSERT_EQ("email1", "aaa@vmime.org", mbox1->getEmail());
|
|
ferencd@0
|
143
|
|
ferencd@0
|
144 VASSERT_EQ("name2", vmime::text(), mbox2->getName());
|
|
ferencd@0
|
145 VASSERT_EQ("email2", "bbb@vmime.org", mbox2->getEmail());
|
|
ferencd@0
|
146 }
|
|
ferencd@0
|
147
|
|
ferencd@0
|
148 VMIME_TEST_SUITE_END
|
|
ferencd@0
|
149
|