diff options
author | Minijackson <minijackson@riseup.net> | 2018-03-02 15:45:19 +0100 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2018-03-08 12:04:55 +0100 |
commit | a290f7f5228d6447611f304815baa0baca72e5e2 (patch) | |
tree | 70d0113e21d259ca40674b7e93b9f5bb9069e3bb | |
parent | 5293d0c894464a407cdf0001685b040584f47496 (diff) | |
download | kube-a290f7f5228d6447611f304815baa0baca72e5e2.tar.gz kube-a290f7f5228d6447611f304815baa0baca72e5e2.zip |
Make encrypted forwarding with attachement work + encoding
-rw-r--r-- | framework/src/domain/mime/mailtemplates.cpp | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/framework/src/domain/mime/mailtemplates.cpp b/framework/src/domain/mime/mailtemplates.cpp index 513f0353..30f9a48d 100644 --- a/framework/src/domain/mime/mailtemplates.cpp +++ b/framework/src/domain/mime/mailtemplates.cpp | |||
@@ -227,7 +227,7 @@ KMime::Content *createMultipartAlternativeContent(const QString &plainBody, cons | |||
227 | //FIXME This is supposed to select a charset out of the available charsets that contains all necessary characters to render the text | 227 | //FIXME This is supposed to select a charset out of the available charsets that contains all necessary characters to render the text |
228 | // QTextCodec *charset = selectCharset(m_charsets, htmlBody); | 228 | // QTextCodec *charset = selectCharset(m_charsets, htmlBody); |
229 | // htmlPart->contentType()->setCharset(charset->name()); | 229 | // htmlPart->contentType()->setCharset(charset->name()); |
230 | textPart->contentType()->setCharset("utf-8"); | 230 | htmlPart->contentType()->setCharset("utf-8"); |
231 | htmlPart->contentTransferEncoding()->setEncoding(KMime::Headers::CE8Bit); | 231 | htmlPart->contentTransferEncoding()->setEncoding(KMime::Headers::CE8Bit); |
232 | htmlPart->fromUnicodeString(htmlBody); | 232 | htmlPart->fromUnicodeString(htmlBody); |
233 | multipartAlternative->addContent(htmlPart); | 233 | multipartAlternative->addContent(htmlPart); |
@@ -235,9 +235,9 @@ KMime::Content *createMultipartAlternativeContent(const QString &plainBody, cons | |||
235 | return multipartAlternative; | 235 | return multipartAlternative; |
236 | } | 236 | } |
237 | 237 | ||
238 | KMime::Message *createMultipartMixedContent(QVector<KMime::Content *> contents) | 238 | KMime::Content *createMultipartMixedContent(QVector<KMime::Content *> contents) |
239 | { | 239 | { |
240 | KMime::Message *multiPartMixed = new KMime::Message(); | 240 | KMime::Content *multiPartMixed = new KMime::Content(); |
241 | multiPartMixed->contentType()->setMimeType("multipart/mixed"); | 241 | multiPartMixed->contentType()->setMimeType("multipart/mixed"); |
242 | multiPartMixed->contentType()->setBoundary(KMime::multiPartBoundary()); | 242 | multiPartMixed->contentType()->setBoundary(KMime::multiPartBoundary()); |
243 | 243 | ||
@@ -899,7 +899,7 @@ void MailTemplates::forward(const KMime::Message::Ptr &origMsg, | |||
899 | 899 | ||
900 | // Decrypt the original message, it will be encrypted again in the composer | 900 | // Decrypt the original message, it will be encrypted again in the composer |
901 | // for the right recipient | 901 | // for the right recipient |
902 | KMime::Message::Ptr forwardedMessage; | 902 | KMime::Message::Ptr forwardedMessage(new KMime::Message()); |
903 | if (isEncrypted(origMsg.data())) { | 903 | if (isEncrypted(origMsg.data())) { |
904 | qDebug() << "Original message was encrypted, decrypting it"; | 904 | qDebug() << "Original message was encrypted, decrypting it"; |
905 | MimeTreeParser::ObjectTreeParser otp; | 905 | MimeTreeParser::ObjectTreeParser otp; |
@@ -907,34 +907,31 @@ void MailTemplates::forward(const KMime::Message::Ptr &origMsg, | |||
907 | otp.decryptParts(); | 907 | otp.decryptParts(); |
908 | 908 | ||
909 | auto htmlContent = otp.htmlContent(); | 909 | auto htmlContent = otp.htmlContent(); |
910 | |||
910 | KMime::Content *recreatedMsg = | 911 | KMime::Content *recreatedMsg = |
911 | htmlContent.isEmpty() ? createPlainPartContent(otp.plainTextContent()) : | 912 | htmlContent.isEmpty() ? createPlainPartContent(otp.plainTextContent()) : |
912 | createMultipartAlternativeContent(otp.plainTextContent(), htmlContent); | 913 | createMultipartAlternativeContent(otp.plainTextContent(), htmlContent); |
913 | 914 | ||
914 | if (hasAttachment(origMsg.data())) { | 915 | KMime::Message::Ptr tmpForwardedMessage; |
916 | auto attachments = otp.collectAttachmentParts(); | ||
917 | if (!attachments.isEmpty()) { | ||
915 | QVector<KMime::Content *> contents = {recreatedMsg}; | 918 | QVector<KMime::Content *> contents = {recreatedMsg}; |
916 | contents.append(origMsg->attachments()); | 919 | for (const auto &attachment : attachments) { |
920 | contents.append(attachment->node()); | ||
921 | } | ||
917 | 922 | ||
918 | auto msg = createMultipartMixedContent(contents); | 923 | auto msg = createMultipartMixedContent(contents); |
919 | 924 | ||
920 | forwardedMessage.reset(KMime::contentToMessage(msg)); | 925 | tmpForwardedMessage.reset(KMime::contentToMessage(msg)); |
921 | } else { | 926 | } else { |
922 | forwardedMessage.reset(KMime::contentToMessage(recreatedMsg)); | 927 | tmpForwardedMessage.reset(KMime::contentToMessage(recreatedMsg)); |
923 | } | 928 | } |
924 | 929 | ||
925 | forwardedMessage->subject()->from7BitString(origMsg->subject()->as7BitString()); | 930 | origMsg->contentType()->fromUnicodeString(tmpForwardedMessage->contentType()->asUnicodeString(), "utf-8"); |
926 | 931 | origMsg->assemble(); | |
927 | for (const auto &addr : origMsg->to()->mailboxes()) { | 932 | forwardedMessage->setHead(origMsg->head()); |
928 | forwardedMessage->to()->addAddress(addr); | 933 | forwardedMessage->setBody(tmpForwardedMessage->encodedBody()); |
929 | } | 934 | forwardedMessage->parse(); |
930 | |||
931 | for (const auto &addr : origMsg->cc()->mailboxes()) { | ||
932 | forwardedMessage->cc()->addAddress(addr); | ||
933 | } | ||
934 | |||
935 | for (const auto &addr : origMsg->bcc()->mailboxes()) { | ||
936 | forwardedMessage->bcc()->addAddress(addr); | ||
937 | } | ||
938 | 935 | ||
939 | } else { | 936 | } else { |
940 | qDebug() << "Original message was not encrypted, using it as-is"; | 937 | qDebug() << "Original message was not encrypted, using it as-is"; |