Commit 87bc9316 authored by Sandro Knauß's avatar Sandro Knauß

messagecomposer: Move protected headers to signed part.

If there is a signed part we should have the protected headers there
instead of only the encrypted part.
parent 3a711439
Pipeline #46504 passed with stage
in 16 minutes and 49 seconds
......@@ -322,6 +322,77 @@ void CryptoComposerTest::testSignEncryptLateAttachments()
QCOMPARE(QString::fromLatin1(MessageCore::NodeHelper::nextSibling(b)->body()), QString::fromLatin1("abc"));
}
// protected headers
void CryptoComposerTest::testProtectedHeaders_data()
{
QTest::addColumn<QString>("data");
QTest::addColumn<bool>("sign");
QTest::addColumn<bool>("encrypt");
QTest::addColumn<Headers::contentEncoding>("cte");
QString data(QStringLiteral("All happy families are alike; each unhappy family is unhappy in its own way."));
QTest::newRow("SignOpenPGPMime") << data << true << false << Headers::CE7Bit;
QTest::newRow("EncryptOpenPGPMime") << data << false << true << Headers::CE7Bit;
QTest::newRow("SignEncryptOpenPGPMime") << data << true << true << Headers::CE7Bit;
}
void CryptoComposerTest::testProtectedHeaders()
{
QFETCH(QString, data);
QFETCH(bool, sign);
QFETCH(bool, encrypt);
QFETCH(Headers::contentEncoding, cte);
Composer composer;
fillComposerData(&composer, data);
fillComposerCryptoData(&composer);
composer.setSignAndEncrypt(sign, encrypt);
composer.setMessageCryptoFormat(Kleo::OpenPGPMIMEFormat);
VERIFYEXEC((&composer));
QCOMPARE(composer.resultMessages().size(), 1);
KMime::Message::Ptr message = composer.resultMessages().first();
// parse the result and make sure it is valid in various ways
MimeTreeParser::SimpleObjectTreeSource testSource;
MimeTreeParser::NodeHelper nh;
MimeTreeParser::ObjectTreeParser otp(&testSource, &nh);
testSource.setDecryptMessage(true);
otp.parseObjectTree(message.data());
if (encrypt) {
QCOMPARE(nh.encryptionState(message.data()), MimeTreeParser::KMMsgFullyEncrypted);
}
if (sign && !encrypt) {
QCOMPARE(nh.signatureState(message.data()), MimeTreeParser::KMMsgFullySigned);
}
KMime::Content *part = nullptr;
if (sign && !encrypt) {
part = Util::findTypeInMessage(message.data(), "text", "plain");
} else if (encrypt) {
auto extraContents = nh.extraContents(message.data());
QCOMPARE(extraContents.size(), 1);
part = extraContents.first();
if (sign) {
QVERIFY(!part->contentType(false)->hasParameter(QStringLiteral("protected-headers")));
QVERIFY(!part->headerByType("to"));
QVERIFY(!part->headerByType("from:"));
part = Util::findTypeInMessage(part, "text", "plain");
}
}
QVERIFY(part);
QCOMPARE(part->contentType(false)->parameter(QStringLiteral("protected-headers")),QStringLiteral("v1"));
QCOMPARE(part->headerByType("to")->asUnicodeString(), QStringLiteral("you@you.you"));
QCOMPARE(part->headerByType("from")->asUnicodeString(), QStringLiteral("me@me.me"));
}
void CryptoComposerTest::testBCCEncrypt_data()
{
QTest::addColumn<int>("format");
......
......@@ -38,6 +38,10 @@ private Q_SLOTS:
void testEditEncryptAndLateAttachments();
void testEditEncryptAndLateAttachments_data();
// test protected headers
void testProtectedHeaders();
void testProtectedHeaders_data();
// secondary recipients
void testBCCEncrypt();
void testBCCEncrypt_data();
......
......@@ -212,18 +212,21 @@ void ComposerPrivate::composeStep2()
sJob->setCryptoMessageFormat(format);
sJob->setSigningKeys(signers);
sJob->appendSubjob(mainJob);
if (!encrypt) {
sJob->setSkeletonMessage(skeletonMessage);
}
sJob->setSkeletonMessage(skeletonMessage);
mainJob = sJob;
}
if (encrypt) {
const auto lstJob = createEncryptJobs(mainJob, false);
for (ContentJobBase *eJob : lstJob) {
QObject::connect(eJob, SIGNAL(finished(KJob*)), q, SLOT(contentJobFinished(KJob*)));
q->addSubjob(eJob);
mainJob = eJob; //start only last EncryptJob
for (ContentJobBase *job : lstJob) {
auto eJob = dynamic_cast<EncryptJob *>(job);
if (eJob && sign) {
// When doing Encrypt and Sign move headers only in the singed part
eJob->setProtectedHeaders(false);
}
QObject::connect(job, SIGNAL(finished(KJob*)), q, SLOT(contentJobFinished(KJob*)));
q->addSubjob(job);
mainJob = job; //start only last EncryptJob
}
} else {
QObject::connect(mainJob, SIGNAL(finished(KJob*)), q, SLOT(contentJobFinished(KJob*)));
......
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