From 37983d97ec0eb03845f11eb03f429174acfd327b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 6 Jun 2017 00:27:24 +0200 Subject: A simplistic security border Still a bit obnoxious and doesn't really convey a whole lot of information. Consider it a stub for now --- framework/src/domain/mime/mimetreeparser/enums.h | 20 ++++++++-------- .../src/domain/mime/mimetreeparser/messagepart.cpp | 28 +++++++++++++++++++--- .../src/domain/mime/mimetreeparser/messagepart.h | 7 ++++-- .../mime/mimetreeparser/tests/interfacetest.cpp | 9 +++++++ framework/src/domain/mime/partmodel.cpp | 4 ++-- 5 files changed, 51 insertions(+), 17 deletions(-) (limited to 'framework/src/domain') diff --git a/framework/src/domain/mime/mimetreeparser/enums.h b/framework/src/domain/mime/mimetreeparser/enums.h index bec5a028..db3af165 100644 --- a/framework/src/domain/mime/mimetreeparser/enums.h +++ b/framework/src/domain/mime/mimetreeparser/enums.h @@ -33,20 +33,20 @@ enum UpdateMode { /** Flags for the encryption state. */ typedef enum { - KMMsgEncryptionStateUnknown = ' ', - KMMsgNotEncrypted = 'N', - KMMsgPartiallyEncrypted = 'P', - KMMsgFullyEncrypted = 'F', - KMMsgEncryptionProblematic = 'X' + KMMsgEncryptionStateUnknown, + KMMsgNotEncrypted, + KMMsgPartiallyEncrypted, + KMMsgFullyEncrypted, + KMMsgEncryptionProblematic } KMMsgEncryptionState; /** Flags for the signature state. */ typedef enum { - KMMsgSignatureStateUnknown = ' ', - KMMsgNotSigned = 'N', - KMMsgPartiallySigned = 'P', - KMMsgFullySigned = 'F', - KMMsgSignatureProblematic = 'X' + KMMsgSignatureStateUnknown, + KMMsgNotSigned, + KMMsgPartiallySigned, + KMMsgFullySigned, + KMMsgSignatureProblematic } KMMsgSignatureState; } diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.cpp b/framework/src/domain/mime/mimetreeparser/messagepart.cpp index b4db4016..00abb003 100644 --- a/framework/src/domain/mime/mimetreeparser/messagepart.cpp +++ b/framework/src/domain/mime/mimetreeparser/messagepart.cpp @@ -312,6 +312,22 @@ QVector MessagePart::encryptions() const return list; } +KMMsgEncryptionState MessagePart::encryptionState() const +{ + if (!encryptions().isEmpty()) { + return KMMsgFullyEncrypted; + } + return KMMsgNotEncrypted; +} + +KMMsgSignatureState MessagePart::signatureState() const +{ + if (!signatures().isEmpty()) { + return KMMsgFullySigned; + } + return KMMsgNotSigned; +} + void MessagePart::bindLifetime(KMime::Content *node) { mNodesToDelete << node; @@ -346,7 +362,9 @@ QString MessagePartList::htmlContent() const //-----TextMessageBlock---------------------- TextMessagePart::TextMessagePart(ObjectTreeParser *otp, KMime::Content *node) - : MessagePartList(otp, node) + : MessagePartList(otp, node), + mSignatureState(KMMsgSignatureStateUnknown), + mEncryptionState(KMMsgEncryptionStateUnknown) { if (!mNode) { qCWarning(MIMETREEPARSER_LOG) << "not a valid node"; @@ -401,7 +419,6 @@ void TextMessagePart::parseContent() mp->bindLifetime(content); mp->setIsEncrypted(true); appendSubPart(mp); - continue; } else if (block.type() == ClearsignedBlock) { KMime::Content *content = new KMime::Content; content->setBody(block.text()); @@ -410,7 +427,6 @@ void TextMessagePart::parseContent() mp->bindLifetime(content); mp->setIsSigned(true); appendSubPart(mp); - continue; } else { continue; } @@ -445,11 +461,17 @@ void TextMessagePart::parseContent() KMMsgEncryptionState TextMessagePart::encryptionState() const { + if (mEncryptionState == KMMsgNotEncrypted) { + return MessagePart::encryptionState(); + } return mEncryptionState; } KMMsgSignatureState TextMessagePart::signatureState() const { + if (mSignatureState == KMMsgNotSigned) { + return MessagePart::signatureState(); + } return mSignatureState; } diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.h b/framework/src/domain/mime/mimetreeparser/messagepart.h index 9fe34c3b..dd3a842f 100644 --- a/framework/src/domain/mime/mimetreeparser/messagepart.h +++ b/framework/src/domain/mime/mimetreeparser/messagepart.h @@ -112,6 +112,9 @@ public: KMime::Content *node() const; + virtual KMMsgSignatureState signatureState() const; + virtual KMMsgEncryptionState encryptionState() const; + QVector signatures() const; QVector encryptions() const; @@ -178,8 +181,8 @@ public: TextMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node); virtual ~TextMessagePart(); - KMMsgSignatureState signatureState() const; - KMMsgEncryptionState encryptionState() const; + KMMsgSignatureState signatureState() const Q_DECL_OVERRIDE; + KMMsgEncryptionState encryptionState() const Q_DECL_OVERRIDE; private: void parseContent(); diff --git a/framework/src/domain/mime/mimetreeparser/tests/interfacetest.cpp b/framework/src/domain/mime/mimetreeparser/tests/interfacetest.cpp index 74f12eec..f9b557c9 100644 --- a/framework/src/domain/mime/mimetreeparser/tests/interfacetest.cpp +++ b/framework/src/domain/mime/mimetreeparser/tests/interfacetest.cpp @@ -125,16 +125,22 @@ private slots: QCOMPARE(part->charset(), QStringLiteral("us-ascii").toLocal8Bit()); QCOMPARE(part->encryptions().size(), 1); QCOMPARE(part->signatures().size(), 1); + QCOMPARE(part->encryptionState(), MimeTreeParser::KMMsgFullyEncrypted); + QCOMPARE(part->signatureState(), MimeTreeParser::KMMsgFullySigned); auto contentAttachmentList = otp.collectAttachmentParts(); QCOMPARE(contentAttachmentList.size(), 2); // QCOMPARE(contentAttachmentList[0]->availableContents(), QVector() << "text/plain"); // QCOMPARE(contentAttachmentList[0]->content().size(), 1); QCOMPARE(contentAttachmentList[0]->encryptions().size(), 1); QCOMPARE(contentAttachmentList[0]->signatures().size(), 1); + QCOMPARE(contentAttachmentList[0]->encryptionState(), MimeTreeParser::KMMsgFullyEncrypted); + QCOMPARE(contentAttachmentList[0]->signatureState(), MimeTreeParser::KMMsgFullySigned); // QCOMPARE(contentAttachmentList[1]->availableContents(), QVector() << "image/png"); // QCOMPARE(contentAttachmentList[1]->content().size(), 1); QCOMPARE(contentAttachmentList[1]->encryptions().size(), 0); QCOMPARE(contentAttachmentList[1]->signatures().size(), 0); + QCOMPARE(contentAttachmentList[1]->encryptionState(), MimeTreeParser::KMMsgNotEncrypted); + QCOMPARE(contentAttachmentList[1]->signatureState(), MimeTreeParser::KMMsgNotSigned); } void testOpenPGPInline() @@ -173,6 +179,9 @@ private slots: //TODO test if we get the proper subparts with the appropriate encryptions QCOMPARE(part1->charset(), QStringLiteral("us-ascii").toLocal8Bit()); + QCOMPARE(part1->encryptionState(), MimeTreeParser::KMMsgPartiallyEncrypted); + QCOMPARE(part1->signatureState(), MimeTreeParser::KMMsgNotSigned); + // QCOMPARE(part1->text(), QStringLiteral("Not encrypted not signed :(\n\n")); // QCOMPARE(part1->charset(), QStringLiteral("us-ascii").toLocal8Bit()); // QCOMPARE(contentList[1]->content(), QStringLiteral("some random text").toLocal8Bit()); diff --git a/framework/src/domain/mime/partmodel.cpp b/framework/src/domain/mime/partmodel.cpp index b86251ef..ea3e90e1 100644 --- a/framework/src/domain/mime/partmodel.cpp +++ b/framework/src/domain/mime/partmodel.cpp @@ -151,9 +151,9 @@ QVariant PartModel::data(const QModelIndex &index, int role) const return text; } case IsEncryptedRole: - return messagePart->encryptions().size() > 0; + return messagePart->encryptionState() != MimeTreeParser::KMMsgNotEncrypted; case IsSignedRole: - return messagePart->signatures().size() > 0; + return messagePart->signatureState() != MimeTreeParser::KMMsgNotSigned; case EncryptionErrorType: return messagePart->error(); case EncryptionErrorString: -- cgit v1.2.3