aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Dmitry Isaikin <isaikin@corp.mail.ru>2016-02-09 16:12:15 +0300
committerGravatar Dmitry Isaikin <isaikin@corp.mail.ru>2016-02-09 16:35:06 +0300
commite554610cb5b5820eae81217066d594c6f1999089 (patch)
tree5c0c29428e1a87ae80d3fd69a254d51e02137b93 /tests
parentd1e587a9cd06a9cf5f619642ec17506d589c687b (diff)
Add some tests for sending message from file via SMTP
Diffstat (limited to 'tests')
-rw-r--r--tests/test-all.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/test-all.cpp b/tests/test-all.cpp
index ba79a3ea..de5c50a6 100644
--- a/tests/test-all.cpp
+++ b/tests/test-all.cpp
@@ -197,6 +197,49 @@ static void testSMTP(mailcore::Data * data)
smtp->release();
}
+static void parseAddressesFromRfc822(mailcore::String * filename, mailcore::Array ** pRecipients, mailcore::Address ** pFrom)
+{
+ mailcore::MessageParser * parser = mailcore::MessageParser::messageParserWithContentsOfFile(filename);
+
+ mailcore::Array * recipients = mailcore::Array::array();
+ if (parser->header()->to() != NULL) {
+ recipients->addObjectsFromArray(parser->header()->to());
+ }
+ if (parser->header()->cc() != NULL) {
+ recipients->addObjectsFromArray(parser->header()->cc());
+ }
+ if (parser->header()->bcc() != NULL) {
+ recipients->addObjectsFromArray(parser->header()->bcc());
+ }
+ *pRecipients = recipients;
+ *pFrom = parser->header()->from();
+}
+
+static void testSendingMessageFromFileViaSMTP(mailcore::Data * data)
+{
+ mailcore::SMTPSession * smtp;
+ mailcore::ErrorCode error;
+
+ mailcore::String * filename = temporaryFilenameForTest();
+ data->writeToFile(filename);
+
+ smtp = new mailcore::SMTPSession();
+
+ smtp->setHostname(MCSTR("smtp.gmail.com"));
+ smtp->setPort(25);
+ smtp->setUsername(email);
+ smtp->setPassword(password);
+ smtp->setConnectionType(mailcore::ConnectionTypeStartTLS);
+
+ mailcore::Array * recipients;
+ mailcore::Address * from;
+ parseAddressesFromRfc822(filename, &recipients, &from);
+
+ smtp->sendMessage(from, recipients, filename, NULL, &error);
+
+ smtp->release();
+}
+
static void testPOP()
{
mailcore::POPSession * session;
@@ -288,6 +331,36 @@ static void testAsyncSMTP(mailcore::Data * data)
//smtp->release();
}
+static void testAsyncSendMessageFromFileViaSMTP(mailcore::Data * data)
+{
+ mailcore::SMTPAsyncSession * smtp;
+ TestSMTPCallback * callback = new TestSMTPCallback();
+
+ mailcore::String * filename = temporaryFilenameForTest();
+ data->writeToFile(filename);
+
+ mailcore::Array * recipients;
+ mailcore::Address * from;
+ parseAddressesFromRfc822(filename, &recipients, &from);
+
+ smtp = new mailcore::SMTPAsyncSession();
+
+ smtp->setHostname(MCSTR("smtp.gmail.com"));
+ smtp->setPort(25);
+ smtp->setUsername(email);
+ smtp->setPassword(password);
+ smtp->setConnectionType(mailcore::ConnectionTypeStartTLS);
+
+ mailcore::SMTPOperation * op = smtp->sendMessageOperation(from, recipients, filename);
+ op->setSmtpCallback(callback);
+ op->setCallback(callback);
+ op->start();
+
+ mainLoop();
+
+ //smtp->release();
+}
+
class TestIMAPCallback : public mailcore::Object, public mailcore::OperationCallback, public mailcore::IMAPOperationCallback {
virtual void operationFinished(mailcore::Operation * op)
{
@@ -408,11 +481,13 @@ void testAll()
//mailcore::Data * data = testMessageBuilder();
//testMessageParser(data);
//testSMTP(data);
+ //testSendingMessageFromFileViaSMTP(data);
//testIMAP();
//testIMAPMove();
//testPOP();
//testNNTP();
//testAsyncSMTP(data);
+ //testAsyncSendMessageFromFileViaSMTP(data);
//testAsyncIMAP();
//testAsyncPOP();
//testAddresses();