#include #include "SmtpClient.h" namespace { std::string Decode(const std::string& in) { static const std::string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; std::string out; int val = 0, bits = -8; for (const char c : in) { const auto pos = chars.find(c); if (pos == std::string::npos) continue; val = (val << 6) + static_cast(pos); bits += 6; if (bits >= 0) { out.push_back(static_cast((val >> bits) & 0xFF)); bits -= 8; } } return out; } Smtp::Config TestConfig() { Smtp::Config config; config.fromAddress = "noreply@example.com"; config.fromName = "Test Server"; return config; } } TEST(SmtpTest, ValidatesAddresses) { EXPECT_TRUE(Smtp::IsValidAddress("player@example.com")); EXPECT_TRUE(Smtp::IsValidAddress("first.last+tag@sub.example.co.uk")); EXPECT_FALSE(Smtp::IsValidAddress("no-at-sign.example.com")); EXPECT_FALSE(Smtp::IsValidAddress("two@@example.com")); EXPECT_FALSE(Smtp::IsValidAddress("@example.com")); EXPECT_FALSE(Smtp::IsValidAddress("user@localhost")); EXPECT_FALSE(Smtp::IsValidAddress("user@example.com>\r\nRCPT TO:\r\n"), std::string::npos); EXPECT_NE(data.find("To: \r\n"), std::string::npos); EXPECT_NE(data.find("Content-Transfer-Encoding: base64\r\n"), std::string::npos); const auto body = data.substr(data.find("\r\n\r\n") + 4); EXPECT_EQ(Decode(body), "Line one\r\nLine two\r\n.starts with a dot"); }