Commit 3a711439 authored by Sandro Knauß's avatar Sandro Knauß

Fix[messagecomposer]: Do copy all mail headers instad of reference them.

When dealing with encryption and protected headers it is enough to
reference the headers in the messagepart, as the result is encrypted
directly. This is different for Sign only and there may be jobs after
signing that are changing the mail headers, so we need to copy all
headers into the encapsulated part instead of referencing them.

BUG: 427091
FIXED-IN: 5.16.1
parent 3ab9029f
Pipeline #46501 passed with stage
in 16 minutes and 38 seconds
......@@ -262,3 +262,58 @@ void SignJobTest::testProtectedHeaders()
Test::compareFile(referenceFile, QStringLiteral(MAIL_DATA_DIR "/")+referenceFile);
}
void SignJobTest::testProtectedHeadersOverwrite()
{
const std::vector< GpgME::Key > &keys = Test::getKeys();
const auto referenceFile = QStringLiteral("protected_headers-non-obvoscate.mbox");
Composer composer;
auto sJob = new SignJob(&composer);
QVERIFY(sJob);
const QByteArray data(QString::fromLocal8Bit("one flew over the cuckoo's nest").toUtf8());
const QString subject(QStringLiteral("asdfghjklö"));
auto content = new KMime::Content;
content->contentType(true)->setMimeType("text/plain");
content->setBody(data);
KMime::Message skeletonMessage;
skeletonMessage.contentType(true)->setMimeType("foo/bla");
skeletonMessage.to(true)->from7BitString("to@test.de, to2@test.de");
skeletonMessage.cc(true)->from7BitString("cc@test.de, cc2@test.de");
skeletonMessage.bcc(true)->from7BitString("bcc@test.de, bcc2@test.de");
skeletonMessage.subject(true)->fromUnicodeString(subject, "utf-8");
sJob->setContent(content);
sJob->setCryptoMessageFormat(Kleo::OpenPGPMIMEFormat);
sJob->setSigningKeys(keys);
sJob->setSkeletonMessage(&skeletonMessage);
sJob->setProtectedHeaders(true);
VERIFYEXEC(sJob);
QCOMPARE(skeletonMessage.subject()->asUnicodeString(), subject);
skeletonMessage.to()->from7BitString("owerwrite@example.org");
skeletonMessage.cc()->from7BitString("cc_overwrite@example.org");
skeletonMessage.bcc()->from7BitString("bcc_overwrite@example.org");
skeletonMessage.subject()->fromUnicodeString(subject+QStringLiteral("_owerwrite"), "utf-8");
KMime::Content *result = sJob->content();
result->assemble();
QFile f(referenceFile);
QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Truncate));
const QByteArray signedContent(result->contents().at(0)->encodedContent());
f.write(signedContent);
if (!signedContent.endsWith('\n')) {
f.write("\n");
}
f.close();
Test::compareFile(referenceFile, QStringLiteral(MAIL_DATA_DIR "/")+referenceFile);
}
......@@ -33,6 +33,8 @@ private Q_SLOTS:
void testProtectedHeaders_data();
void testProtectedHeaders();
void testProtectedHeadersOverwrite();
private:
void checkSignJob(MessageComposer::SignJob *sJob);
};
......
......@@ -133,13 +133,12 @@ void ProtectedHeadersJob::process()
if (headerType.startsWith("Content-")) {
continue;
}
if (headerType == "Subject") {
auto *copySubject = new KMime::Headers::Subject();
copySubject->from7BitString(subject->as7BitString(false));
d->content->appendHeader(copySubject);
} else {
d->content->appendHeader(header);
auto copyHeader = KMime::Headers::createHeader(headerType);
if (!copyHeader) {
copyHeader = new KMime::Headers::Generic(headerType.constData(), headerType.size());
}
copyHeader->from7BitString(header->as7BitString(false));
d->content->appendHeader(copyHeader);
}
if (d->obvoscate && subject) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment