-
Notifications
You must be signed in to change notification settings - Fork 373
/
Copy pathMailMessageTest.C
166 lines (128 loc) · 4.92 KB
/
MailMessageTest.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* Copyright (C) 2023 Emweb bv, Herent, Belgium.
*
* See the LICENSE file for terms of use.
*/
#include <boost/test/unit_test.hpp>
#include <Wt/WApplication.h>
#include <Wt/WDate.h>
#include <Wt/WDateTime.h>
#include <Wt/WTime.h>
#include <Wt/cpp20/tz.hpp>
#include <Wt/Mail/Message.h>
#include <Wt/Test/WTestEnvironment.h>
#include <string>
#include <web/FileUtils.h>
#include <sstream>
using namespace Wt;
using namespace Wt::Mail;
BOOST_AUTO_TEST_CASE( Message_header_RFC5322_date )
{
// Tests whether the mail message header is in the RFC 5322 compliant
// format. Meaning the name of the day and month are in English.
#ifdef WT_WIN32
Wt::cpp20::date::set_install("./tzdata");
#endif
Wt::Test::WTestEnvironment environment;
Wt::WLocale locale = environment.locale();
locale.setTimeZone(Wt::cpp20::date::locate_zone("GB"));
environment.setLocale(locale);
Wt::WApplication app(environment);
std::string file = app.appRoot() + "types/days_months_names";
BOOST_REQUIRE(Wt::FileUtils::exists(file + ".xml"));
app.messageResourceBundle().use(file);
Wt::WDateTime datetime(Wt::WDate(2022, 1, 2), Wt::WTime(10, 8, 9));
BOOST_TEST(datetime.toString() == "Dom Ene 2 10:08:09 2022");
BOOST_TEST(datetime.toString("dddd MMMM") == "Domigo Enero");
std::stringstream ss;
Message message;
message.setDate(datetime.toLocalTime(environment.locale()));
message.write(ss);
auto messageString = ss.str();
auto match = "Sun, 02 Jan 2022 10:08:09 +0000";
BOOST_REQUIRE(messageString.find(match) != std::string::npos);
}
BOOST_AUTO_TEST_CASE( Message_header_RFC5322_to_address_no_display )
{
Message message;
message.addRecipient(Wt::Mail::RecipientType::To, Wt::Mail::Mailbox("[email protected]"));
std::stringstream ss;
message.write(ss);
auto messageString = ss.str();
auto match = "To: <[email protected]>\r\n";
BOOST_REQUIRE(messageString.find(match) != std::string::npos);
}
BOOST_AUTO_TEST_CASE( Message_header_RFC5322_to_address_with_display )
{
Message message;
message.addRecipient(Wt::Mail::RecipientType::To, Wt::Mail::Mailbox("[email protected]", "Test1"));
std::stringstream ss;
message.write(ss);
auto messageString = ss.str();
auto match = "To: Test1 <[email protected]>\r\n";
BOOST_REQUIRE(messageString.find(match) != std::string::npos);
}
BOOST_AUTO_TEST_CASE( Message_header_RFC5322_to_addresses_no_display )
{
Message message;
message.addRecipient(Wt::Mail::RecipientType::To, Wt::Mail::Mailbox("[email protected]"));
message.addRecipient(Wt::Mail::RecipientType::To, Wt::Mail::Mailbox("[email protected]"));
std::stringstream ss;
message.write(ss);
auto messageString = ss.str();
auto match = "To: <[email protected]>, <[email protected]>\r\n";
BOOST_REQUIRE(messageString.find(match) != std::string::npos);
}
BOOST_AUTO_TEST_CASE( Message_header_RFC5322_to_addresses_with_display )
{
Message message;
message.addRecipient(Wt::Mail::RecipientType::To, Wt::Mail::Mailbox("[email protected]", "Test1"));
message.addRecipient(Wt::Mail::RecipientType::To, Wt::Mail::Mailbox("[email protected]"));
std::stringstream ss;
message.write(ss);
auto messageString = ss.str();
auto match = "To: Test1 <[email protected]>, <[email protected]>\r\n";
BOOST_REQUIRE(messageString.find(match) != std::string::npos);
}
BOOST_AUTO_TEST_CASE( Message_header_RFC5322_cc_address_no_display )
{
Message message;
message.addRecipient(Wt::Mail::RecipientType::Cc, Wt::Mail::Mailbox("[email protected]"));
std::stringstream ss;
message.write(ss);
auto messageString = ss.str();
auto match = "Cc: <[email protected]>\r\n";
BOOST_REQUIRE(messageString.find(match) != std::string::npos);
}
BOOST_AUTO_TEST_CASE( Message_header_RFC5322_cc_address_with_display )
{
Message message;
message.addRecipient(Wt::Mail::RecipientType::Cc, Wt::Mail::Mailbox("[email protected]", "Test1"));
std::stringstream ss;
message.write(ss);
auto messageString = ss.str();
auto match = "Cc: Test1 <[email protected]>\r\n";
BOOST_REQUIRE(messageString.find(match) != std::string::npos);
}
BOOST_AUTO_TEST_CASE( Message_header_RFC5322_cc_addresses_no_display )
{
Message message;
message.addRecipient(Wt::Mail::RecipientType::Cc, Wt::Mail::Mailbox("[email protected]"));
message.addRecipient(Wt::Mail::RecipientType::Cc, Wt::Mail::Mailbox("[email protected]"));
std::stringstream ss;
message.write(ss);
auto messageString = ss.str();
auto match = "Cc: <[email protected]>, <[email protected]>\r\n";
BOOST_REQUIRE(messageString.find(match) != std::string::npos);
}
BOOST_AUTO_TEST_CASE( Message_header_RFC5322_cc_addresses_with_display )
{
Message message;
message.addRecipient(Wt::Mail::RecipientType::Cc, Wt::Mail::Mailbox("[email protected]", "Test1"));
message.addRecipient(Wt::Mail::RecipientType::Cc, Wt::Mail::Mailbox("[email protected]"));
std::stringstream ss;
message.write(ss);
auto messageString = ss.str();
auto match = "Cc: Test1 <[email protected]>, <[email protected]>\r\n";
BOOST_REQUIRE(messageString.find(match) != std::string::npos);
}