diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-06-11 22:42:28 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-06-11 22:49:59 +0200 |
commit | e331c1cd5fc25e814a849d2db5c0beaf0024a47c (patch) | |
tree | 232bec65b4094a98ba405336ba42c6ae23b42474 | |
parent | 37a2512e3cc58722d637471fae950593ccf4ef1d (diff) | |
download | kube-e331c1cd5fc25e814a849d2db5c0beaf0024a47c.tar.gz kube-e331c1cd5fc25e814a849d2db5c0beaf0024a47c.zip |
MessagePart error enum
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/messagepart.cpp | 91 | ||||
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/messagepart.h | 16 | ||||
-rw-r--r-- | framework/src/domain/mime/partmodel.cpp | 4 |
3 files changed, 50 insertions, 61 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.cpp b/framework/src/domain/mime/mimetreeparser/messagepart.cpp index 10dee9cf..939554fe 100644 --- a/framework/src/domain/mime/mimetreeparser/messagepart.cpp +++ b/framework/src/domain/mime/mimetreeparser/messagepart.cpp | |||
@@ -57,6 +57,7 @@ MessagePart::MessagePart(ObjectTreeParser *otp, const QString &text, KMime::Cont | |||
57 | , mNode(node) //only null for messagepartlist | 57 | , mNode(node) //only null for messagepartlist |
58 | , mParentPart(nullptr) | 58 | , mParentPart(nullptr) |
59 | , mRoot(false) | 59 | , mRoot(false) |
60 | , mError(NoError) | ||
60 | { | 61 | { |
61 | } | 62 | } |
62 | 63 | ||
@@ -166,15 +167,9 @@ bool MessagePart::isText() const | |||
166 | return false; | 167 | return false; |
167 | } | 168 | } |
168 | 169 | ||
169 | int MessagePart::error() const | 170 | MessagePart::Error MessagePart::error() const |
170 | { | 171 | { |
171 | if (dynamic_cast<const EncryptedMessagePart*>(this)) { | 172 | return mError; |
172 | //TODO Find a better way to detect errors | ||
173 | if (mMetaData.errorText != QStringLiteral("Success")) { | ||
174 | return 1; | ||
175 | } | ||
176 | } | ||
177 | return 0; | ||
178 | } | 173 | } |
179 | 174 | ||
180 | QString MessagePart::errorString() const | 175 | QString MessagePart::errorString() const |
@@ -685,7 +680,6 @@ SignedMessagePart::SignedMessagePart(ObjectTreeParser *otp, | |||
685 | , mFromAddress(fromAddress) | 680 | , mFromAddress(fromAddress) |
686 | , mSignedData(signedData) | 681 | , mSignedData(signedData) |
687 | { | 682 | { |
688 | mMetaData.technicalProblem = (mCryptoProto == nullptr); | ||
689 | mMetaData.isSigned = true; | 683 | mMetaData.isSigned = true; |
690 | mMetaData.isGoodSignature = false; | 684 | mMetaData.isGoodSignature = false; |
691 | mMetaData.keyTrust = GpgME::Signature::Unknown; | 685 | mMetaData.keyTrust = GpgME::Signature::Unknown; |
@@ -713,7 +707,6 @@ bool SignedMessagePart::okVerify(const QByteArray &data, const QByteArray &signa | |||
713 | NodeHelper *nodeHelper = mOtp->nodeHelper(); | 707 | NodeHelper *nodeHelper = mOtp->nodeHelper(); |
714 | 708 | ||
715 | mMetaData.isSigned = false; | 709 | mMetaData.isSigned = false; |
716 | mMetaData.technicalProblem = (mCryptoProto == nullptr); | ||
717 | mMetaData.keyTrust = GpgME::Signature::Unknown; | 710 | mMetaData.keyTrust = GpgME::Signature::Unknown; |
718 | mMetaData.status = i18n("Wrong Crypto Plug-In."); | 711 | mMetaData.status = i18n("Wrong Crypto Plug-In."); |
719 | mMetaData.status_code = GPGME_SIG_STAT_NONE; | 712 | mMetaData.status_code = GPGME_SIG_STAT_NONE; |
@@ -1016,13 +1009,10 @@ EncryptedMessagePart::EncryptedMessagePart(ObjectTreeParser *otp, | |||
1016 | const QString &fromAddress, | 1009 | const QString &fromAddress, |
1017 | KMime::Content *node, KMime::Content *encryptedNode) | 1010 | KMime::Content *node, KMime::Content *encryptedNode) |
1018 | : MessagePart(otp, text, node) | 1011 | : MessagePart(otp, text, node) |
1019 | , mPassphraseError(false) | ||
1020 | , mNoSecKey(false) | ||
1021 | , mCryptoProto(cryptoProto) | 1012 | , mCryptoProto(cryptoProto) |
1022 | , mFromAddress(fromAddress) | 1013 | , mFromAddress(fromAddress) |
1023 | , mEncryptedNode(encryptedNode) | 1014 | , mEncryptedNode(encryptedNode) |
1024 | { | 1015 | { |
1025 | mMetaData.technicalProblem = (mCryptoProto == nullptr); | ||
1026 | mMetaData.isSigned = false; | 1016 | mMetaData.isSigned = false; |
1027 | mMetaData.isGoodSignature = false; | 1017 | mMetaData.isGoodSignature = false; |
1028 | mMetaData.isEncrypted = false; | 1018 | mMetaData.isEncrypted = false; |
@@ -1052,11 +1042,6 @@ bool EncryptedMessagePart::isDecryptable() const | |||
1052 | return mMetaData.isDecryptable; | 1042 | return mMetaData.isDecryptable; |
1053 | } | 1043 | } |
1054 | 1044 | ||
1055 | bool EncryptedMessagePart::passphraseError() const | ||
1056 | { | ||
1057 | return mPassphraseError; | ||
1058 | } | ||
1059 | |||
1060 | void EncryptedMessagePart::startDecryption(const QByteArray &text, const QTextCodec *aCodec) | 1045 | void EncryptedMessagePart::startDecryption(const QByteArray &text, const QTextCodec *aCodec) |
1061 | { | 1046 | { |
1062 | KMime::Content *content = new KMime::Content; | 1047 | KMime::Content *content = new KMime::Content; |
@@ -1083,21 +1068,24 @@ void EncryptedMessagePart::startDecryption(const QByteArray &text, const QTextCo | |||
1083 | 1068 | ||
1084 | bool EncryptedMessagePart::okDecryptMIME(KMime::Content &data) | 1069 | bool EncryptedMessagePart::okDecryptMIME(KMime::Content &data) |
1085 | { | 1070 | { |
1086 | mPassphraseError = false; | 1071 | mError = NoError; |
1072 | auto passphraseError = false; | ||
1073 | auto noSecKey = false; | ||
1087 | mMetaData.inProgress = false; | 1074 | mMetaData.inProgress = false; |
1088 | mMetaData.errorText.clear(); | 1075 | mMetaData.errorText.clear(); |
1089 | mMetaData.auditLogError = GpgME::Error(); | 1076 | mMetaData.auditLogError = GpgME::Error(); |
1090 | mMetaData.auditLog.clear(); | 1077 | mMetaData.auditLog.clear(); |
1091 | bool bDecryptionOk = false; | ||
1092 | NodeHelper *nodeHelper = mOtp->nodeHelper(); | 1078 | NodeHelper *nodeHelper = mOtp->nodeHelper(); |
1093 | 1079 | ||
1094 | if (!mCryptoProto) { | 1080 | if (!mCryptoProto) { |
1081 | mError = UnknownError; | ||
1095 | mMetaData.errorText = i18n("No appropriate crypto plug-in was found."); | 1082 | mMetaData.errorText = i18n("No appropriate crypto plug-in was found."); |
1096 | return false; | 1083 | return false; |
1097 | } | 1084 | } |
1098 | 1085 | ||
1099 | QGpgME::DecryptVerifyJob *job = mCryptoProto->decryptVerifyJob(); | 1086 | QGpgME::DecryptVerifyJob *job = mCryptoProto->decryptVerifyJob(); |
1100 | if (!job) { | 1087 | if (!job) { |
1088 | mError = UnknownError; | ||
1101 | mMetaData.errorText = i18n("Crypto plug-in \"%1\" cannot decrypt messages.", mCryptoProto->name()); | 1089 | mMetaData.errorText = i18n("Crypto plug-in \"%1\" cannot decrypt messages.", mCryptoProto->name()); |
1102 | return false; | 1090 | return false; |
1103 | } | 1091 | } |
@@ -1119,51 +1107,52 @@ bool EncryptedMessagePart::okDecryptMIME(KMime::Content &data) | |||
1119 | } | 1107 | } |
1120 | 1108 | ||
1121 | mDecryptRecipients = decryptResult.recipients(); | 1109 | mDecryptRecipients = decryptResult.recipients(); |
1122 | bDecryptionOk = !decryptResult.error(); | 1110 | auto decryptionOk = !decryptResult.error(); |
1123 | 1111 | ||
1124 | if (!bDecryptionOk) { | 1112 | if (!decryptionOk && mMetaData.isSigned) { |
1125 | std::stringstream ss; | ||
1126 | ss << decryptResult << '\n' << verifyResult; | ||
1127 | qWarning() << ss.str().c_str(); | ||
1128 | } | ||
1129 | |||
1130 | if (!bDecryptionOk && mMetaData.isSigned) { | ||
1131 | //Only a signed part | 1113 | //Only a signed part |
1132 | mMetaData.isEncrypted = false; | 1114 | mMetaData.isEncrypted = false; |
1133 | bDecryptionOk = true; | ||
1134 | mDecryptedData = plainText; | 1115 | mDecryptedData = plainText; |
1116 | return true; | ||
1117 | } | ||
1118 | |||
1119 | passphraseError = decryptResult.error().isCanceled() || decryptResult.error().code() == GPG_ERR_NO_SECKEY; | ||
1120 | mMetaData.isEncrypted = decryptResult.error().code() != GPG_ERR_NO_DATA; | ||
1121 | mMetaData.errorText = QString::fromLocal8Bit(decryptResult.error().asString()); | ||
1122 | if (mMetaData.isEncrypted && decryptResult.numRecipients() > 0) { | ||
1123 | mMetaData.keyId = decryptResult.recipient(0).keyID(); | ||
1124 | } | ||
1125 | |||
1126 | if (decryptionOk) { | ||
1127 | mDecryptedData = plainText; | ||
1128 | setText(QString::fromUtf8(mDecryptedData.constData())); | ||
1135 | } else { | 1129 | } else { |
1136 | mPassphraseError = decryptResult.error().isCanceled() || decryptResult.error().code() == GPG_ERR_NO_SECKEY; | 1130 | noSecKey = true; |
1137 | mMetaData.isEncrypted = decryptResult.error().code() != GPG_ERR_NO_DATA; | 1131 | foreach (const GpgME::DecryptionResult::Recipient &recipient, decryptResult.recipients()) { |
1138 | mMetaData.errorText = QString::fromLocal8Bit(decryptResult.error().asString()); | 1132 | noSecKey &= (recipient.status().code() == GPG_ERR_NO_SECKEY); |
1139 | if (mMetaData.isEncrypted && decryptResult.numRecipients() > 0) { | ||
1140 | mMetaData.keyId = decryptResult.recipient(0).keyID(); | ||
1141 | } | 1133 | } |
1142 | 1134 | if (!passphraseError && !noSecKey) { // GpgME do not detect passphrase error correctly | |
1143 | if (bDecryptionOk) { | 1135 | passphraseError = true; |
1144 | mDecryptedData = plainText; | ||
1145 | setText(QString::fromUtf8(mDecryptedData.constData())); | ||
1146 | } else { | ||
1147 | mNoSecKey = true; | ||
1148 | foreach (const GpgME::DecryptionResult::Recipient &recipient, decryptResult.recipients()) { | ||
1149 | mNoSecKey &= (recipient.status().code() == GPG_ERR_NO_SECKEY); | ||
1150 | } | ||
1151 | if (!mPassphraseError && !mNoSecKey) { // GpgME do not detect passphrase error correctly | ||
1152 | mPassphraseError = true; | ||
1153 | } | ||
1154 | } | 1136 | } |
1155 | } | 1137 | std::stringstream ss; |
1138 | ss << decryptResult << '\n' << verifyResult; | ||
1139 | qWarning() << "Decryption failed: " << ss.str().c_str(); | ||
1156 | 1140 | ||
1157 | if (!bDecryptionOk) { | 1141 | if(noSecKey) { |
1158 | if(mNoSecKey) { | 1142 | mError = NoKeyError; |
1159 | mMetaData.errorText = i18n("Crypto plug-in \"%1\" could not decrypt the data. ", mCryptoProto->name()) | 1143 | mMetaData.errorText = i18n("Crypto plug-in \"%1\" could not decrypt the data. ", mCryptoProto->name()) |
1160 | + i18n("No key found for recepients."); | 1144 | + i18n("No key found for recepients."); |
1161 | } else if (!passphraseError()) { | 1145 | } else if (passphraseError) { |
1146 | mError = PassphraseError; | ||
1147 | } else { | ||
1148 | mError = UnknownError; | ||
1162 | mMetaData.errorText = i18n("Crypto plug-in \"%1\" could not decrypt the data. ", mCryptoProto->name()) | 1149 | mMetaData.errorText = i18n("Crypto plug-in \"%1\" could not decrypt the data. ", mCryptoProto->name()) |
1163 | + i18n("Error: %1", mMetaData.errorText); | 1150 | + i18n("Error: %1", mMetaData.errorText); |
1164 | } | 1151 | } |
1152 | return false; | ||
1165 | } | 1153 | } |
1166 | return bDecryptionOk; | 1154 | |
1155 | return true; | ||
1167 | } | 1156 | } |
1168 | 1157 | ||
1169 | void EncryptedMessagePart::startDecryption(KMime::Content *data) | 1158 | void EncryptedMessagePart::startDecryption(KMime::Content *data) |
diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.h b/framework/src/domain/mime/mimetreeparser/messagepart.h index 7d266ac5..5cd186e6 100644 --- a/framework/src/domain/mime/mimetreeparser/messagepart.h +++ b/framework/src/domain/mime/mimetreeparser/messagepart.h | |||
@@ -101,7 +101,15 @@ public: | |||
101 | QString filename() const; | 101 | QString filename() const; |
102 | Disposition disposition() const; | 102 | Disposition disposition() const; |
103 | bool isText() const; | 103 | bool isText() const; |
104 | int error() const; | 104 | |
105 | enum Error { | ||
106 | NoError = 0, | ||
107 | PassphraseError, | ||
108 | NoKeyError, | ||
109 | UnknownError | ||
110 | }; | ||
111 | |||
112 | Error error() const; | ||
105 | QString errorString() const; | 113 | QString errorString() const; |
106 | 114 | ||
107 | PartMetaData *partMetaData(); | 115 | PartMetaData *partMetaData(); |
@@ -130,6 +138,7 @@ protected: | |||
130 | MessagePart *mParentPart; | 138 | MessagePart *mParentPart; |
131 | KMime::Content *mNode; | 139 | KMime::Content *mNode; |
132 | QVector<KMime::Content*> mNodesToDelete; | 140 | QVector<KMime::Content*> mNodesToDelete; |
141 | Error mError; | ||
133 | 142 | ||
134 | private: | 143 | private: |
135 | QVector<MessagePart::Ptr> mBlocks; | 144 | QVector<MessagePart::Ptr> mBlocks; |
@@ -293,7 +302,6 @@ class EncryptedMessagePart : public MessagePart | |||
293 | { | 302 | { |
294 | Q_OBJECT | 303 | Q_OBJECT |
295 | Q_PROPERTY(bool isEncrypted READ isEncrypted) | 304 | Q_PROPERTY(bool isEncrypted READ isEncrypted) |
296 | Q_PROPERTY(bool passphraseError READ passphraseError) | ||
297 | public: | 305 | public: |
298 | typedef QSharedPointer<EncryptedMessagePart> Ptr; | 306 | typedef QSharedPointer<EncryptedMessagePart> Ptr; |
299 | EncryptedMessagePart(ObjectTreeParser *otp, | 307 | EncryptedMessagePart(ObjectTreeParser *otp, |
@@ -311,8 +319,6 @@ public: | |||
311 | 319 | ||
312 | bool isDecryptable() const; | 320 | bool isDecryptable() const; |
313 | 321 | ||
314 | bool passphraseError() const; | ||
315 | |||
316 | void startDecryption(const QByteArray &text, const QTextCodec *aCodec); | 322 | void startDecryption(const QByteArray &text, const QTextCodec *aCodec); |
317 | void startDecryption(KMime::Content *data = nullptr); | 323 | void startDecryption(KMime::Content *data = nullptr); |
318 | 324 | ||
@@ -329,8 +335,6 @@ private: | |||
329 | bool okDecryptMIME(KMime::Content &data); | 335 | bool okDecryptMIME(KMime::Content &data); |
330 | 336 | ||
331 | protected: | 337 | protected: |
332 | bool mPassphraseError; | ||
333 | bool mNoSecKey; | ||
334 | const QGpgME::Protocol *mCryptoProto; | 338 | const QGpgME::Protocol *mCryptoProto; |
335 | QString mFromAddress; | 339 | QString mFromAddress; |
336 | QByteArray mVerifiedText; | 340 | QByteArray mVerifiedText; |
diff --git a/framework/src/domain/mime/partmodel.cpp b/framework/src/domain/mime/partmodel.cpp index d03ae103..a87a60df 100644 --- a/framework/src/domain/mime/partmodel.cpp +++ b/framework/src/domain/mime/partmodel.cpp | |||
@@ -167,10 +167,6 @@ QVariant PartModel::data(const QModelIndex &index, int role) const | |||
167 | case IsErrorRole: | 167 | case IsErrorRole: |
168 | return messagePart->error(); | 168 | return messagePart->error(); |
169 | case ContentRole: { | 169 | case ContentRole: { |
170 | auto errorText = messagePart->partMetaData()->errorText; | ||
171 | if (!errorText.isEmpty()) { | ||
172 | return errorText; | ||
173 | } | ||
174 | const auto text = messagePart->isHtml() ? messagePart->htmlContent() : messagePart->text(); | 170 | const auto text = messagePart->isHtml() ? messagePart->htmlContent() : messagePart->text(); |
175 | if (messagePart->isHtml()) { | 171 | if (messagePart->isHtml()) { |
176 | return d->mParser->resolveCidLinks(text); | 172 | return d->mParser->resolveCidLinks(text); |