diff options
Diffstat (limited to 'framework/src/domain/mime/mailtemplates.cpp')
-rw-r--r-- | framework/src/domain/mime/mailtemplates.cpp | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/framework/src/domain/mime/mailtemplates.cpp b/framework/src/domain/mime/mailtemplates.cpp index bbe079d8..5f5b35df 100644 --- a/framework/src/domain/mime/mailtemplates.cpp +++ b/framework/src/domain/mime/mailtemplates.cpp | |||
@@ -958,7 +958,7 @@ static KMime::Types::Mailbox::List stringListToMailboxes(const QStringList &list | |||
958 | return mailboxes; | 958 | return mailboxes; |
959 | } | 959 | } |
960 | 960 | ||
961 | KMime::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) | 961 | KMime::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, const std::vector<GpgME::Key> &encryptionKeys) |
962 | { | 962 | { |
963 | auto mail = existingMessage; | 963 | auto mail = existingMessage; |
964 | if (!mail) { | 964 | if (!mail) { |
@@ -995,41 +995,42 @@ KMime::Message::Ptr MailTemplates::createMessage(KMime::Message::Ptr existingMes | |||
995 | } | 995 | } |
996 | mail->assemble(); | 996 | mail->assemble(); |
997 | 997 | ||
998 | KMime::Content *bodyPart; | 998 | std::unique_ptr<KMime::Content> bodyPart{[&] { |
999 | if (!attachments.isEmpty()) { | 999 | if (!attachments.isEmpty()) { |
1000 | bodyPart = new KMime::Content; | 1000 | auto bodyPart = new KMime::Content; |
1001 | bodyPart->contentType(true)->setMimeType("multipart/mixed"); | 1001 | bodyPart->contentType(true)->setMimeType("multipart/mixed"); |
1002 | bodyPart->contentType()->setBoundary(KMime::multiPartBoundary()); | 1002 | bodyPart->contentType()->setBoundary(KMime::multiPartBoundary()); |
1003 | bodyPart->contentTransferEncoding()->setEncoding(KMime::Headers::CE7Bit); | 1003 | bodyPart->contentTransferEncoding()->setEncoding(KMime::Headers::CE7Bit); |
1004 | bodyPart->setPreamble("This is a multi-part message in MIME format.\n"); | 1004 | bodyPart->setPreamble("This is a multi-part message in MIME format.\n"); |
1005 | bodyPart->addContent(createBodyPart(body.toUtf8(), htmlBody)); | 1005 | bodyPart->addContent(createBodyPart(body.toUtf8(), htmlBody)); |
1006 | for (const auto &attachment : attachments) { | 1006 | for (const auto &attachment : attachments) { |
1007 | bodyPart->addContent(createAttachmentPart(attachment.data, attachment.filename, attachment.isInline, attachment.mimeType, attachment.name)); | 1007 | bodyPart->addContent(createAttachmentPart(attachment.data, attachment.filename, attachment.isInline, attachment.mimeType, attachment.name)); |
1008 | } | ||
1009 | return bodyPart; | ||
1010 | } else { | ||
1011 | return createBodyPart(body.toUtf8(), htmlBody); | ||
1008 | } | 1012 | } |
1009 | } else { | 1013 | }()}; |
1010 | bodyPart = createBodyPart(body.toUtf8(), htmlBody); | ||
1011 | } | ||
1012 | bodyPart->assemble(); | 1014 | bodyPart->assemble(); |
1013 | 1015 | ||
1014 | KMime::Content *signedResult = nullptr; | 1016 | QByteArray bodyData; |
1015 | if (!signingKeys.empty()) { | 1017 | if (!signingKeys.empty() || !encryptionKeys.empty()) { |
1016 | signedResult = MailCrypto::sign(bodyPart, signingKeys); | 1018 | auto result = MailCrypto::processCrypto(bodyPart.get(), signingKeys, encryptionKeys, MailCrypto::OPENPGP); |
1017 | if (!signedResult) { | 1019 | if (!result) { |
1018 | qWarning() << "Signing failed"; | 1020 | qWarning() << "Signing failed"; |
1019 | return {}; | 1021 | return {}; |
1020 | } | 1022 | } |
1023 | bodyData = result->encodedContent(); | ||
1021 | } else { | 1024 | } else { |
1022 | if (!bodyPart->contentType(false)) { | 1025 | if (!bodyPart->contentType(false)) { |
1023 | bodyPart->contentType(true)->setMimeType("text/plain"); | 1026 | bodyPart->contentType(true)->setMimeType("text/plain"); |
1024 | bodyPart->assemble(); | 1027 | bodyPart->assemble(); |
1025 | } | 1028 | } |
1029 | bodyData = bodyPart->encodedContent(); | ||
1026 | } | 1030 | } |
1027 | 1031 | ||
1028 | const QByteArray allData = mail->head() + (signedResult ? signedResult->encodedContent() : bodyPart->encodedContent()); | ||
1029 | delete bodyPart; | ||
1030 | KMime::Message::Ptr resultMessage(new KMime::Message); | 1032 | KMime::Message::Ptr resultMessage(new KMime::Message); |
1031 | resultMessage->setContent(allData); | 1033 | resultMessage->setContent(mail->head() + bodyData); |
1032 | resultMessage->parse(); // Not strictly necessary. | 1034 | resultMessage->parse(); // Not strictly necessary. |
1033 | |||
1034 | return resultMessage; | 1035 | return resultMessage; |
1035 | } | 1036 | } |