summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/kube/contents/ui/ComposerView.qml14
-rw-r--r--framework/src/domain/composercontroller.cpp2
-rw-r--r--framework/src/domain/composercontroller.h1
-rw-r--r--framework/src/domain/mime/mailtemplates.cpp24
-rw-r--r--framework/src/domain/mime/mailtemplates.h2
-rw-r--r--framework/src/domain/mime/tests/mailtemplatetest.cpp30
6 files changed, 59 insertions, 14 deletions
diff --git a/components/kube/contents/ui/ComposerView.qml b/components/kube/contents/ui/ComposerView.qml
index 25244199..95f267b2 100644
--- a/components/kube/contents/ui/ComposerView.qml
+++ b/components/kube/contents/ui/ComposerView.qml
@@ -34,16 +34,18 @@ Kube.View {
34 property variant message: {} 34 property variant message: {}
35 property variant recipients: [] 35 property variant recipients: []
36 36
37 //FIXME mean hack to unfuck hiding
38 property variant _composerController: Kube.ComposerController {
39 id: composerController
40 onDone: Kube.Fabric.postMessage(Kube.Messages.componentDone, {})
41 }
42
43 //actions 37 //actions
44 property variant sendAction: composerController.sendAction 38 property variant sendAction: composerController.sendAction
45 property variant saveAsDraftAction: composerController.saveAsDraftAction 39 property variant saveAsDraftAction: composerController.saveAsDraftAction
46 40
41 resources: [
42 Kube.ComposerController {
43 id: composerController
44 htmlBody: html.checked
45 onDone: Kube.Fabric.postMessage(Kube.Messages.componentDone, {})
46 }
47 ]
48
47 Component.onCompleted: loadMessage(root.message, root.loadAsDraft) 49 Component.onCompleted: loadMessage(root.message, root.loadAsDraft)
48 50
49 Controls2.StackView.onActivated: { 51 Controls2.StackView.onActivated: {
diff --git a/framework/src/domain/composercontroller.cpp b/framework/src/domain/composercontroller.cpp
index b6380f50..abb4fdf4 100644
--- a/framework/src/domain/composercontroller.cpp
+++ b/framework/src/domain/composercontroller.cpp
@@ -427,7 +427,7 @@ KMime::Message::Ptr ComposerController::assembleMessage()
427 }; 427 };
428 } 428 }
429 } 429 }
430 return MailTemplates::createMessage(mExistingMessage, mToModel->stringList(), mCcModel->stringList(), mBccModel->stringList(), getIdentity(), getSubject(), getBody(), attachments); 430 return MailTemplates::createMessage(mExistingMessage, mToModel->stringList(), mCcModel->stringList(), mBccModel->stringList(), getIdentity(), getSubject(), getBody(), getHtmlBody(), attachments);
431} 431}
432 432
433void ComposerController::updateSendAction() 433void ComposerController::updateSendAction()
diff --git a/framework/src/domain/composercontroller.h b/framework/src/domain/composercontroller.h
index b2486cee..784591eb 100644
--- a/framework/src/domain/composercontroller.h
+++ b/framework/src/domain/composercontroller.h
@@ -51,6 +51,7 @@ class ComposerController : public Kube::Controller
51 //Interface properties 51 //Interface properties
52 KUBE_CONTROLLER_PROPERTY(QString, Subject, subject) 52 KUBE_CONTROLLER_PROPERTY(QString, Subject, subject)
53 KUBE_CONTROLLER_PROPERTY(QString, Body, body) 53 KUBE_CONTROLLER_PROPERTY(QString, Body, body)
54 KUBE_CONTROLLER_PROPERTY(bool, HtmlBody, htmlBody)
54 55
55 //Set by identitySelector 56 //Set by identitySelector
56 KUBE_CONTROLLER_PROPERTY(KMime::Types::Mailbox, Identity, identity) 57 KUBE_CONTROLLER_PROPERTY(KMime::Types::Mailbox, Identity, identity)
diff --git a/framework/src/domain/mime/mailtemplates.cpp b/framework/src/domain/mime/mailtemplates.cpp
index dc4f93b5..25ce1385 100644
--- a/framework/src/domain/mime/mailtemplates.cpp
+++ b/framework/src/domain/mime/mailtemplates.cpp
@@ -913,6 +913,13 @@ static KMime::Content *createBodyPart(const QByteArray &body) {
913 return mainMessage; 913 return mainMessage;
914} 914}
915 915
916static KMime::Content *createHtmlBodyPart(const QByteArray &body) {
917 auto mainMessage = new KMime::Content;
918 mainMessage->setBody(body);
919 mainMessage->contentType(true)->setMimeType("text/html");
920 return mainMessage;
921}
922
916static KMime::Types::Mailbox::List stringListToMailboxes(const QStringList &list) 923static KMime::Types::Mailbox::List stringListToMailboxes(const QStringList &list)
917{ 924{
918 KMime::Types::Mailbox::List mailboxes; 925 KMime::Types::Mailbox::List mailboxes;
@@ -924,7 +931,7 @@ static KMime::Types::Mailbox::List stringListToMailboxes(const QStringList &list
924 return mailboxes; 931 return mailboxes;
925} 932}
926 933
927KMime::Message::Ptr MailTemplates::createMessage(KMime::Message::Ptr existingMessage, const QStringList &to, const QStringList &cc, const QStringList &bcc, const KMime::Types::Mailbox &from, const QString &subject, const QString &body, const QList<Attachment> &attachments, const std::vector<GpgME::Key> &signingKeys) 934KMime::Message::Ptr MailTemplates::createMessage(KMime::Message::Ptr existingMessage, const QStringList &to, const QStringList &cc, const QStringList &bcc, const KMime::Types::Mailbox &from, const QString &subject, const QString &body, bool htmlBody, const QList<Attachment> &attachments, const std::vector<GpgME::Key> &signingKeys)
928{ 935{
929 auto mail = existingMessage; 936 auto mail = existingMessage;
930 if (!mail) { 937 if (!mail) {
@@ -968,12 +975,25 @@ KMime::Message::Ptr MailTemplates::createMessage(KMime::Message::Ptr existingMes
968 bodyPart->contentType()->setBoundary(KMime::multiPartBoundary()); 975 bodyPart->contentType()->setBoundary(KMime::multiPartBoundary());
969 bodyPart->contentTransferEncoding()->setEncoding(KMime::Headers::CE7Bit); 976 bodyPart->contentTransferEncoding()->setEncoding(KMime::Headers::CE7Bit);
970 bodyPart->setPreamble("This is a multi-part message in MIME format.\n"); 977 bodyPart->setPreamble("This is a multi-part message in MIME format.\n");
978 //TODO deal with html
971 bodyPart->addContent(createBodyPart(body.toUtf8())); 979 bodyPart->addContent(createBodyPart(body.toUtf8()));
972 for (const auto &attachment : attachments) { 980 for (const auto &attachment : attachments) {
973 bodyPart->addContent(createAttachmentPart(attachment.data, attachment.filename, attachment.isInline, attachment.mimeType, attachment.name)); 981 bodyPart->addContent(createAttachmentPart(attachment.data, attachment.filename, attachment.isInline, attachment.mimeType, attachment.name));
974 } 982 }
975 } else { 983 } else {
976 bodyPart = createBodyPart(body.toUtf8()); 984 if (htmlBody) {
985 bodyPart = new KMime::Content;
986 bodyPart->contentType(true)->setMimeType("multipart/alternative");
987 bodyPart->contentType()->setBoundary(KMime::multiPartBoundary());
988
989 QTextDocument doc;
990 doc.setHtml(body);
991
992 bodyPart->addContent(createBodyPart(doc.toPlainText().toUtf8()));
993 bodyPart->addContent(createHtmlBodyPart(body.toUtf8()));
994 } else {
995 bodyPart = createBodyPart(body.toUtf8());
996 }
977 } 997 }
978 bodyPart->assemble(); 998 bodyPart->assemble();
979 999
diff --git a/framework/src/domain/mime/mailtemplates.h b/framework/src/domain/mime/mailtemplates.h
index edcc982a..d28b100e 100644
--- a/framework/src/domain/mime/mailtemplates.h
+++ b/framework/src/domain/mime/mailtemplates.h
@@ -36,5 +36,5 @@ namespace MailTemplates
36{ 36{
37 void reply(const KMime::Message::Ptr &origMsg, const std::function<void(const KMime::Message::Ptr &result)> &callback, const KMime::Types::AddrSpecList &me = {}); 37 void reply(const KMime::Message::Ptr &origMsg, const std::function<void(const KMime::Message::Ptr &result)> &callback, const KMime::Types::AddrSpecList &me = {});
38 QString plaintextContent(const KMime::Message::Ptr &origMsg); 38 QString plaintextContent(const KMime::Message::Ptr &origMsg);
39 KMime::Message::Ptr createMessage(KMime::Message::Ptr existingMessage, const QStringList &to, const QStringList &cc, const QStringList &bcc, const KMime::Types::Mailbox &from, const QString &subject, const QString &body, const QList<Attachment> &attachments, const std::vector<GpgME::Key> &signingKeys = {}); 39 KMime::Message::Ptr createMessage(KMime::Message::Ptr existingMessage, const QStringList &to, const QStringList &cc, const QStringList &bcc, const KMime::Types::Mailbox &from, const QString &subject, const QString &body, bool htmlBody, const QList<Attachment> &attachments, const std::vector<GpgME::Key> &signingKeys = {});
40}; 40};
diff --git a/framework/src/domain/mime/tests/mailtemplatetest.cpp b/framework/src/domain/mime/tests/mailtemplatetest.cpp
index 700ae7a3..0ea5305f 100644
--- a/framework/src/domain/mime/tests/mailtemplatetest.cpp
+++ b/framework/src/domain/mime/tests/mailtemplatetest.cpp
@@ -225,7 +225,7 @@ private slots:
225 QString body = "body"; 225 QString body = "body";
226 QList<Attachment> attachments; 226 QList<Attachment> attachments;
227 227
228 auto result = MailTemplates::createMessage({}, to, cc, bcc, from, subject, body, attachments); 228 auto result = MailTemplates::createMessage({}, to, cc, bcc, from, subject, body, false, attachments);
229 229
230 QVERIFY(result); 230 QVERIFY(result);
231 QCOMPARE(result->subject()->asUnicodeString(), subject); 231 QCOMPARE(result->subject()->asUnicodeString(), subject);
@@ -234,6 +234,28 @@ private slots:
234 QVERIFY(result->contentType()->isMimeType("text/plain")); 234 QVERIFY(result->contentType()->isMimeType("text/plain"));
235 } 235 }
236 236
237 void testCreateHtmlMail()
238 {
239 QStringList to = {{"to@example.org"}};
240 QStringList cc = {{"cc@example.org"}};
241 QStringList bcc = {{"bcc@example.org"}};;
242 KMime::Types::Mailbox from;
243 from.fromUnicodeString("from@example.org");
244 QString subject = "subject";
245 QString body = "body";
246 QList<Attachment> attachments;
247
248 auto result = MailTemplates::createMessage({}, to, cc, bcc, from, subject, body, true, attachments);
249
250 QVERIFY(result);
251 QCOMPARE(result->subject()->asUnicodeString(), subject);
252 QVERIFY(result->date(false)->dateTime().isValid());
253 QVERIFY(result->contentType()->isMimeType("multipart/alternative"));
254 const auto contents = result->contents();
255 //1 Plain + 1 Html
256 QCOMPARE(contents.size(), 2);
257 }
258
237 void testCreatePlainMailWithAttachments() 259 void testCreatePlainMailWithAttachments()
238 { 260 {
239 QStringList to = {{"to@example.org"}}; 261 QStringList to = {{"to@example.org"}};
@@ -245,7 +267,7 @@ private slots:
245 QString body = "body"; 267 QString body = "body";
246 QList<Attachment> attachments = {{"name", "filename", "mimetype", true, "inlineAttachment"}, {"name", "filename", "mimetype", false, "nonInlineAttachment"}}; 268 QList<Attachment> attachments = {{"name", "filename", "mimetype", true, "inlineAttachment"}, {"name", "filename", "mimetype", false, "nonInlineAttachment"}};
247 269
248 auto result = MailTemplates::createMessage({}, to, cc, bcc, from, subject, body, attachments); 270 auto result = MailTemplates::createMessage({}, to, cc, bcc, from, subject, body, false, attachments);
249 271
250 QVERIFY(result); 272 QVERIFY(result);
251 QCOMPARE(result->subject()->asUnicodeString(), subject); 273 QCOMPARE(result->subject()->asUnicodeString(), subject);
@@ -269,7 +291,7 @@ private slots:
269 291
270 std::vector<GpgME::Key> keys = getKeys(); 292 std::vector<GpgME::Key> keys = getKeys();
271 293
272 auto result = MailTemplates::createMessage({}, to, cc, bcc, from, subject, body, attachments, keys); 294 auto result = MailTemplates::createMessage({}, to, cc, bcc, from, subject, body, false, attachments, keys);
273 295
274 QVERIFY(result); 296 QVERIFY(result);
275 // qWarning() << "---------------------------------"; 297 // qWarning() << "---------------------------------";
@@ -304,7 +326,7 @@ private slots:
304 326
305 std::vector<GpgME::Key> keys = getKeys(); 327 std::vector<GpgME::Key> keys = getKeys();
306 328
307 auto result = MailTemplates::createMessage({}, to, cc, bcc, from, subject, body, attachments, keys); 329 auto result = MailTemplates::createMessage({}, to, cc, bcc, from, subject, body, false, attachments, keys);
308 330
309 QVERIFY(result); 331 QVERIFY(result);
310 QCOMPARE(result->subject()->asUnicodeString(), subject); 332 QCOMPARE(result->subject()->asUnicodeString(), subject);