From 816a7aaba15bef4773bcc3ddf12b3ffb93db0bae Mon Sep 17 00:00:00 2001 From: Andre Heinecke <aheinecke@intevation.de> Date: Thu, 18 Feb 2016 12:02:58 +0100 Subject: [PATCH 44/74] Improve detection of lastEncryptAndSignState KMime::isSigned and KMime::isEncrypted only work well for MIME mails where the outer content type is set accordingly. It also when a PGP/MIME message is singed and encrypted (where it only detects encrypted). The objecttreeparser also does not return the signatureState correctly in that case so we default to Signed & Encrypted for that as this is best practice. --- kmail/util.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/kmail/util.cpp b/kmail/util.cpp index 943024fa68..1c28a6186c 100644 --- a/kmail/util.cpp +++ b/kmail/util.cpp @@ -41,6 +41,9 @@ #include "messagecore/utils/stringutil.h" #include "messagecomposer/helper/messagehelper.h" +#include "messageviewer/viewer/objecttreeemptysource.h" +#include "messageviewer/viewer/objecttreeparser.h" + #include "templateparser/templateparser.h" #include <kmime/kmime_message.h> @@ -184,8 +187,24 @@ bool KMail::Util::mailingListHelp( const QSharedPointer<MailCommon::FolderCollec void KMail::Util::lastEncryptAndSignState(bool &lastEncrypt, bool &lastSign, const KMime::Message::Ptr& msg) { - lastSign = KMime::isSigned(msg.get()); - lastEncrypt = KMime::isEncrypted(msg.get()); + // lastSign = KMime::isSigned(msg.get()); + // lastEncrypt = KMime::isEncrypted(msg.get()); + // KMime does not find inline Encrypted or get the correct state when a pgp/mime + // message is signed and encrypted (because you need to decrypt first to find that out) + // So we need to do the Objecttree parsing here to get the correct state. + MessageViewer::EmptySource source; + source.setAllowDecryption(true); + MessageViewer::NodeHelper nodeHelper; + + MessageViewer::ObjectTreeParser otp( &source, &nodeHelper, 0 , true, false, true ); + otp.parseObjectTree( msg->topLevel() ); + + MessageViewer::KMMsgEncryptionState encState = nodeHelper.overallEncryptionState( msg.get() ); + MessageViewer::KMMsgSignatureState sigState = nodeHelper.overallSignatureState( msg.get() ); + lastEncrypt = (encState == MessageViewer::KMMsgFullyEncrypted || + encState == MessageViewer::KMMsgPartiallyEncrypted); + lastSign = (sigState == MessageViewer::KMMsgFullySigned || + sigState == MessageViewer::KMMsgPartiallySigned); } QColor KMail::Util::misspelledColor() -- 2.14.1