From 17197c848caec74d070b2c3e05f87799aaf0c0c5 Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Mon, 16 Aug 2021 17:48:55 +0200 Subject: [PATCH] Fix CryptoUtils::assembleMessage() to not add bogus text/plain content-type Found by failing unit tests mailcommon-filter-filteractiondecrypttest & mailcommon-filter-filteractionencrypttest --- src/util/cryptoutils.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/util/cryptoutils.cpp b/src/util/cryptoutils.cpp index e8169a7..9ee39f5 100644 --- a/src/util/cryptoutils.cpp +++ b/src/util/cryptoutils.cpp @@ -166,9 +166,17 @@ KMime::Message::Ptr CryptoUtils::assembleMessage(const KMime::Message::Ptr &orig out->setBody(const_cast(newContent)->encodedBody()); out->parse(); + // remove default explicit content headers added by KMime::Content::parse() + QVector headers = out->headers(); + for (const auto hdr : std::as_const(headers)) { + if (isContentHeader(hdr)) { + out->removeHeader(hdr->type()); + } + } + // Copy over headers from the original message, except for CT, CTE and CD // headers, we want to preserve those from the new content - QVector headers = orig->headers(); + headers = orig->headers(); for (const auto hdr : std::as_const(headers)) { if (isContentHeader(hdr)) { continue;