From 00bcc137ab2d82d786f1b4423f3d3b4e5c30e71d Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 8 Oct 2017 14:33:32 +0200 Subject: Html with attachments --- .../src/domain/mime/tests/mailtemplatetest.cpp | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'framework/src/domain/mime/tests') diff --git a/framework/src/domain/mime/tests/mailtemplatetest.cpp b/framework/src/domain/mime/tests/mailtemplatetest.cpp index 0ea5305f..b0d91182 100644 --- a/framework/src/domain/mime/tests/mailtemplatetest.cpp +++ b/framework/src/domain/mime/tests/mailtemplatetest.cpp @@ -14,6 +14,16 @@ #include "mailtemplates.h" #include "mailcrypto.h" +static KMime::Content *getSubpart(KMime::Content *msg, const QByteArray &mimeType) +{ + for (const auto c : msg->contents()) { + if (c->contentType(false)->mimeType() == mimeType) { + return c; + } + } + return nullptr; +} + static std::vector< GpgME::Key, std::allocator< GpgME::Key > > getKeys(bool smime = false) { QGpgME::KeyListJob *job = nullptr; @@ -276,6 +286,32 @@ private slots: const auto contents = result->contents(); //1 Plain + 2 Attachments QCOMPARE(contents.size(), 3); + auto p = getSubpart(result.data(), "text/plain"); + QVERIFY(p); + } + + void testCreateHtmlMailWithAttachments() + { + QStringList to = {{"to@example.org"}}; + QStringList cc = {{"cc@example.org"}};; + QStringList bcc = {{"bcc@example.org"}};; + KMime::Types::Mailbox from; + from.fromUnicodeString("from@example.org"); + QString subject = "subject"; + QString body = "body"; + QList attachments = {{"name", "filename", "mimetype", true, "inlineAttachment"}, {"name", "filename", "mimetype", false, "nonInlineAttachment"}}; + + auto result = MailTemplates::createMessage({}, to, cc, bcc, from, subject, body, true, attachments); + + QVERIFY(result); + QCOMPARE(result->subject()->asUnicodeString(), subject); + QVERIFY(result->contentType()->isMimeType("multipart/mixed")); + QVERIFY(result->date(false)->dateTime().isValid()); + const auto contents = result->contents(); + //1 alternative + 2 Attachments + QCOMPARE(contents.size(), 3); + auto p = getSubpart(result.data(), "multipart/alternative"); + QVERIFY(p); } void testCreatePlainMailSigned() -- cgit v1.2.3