summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandro Knauß <sknauss@kde.org>2016-11-28 21:13:25 (GMT)
committerSandro Knauß <sknauss@kde.org>2016-11-28 22:27:44 (GMT)
commitd10544b77348ca48bebe1c5c94f2a07f807b8ac9 (patch)
tree40978d22364203b0dfc8d1b22047352b84b9d5f8
parent292d86c46feef40f4a43caa2de9d2e7dd1938e3b (diff)
Add Fix for Kontact creates broken pgp signed mails.
Wenn we construct a signed message, we want to make sure, that the mail itself is parsable for other MUAs, so we fix CE7Bit messages that contain quoted-printable-like character when signing (1efea1c00df92e43d0ff66073851f48471d9d76b) But this behaviour we only should do if it is text we sign and not a mimestructure (multipart/mixed) already.
-rw-r--r--messagecomposer/autotests/signjobtest.cpp48
-rw-r--r--messagecomposer/autotests/signjobtest.h1
-rw-r--r--messagecomposer/src/job/signjob.cpp5
3 files changed, 52 insertions, 2 deletions
diff --git a/messagecomposer/autotests/signjobtest.cpp b/messagecomposer/autotests/signjobtest.cpp
index e9a6c9d..ad7c629 100644
--- a/messagecomposer/autotests/signjobtest.cpp
+++ b/messagecomposer/autotests/signjobtest.cpp
@@ -157,7 +157,55 @@ void SignJobTest::testRecommentationRFC3156()
ComposerTestUtil::verify(true, false, result, data.toUtf8(),
Kleo::OpenPGPMIMEFormat, cte);
+}
+
+void SignJobTest::testMixedContent()
+{
+ std::vector< GpgME::Key > keys = MessageComposer::Test::getKeys();
+
+ QString data = QString::fromUtf8("=2D Magic foo\nFrom test\n\n-- quaak\nOhno");
+
+ MessageComposer::Composer *composer = new MessageComposer::Composer;
+ MessageComposer::SignJob* sJob = new MessageComposer::SignJob(composer);
+
+ QVERIFY(composer);
+ QVERIFY(sJob);
+
+ KMime::Content* content = new KMime::Content;
+ content->contentType()->setMimeType(QByteArray("multipart/mixed"));
+ content->contentType()->setBoundary( KMime::multiPartBoundary() );
+ KMime::Content* subcontent = new KMime::Content;
+ subcontent->contentType()->setMimeType(QByteArray("text/plain"));
+ subcontent->setBody( data.toUtf8() );
+ KMime::Content* attachment = new KMime::Content;
+ attachment->contentType()->setMimeType(QByteArray("text/plain"));
+ QByteArray attachmentData("an attachment");
+ attachment->setBody(attachmentData);
+
+ content->addContent(subcontent);
+ content->addContent(attachment);
+ content->assemble();
+ sJob->setContent(content);
+ sJob->setCryptoMessageFormat(Kleo::OpenPGPMIMEFormat);
+ sJob->setSigningKeys(keys);
+
+ VERIFYEXEC(sJob);
+
+ KMime::Content *result = sJob->content();
+ result->assemble();
+ qDebug() << result->encodedContent();
+
+ KMime::Content* firstChild = MessageCore::NodeHelper::firstChild(result);
+ QCOMPARE(result->contents().count(), 2);
+ QCOMPARE(firstChild->contents().count(), 2);
+ QCOMPARE(firstChild->body(), QByteArray());
+ QCOMPARE(firstChild->contentType()->mimeType(), QByteArray("multipart/mixed"));
+ QCOMPARE(firstChild->contents()[0]->body(), data.toUtf8());
+ QCOMPARE(firstChild->contents()[1]->body(), attachmentData);
+
+ ComposerTestUtil::verify(true, false, result, data.toUtf8(),
+ Kleo::OpenPGPMIMEFormat, KMime::Headers::CE7Bit);
}
void SignJobTest::checkSignJob(MessageComposer::SignJob *sJob)
diff --git a/messagecomposer/autotests/signjobtest.h b/messagecomposer/autotests/signjobtest.h
index f711033..2caceba 100644
--- a/messagecomposer/autotests/signjobtest.h
+++ b/messagecomposer/autotests/signjobtest.h
@@ -43,6 +43,7 @@ private Q_SLOTS:
void testContentChained();
void testHeaders();
void testRecommentationRFC3156();
+ void testMixedContent();
private:
void checkSignJob(MessageComposer::SignJob *sJob);
diff --git a/messagecomposer/src/job/signjob.cpp b/messagecomposer/src/job/signjob.cpp
index 3add0e2..67b3f34 100644
--- a/messagecomposer/src/job/signjob.cpp
+++ b/messagecomposer/src/job/signjob.cpp
@@ -168,8 +168,9 @@ void SignJob::process()
// Note: If any line begins with the string "From ", it is strongly
// suggested that either the Quoted-Printable or Base64 MIME encoding
// be applied.
- if (d->content->contentTransferEncoding()->encoding() == KMime::Headers::CEquPr ||
- d->content->contentTransferEncoding()->encoding() == KMime::Headers::CE7Bit) {
+ const auto encoding = d->content->contentTransferEncoding()->encoding();
+ if ((encoding == KMime::Headers::CEquPr || encoding == KMime::Headers::CE7Bit)
+ && !d->content->contentType(false)) {
QByteArray body = d->content->encodedBody();
bool changed = false;
QList<QByteArray> search;