diff --git a/messageviewer/src/dkim-verify/dkimchecksignaturejob.h b/messageviewer/src/dkim-verify/dkimchecksignaturejob.h index 9c25b9c6..1a68b0ff 100644 --- a/messageviewer/src/dkim-verify/dkimchecksignaturejob.h +++ b/messageviewer/src/dkim-verify/dkimchecksignaturejob.h @@ -1,132 +1,143 @@ /* Copyright (C) 2018-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef DKIMCHECKSIGNATUREJOB_H #define DKIMCHECKSIGNATUREJOB_H #include #include "dkimkeyrecord.h" #include "dkiminfo.h" #include "messageviewer_export.h" #include #include namespace MessageViewer { class MESSAGEVIEWER_EXPORT DKIMCheckSignatureJob : public QObject { Q_OBJECT public: enum class DKIMStatus { Unknown, Valid, Invalid, EmailNotSigned }; enum class DKIMError { Any, CorruptedBodyHash, DomainNotExist, MissingFrom, MissingSignature, InvalidQueryMethod, InvalidHeaderCanonicalization, InvalidBodyCanonicalization, InvalidBodyHashAlgorithm, InvalidSignAlgorithm, PublicKeyWasRevoked, SignatureTooLarge, InsupportedHashAlgorithm, PublicKeyTooSmall, ImpossibleToVerifySignature, //TODO add more }; enum class DKIMWarning { Any, SignatureExpired, SignatureCreatedInFuture, SignatureTooSmall }; struct CheckSignatureResult { bool isValid() const { return (status != DKIMCheckSignatureJob::DKIMStatus::Unknown); } + Q_REQUIRED_RESULT bool operator==(const CheckSignatureResult &other) const { + return error == other.error && + warning == other.warning && + status == other.status && + item == other.item; + } + + Q_REQUIRED_RESULT bool operator!=(const CheckSignatureResult &other) const { + return !CheckSignatureResult::operator==(other); + } + DKIMCheckSignatureJob::DKIMError error = DKIMCheckSignatureJob::DKIMError::Any; DKIMCheckSignatureJob::DKIMWarning warning = DKIMCheckSignatureJob::DKIMWarning::Any; DKIMCheckSignatureJob::DKIMStatus status = DKIMCheckSignatureJob::DKIMStatus::Unknown; Akonadi::Item item; }; explicit DKIMCheckSignatureJob(QObject *parent = nullptr); ~DKIMCheckSignatureJob(); void start(); Q_REQUIRED_RESULT QString dkimValue() const; Q_REQUIRED_RESULT DKIMCheckSignatureJob::DKIMStatus status() const; void setStatus(const DKIMCheckSignatureJob::DKIMStatus &status); Q_REQUIRED_RESULT MessageViewer::DKIMCheckSignatureJob::DKIMStatus checkSignature(const MessageViewer::DKIMInfo &info); Q_REQUIRED_RESULT DKIMCheckSignatureJob::DKIMError error() const; Q_REQUIRED_RESULT KMime::Message::Ptr message() const; void setMessage(const KMime::Message::Ptr &message); Q_REQUIRED_RESULT DKIMCheckSignatureJob::DKIMWarning warning() const; void setWarning(const DKIMWarning &warning); Q_REQUIRED_RESULT QString headerCanonizationResult() const; Q_REQUIRED_RESULT QString bodyCanonizationResult() const; Q_REQUIRED_RESULT Akonadi::Item item() const; void setItem(const Akonadi::Item &item); Q_SIGNALS: void result(const MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult &checkResult); void storeKey(const QString &key, const QString &domain, const QString &selector); private: void downloadKey(const DKIMInfo &info); void slotDownloadKeyDone(const QList &lst, const QString &domain, const QString &selector); void parseDKIMKeyRecord(const QString &str, const QString &domain, const QString &selector, bool storeKeyValue = true); Q_REQUIRED_RESULT QString headerCanonizationSimple() const; Q_REQUIRED_RESULT QString headerCanonizationRelaxed() const; Q_REQUIRED_RESULT QString bodyCanonizationRelaxed() const; Q_REQUIRED_RESULT QString bodyCanonizationSimple() const; Q_REQUIRED_RESULT MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult createCheckResult(); void verifyRSASignature(); KMime::Message::Ptr mMessage; Akonadi::Item mMessageItem; DKIMInfo mDkimInfo; DKIMKeyRecord mDkimKeyRecord; QString mDkimValue; QString mHeaderCanonizationResult; QString mBodyCanonizationResult; DKIMCheckSignatureJob::DKIMError mError = DKIMCheckSignatureJob::DKIMError::Any; DKIMCheckSignatureJob::DKIMWarning mWarning = DKIMCheckSignatureJob::DKIMWarning::Any; DKIMCheckSignatureJob::DKIMStatus mStatus = DKIMCheckSignatureJob::DKIMStatus::Unknown; }; } #endif // DKIMCHECKSIGNATUREJOB_H diff --git a/messageviewer/src/dkim-verify/dkimwidgetinfo.cpp b/messageviewer/src/dkim-verify/dkimwidgetinfo.cpp index f3fed290..2101d735 100644 --- a/messageviewer/src/dkim-verify/dkimwidgetinfo.cpp +++ b/messageviewer/src/dkim-verify/dkimwidgetinfo.cpp @@ -1,123 +1,125 @@ /* Copyright (C) 2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "dkimwidgetinfo.h" #include #include #include using namespace MessageViewer; DKIMWidgetInfo::DKIMWidgetInfo(QWidget *parent) : QWidget(parent) { QHBoxLayout *mainLayout = new QHBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainLayout")); mainLayout->setContentsMargins(0, 0, 0, 0); mLabel = new QLabel(this); mLabel->setObjectName(QStringLiteral("label")); mainLayout->addWidget(mLabel); } DKIMWidgetInfo::~DKIMWidgetInfo() { } void DKIMWidgetInfo::setResult(const DKIMCheckSignatureJob::CheckSignatureResult &checkResult) { - mResult = checkResult; - updateInfo(); + if (mResult != checkResult) { + mResult = checkResult; + updateInfo(); + } } void DKIMWidgetInfo::updateInfo() { switch (mResult.status) { case DKIMCheckSignatureJob::DKIMStatus::Unknown: mLabel->setText(i18n("Unknown")); break; case DKIMCheckSignatureJob::DKIMStatus::Valid: mLabel->setText(i18n("KDIM: valid")); break; case DKIMCheckSignatureJob::DKIMStatus::Invalid: mLabel->setText(i18n("KDIM: invalid")); break; case DKIMCheckSignatureJob::DKIMStatus::EmailNotSigned: mLabel->setText(i18n("KDIM: Unsigned")); break; } updateToolTip(); } void DKIMWidgetInfo::updateToolTip() { QString tooltip; if (mResult.status == DKIMCheckSignatureJob::DKIMStatus::Invalid) { switch (mResult.error) { case DKIMCheckSignatureJob::DKIMError::Any: break; case DKIMCheckSignatureJob::DKIMError::CorruptedBodyHash: tooltip = i18n("Body Hash was corrupted."); break; case DKIMCheckSignatureJob::DKIMError::DomainNotExist: break; case DKIMCheckSignatureJob::DKIMError::MissingFrom: tooltip = i18n("Missing header From."); break; case DKIMCheckSignatureJob::DKIMError::MissingSignature: tooltip = i18n("Missing signature."); break; case DKIMCheckSignatureJob::DKIMError::InvalidQueryMethod: break; case DKIMCheckSignatureJob::DKIMError::InvalidHeaderCanonicalization: break; case DKIMCheckSignatureJob::DKIMError::InvalidBodyCanonicalization: break; case DKIMCheckSignatureJob::DKIMError::InvalidBodyHashAlgorithm: break; case DKIMCheckSignatureJob::DKIMError::InvalidSignAlgorithm: break; case DKIMCheckSignatureJob::DKIMError::PublicKeyWasRevoked: tooltip = i18n("The public key was revoked."); break; case DKIMCheckSignatureJob::DKIMError::SignatureTooLarge: break; case DKIMCheckSignatureJob::DKIMError::InsupportedHashAlgorithm: tooltip = i18n("Hash Algorithm is unsupported."); break; case DKIMCheckSignatureJob::DKIMError::PublicKeyTooSmall: break; case DKIMCheckSignatureJob::DKIMError::ImpossibleToVerifySignature: break; } } switch (mResult.warning) { case DKIMCheckSignatureJob::DKIMWarning::Any: break; case DKIMCheckSignatureJob::DKIMWarning::SignatureExpired: tooltip = i18n("Signature expired"); break; case DKIMCheckSignatureJob::DKIMWarning::SignatureCreatedInFuture: tooltip = i18n("Signature created in the future"); break; case DKIMCheckSignatureJob::DKIMWarning::SignatureTooSmall: tooltip = i18n("Signature too small"); break; } mLabel->setToolTip(tooltip); }