diff --git a/messageviewer/src/dkim-verify/autotests/dkimcheckpolicyjobtest.cpp b/messageviewer/src/dkim-verify/autotests/dkimcheckpolicyjobtest.cpp index e78df17b..6baafffe 100644 --- a/messageviewer/src/dkim-verify/autotests/dkimcheckpolicyjobtest.cpp +++ b/messageviewer/src/dkim-verify/autotests/dkimcheckpolicyjobtest.cpp @@ -1,36 +1,35 @@ /* 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 "dkimcheckpolicyjobtest.h" #include "dkim-verify/dkimcheckpolicyjob.h" #include QTEST_GUILESS_MAIN(DKIMCheckPolicyJobTest) DKIMCheckPolicyJobTest::DKIMCheckPolicyJobTest(QObject *parent) : QObject(parent) { - } void DKIMCheckPolicyJobTest::shouldHaveDefaultValues() { MessageViewer::DKIMCheckPolicyJob job; QVERIFY(job.emailAddress().isEmpty()); QVERIFY(!job.canStart()); } diff --git a/messageviewer/src/dkim-verify/autotests/dkimutiltest.cpp b/messageviewer/src/dkim-verify/autotests/dkimutiltest.cpp index 6e5aabe0..9e483ef1 100644 --- a/messageviewer/src/dkim-verify/autotests/dkimutiltest.cpp +++ b/messageviewer/src/dkim-verify/autotests/dkimutiltest.cpp @@ -1,71 +1,69 @@ /* 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 "dkimutiltest.h" #include "dkim-verify/dkimutil.h" #include QTEST_GUILESS_MAIN(DKIMUtilTest) DKIMUtilTest::DKIMUtilTest(QObject *parent) : QObject(parent) { } void DKIMUtilTest::shouldTestBodyCanonizationRelaxed() { { QString ba = QStringLiteral("-- \nLaurent Montel | laurent.montel@kdab.com | KDE/Qt Senior Software Engineer \nKDAB (France) S.A.S., a KDAB Group company\nTel: France +33 (0)4 90 84 08 53, http://www.kdab.fr\nKDAB - The Qt, C++ and OpenGL Experts\n\n\n"); QString result = MessageViewer::DKIMUtil::bodyCanonizationRelaxed(ba); QCOMPARE(MessageViewer::DKIMUtil::generateHash(result.toUtf8(), QCryptographicHash::Sha256), "jnEyWN7LwPIBgES0mElYDek3lmyrRtSwUjDR2Ge08Xw="); } { QString ba = QStringLiteral("Bla bla\n\nbli\t\tblo\nTest\n\n\n\n\n"); QString result = MessageViewer::DKIMUtil::bodyCanonizationRelaxed(ba); QCOMPARE(MessageViewer::DKIMUtil::generateHash(result.toUtf8(), QCryptographicHash::Sha256), "DrwZwEC82qsIhJtHlq76T00vAUcrSrHbJh8wY5GTAws="); } } void DKIMUtilTest::shouldVerifyEmailDomain() { QCOMPARE(MessageViewer::DKIMUtil::emailDomain(QStringLiteral("foo@kde.org")), QStringLiteral("kde.org")); QCOMPARE(MessageViewer::DKIMUtil::emailDomain(QStringLiteral("foo@blo.bli.kde.org")), QStringLiteral("blo.bli.kde.org")); } void DKIMUtilTest::shouldVerifySubEmailDomain() { { const QString email = QStringLiteral("goo@kde.org"); const QString domainName = MessageViewer::DKIMUtil::emailDomain(email); QCOMPARE(MessageViewer::DKIMUtil::emailSubDomain(domainName), QStringLiteral("kde.org")); } { const QString email = QStringLiteral("goo@bla.bli.kde.org"); const QString domainName = MessageViewer::DKIMUtil::emailDomain(email); QCOMPARE(MessageViewer::DKIMUtil::emailSubDomain(domainName), QStringLiteral("kde.org")); } { const QString email = QStringLiteral("goo@bli.kde.org"); const QString domainName = MessageViewer::DKIMUtil::emailDomain(email); QCOMPARE(MessageViewer::DKIMUtil::emailSubDomain(domainName), QStringLiteral("kde.org")); } - } - diff --git a/messageviewer/src/dkim-verify/dkimcheckpolicyjob.cpp b/messageviewer/src/dkim-verify/dkimcheckpolicyjob.cpp index dc5dce9b..571905ec 100644 --- a/messageviewer/src/dkim-verify/dkimcheckpolicyjob.cpp +++ b/messageviewer/src/dkim-verify/dkimcheckpolicyjob.cpp @@ -1,98 +1,96 @@ /* 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 "dkimcheckpolicyjob.h" #include "dmarcpolicyjob.h" #include "settings/messageviewersettings.h" #include "messageviewer_dkimcheckerdebug.h" using namespace MessageViewer; DKIMCheckPolicyJob::DKIMCheckPolicyJob(QObject *parent) : QObject(parent) { - } DKIMCheckPolicyJob::~DKIMCheckPolicyJob() { - } bool DKIMCheckPolicyJob::canStart() const { //TODO verify it ! return !mEmailAddress.isEmpty(); } bool DKIMCheckPolicyJob::start() { if (!canStart()) { qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "Impossible to start DKIMCheckPolicyJob" << mEmailAddress; Q_EMIT result(mCheckResult); deleteLater(); return false; } if (MessageViewer::MessageViewerSettings::self()->useDMarc()) { DMARCPolicyJob *job = new DMARCPolicyJob(this); job->setEmailAddress(mEmailAddress); connect(job, &DMARCPolicyJob::result, this, &DKIMCheckPolicyJob::dmarcPolicyResult); if (!job->start()) { qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "Impossible to start DKIMCheckPolicyJob" << mEmailAddress; Q_EMIT result(mCheckResult); deleteLater(); return false; } } else { //Verify list } //TODO return true; } void DKIMCheckPolicyJob::dmarcPolicyResult(const MessageViewer::DMARCPolicyJob::DMARCResult &value) { if (mCheckResult.status == DKIMCheckSignatureJob::DKIMStatus::EmailNotSigned) { mCheckResult.status = DKIMCheckSignatureJob::DKIMStatus::NeedToBeSigned; //TODO verify it. qDebug() << " void DKIMCheckPolicyJob::dmarcPolicyResult(const MessageViewer::DMARCPolicyJob::DMARCResult &value)"< 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 "messageviewer_export.h" #include #include #include #include namespace MessageViewer { class MESSAGEVIEWER_EXPORT DKIMCheckSignatureJob : public QObject { Q_OBJECT public: enum class DKIMStatus : int { Unknown = 0, Valid = 1, Invalid = 2, EmailNotSigned = 3, NeedToBeSigned = 4 }; Q_ENUM(DKIMStatus) enum class DKIMError : int { Any = 0, CorruptedBodyHash = 1, DomainNotExist = 2, MissingFrom = 3, MissingSignature = 4, InvalidQueryMethod = 5, InvalidHeaderCanonicalization = 6, InvalidBodyCanonicalization = 7, InvalidBodyHashAlgorithm = 8, InvalidSignAlgorithm = 9, PublicKeyWasRevoked = 10, SignatureTooLarge = 11, InsupportedHashAlgorithm = 12, PublicKeyTooSmall = 13, ImpossibleToVerifySignature = 14, DomainI = 15, TestKeyMode = 16, ImpossibleToDownloadKey = 17, }; Q_ENUM(DKIMError) enum class DKIMWarning : int { Any = 0, SignatureExpired = 1, SignatureCreatedInFuture = 2, SignatureTooSmall = 3, HashAlgorithmUnsafe = 4, }; Q_ENUM(DKIMWarning) 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 - && fromEmail == other.fromEmail; + && fromEmail == other.fromEmail; } 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; QString signedBy; QString fromEmail; }; 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_REQUIRED_RESULT bool saveKey() const; void setSaveKey(bool saveKey); 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; QString mFromEmail; 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; bool mSaveKey = false; }; } Q_DECLARE_METATYPE(MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult) #endif // DKIMCHECKSIGNATUREJOB_H diff --git a/messageviewer/src/dkim-verify/dkimmanager.cpp b/messageviewer/src/dkim-verify/dkimmanager.cpp index ebc9545d..69172bc2 100644 --- a/messageviewer/src/dkim-verify/dkimmanager.cpp +++ b/messageviewer/src/dkim-verify/dkimmanager.cpp @@ -1,123 +1,123 @@ /* 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 "dkimmanager.h" #include "messageviewer_dkimcheckerdebug.h" #include "dkimmanagerkey.h" #include "dkimresultattribute.h" #include "dkimstoreresultjob.h" #include "dkimcheckpolicyjob.h" #include "settings/messageviewersettings.h" #include using namespace MessageViewer; DKIMManager::DKIMManager(QObject *parent) : QObject(parent) { Akonadi::AttributeFactory::registerAttribute(); } DKIMManager::~DKIMManager() { } DKIMManager *DKIMManager::self() { static DKIMManager s_self; return &s_self; } void DKIMManager::checkDKim(const Akonadi::Item &item) { if (MessageViewer::MessageViewerSettings::self()->saveDkimResult()) { if (item.hasAttribute()) { const MessageViewer::DKIMResultAttribute *const attr = item.attribute(); if (attr) { DKIMCheckSignatureJob::CheckSignatureResult checkResult; checkResult.item = item; checkResult.error = static_cast(attr->error()); checkResult.warning = static_cast(attr->warning()); checkResult.status = static_cast(attr->status()); qCDebug(MESSAGEVIEWER_DKIMCHECKER_LOG) << "result : status " << checkResult.status << " error : " << checkResult.error << " warning " << checkResult.warning; Q_EMIT result(checkResult); return; } } } DKIMCheckSignatureJob *job = new DKIMCheckSignatureJob(this); connect(job, &DKIMCheckSignatureJob::storeKey, this, &DKIMManager::storeKey); connect(job, &DKIMCheckSignatureJob::result, this, &DKIMManager::slotCheckSignatureResult); job->setSaveKey(MessageViewer::MessageViewerSettings::self()->saveKey()); job->setItem(item); job->start(); } void DKIMManager::clearInfoWidget() { Q_EMIT clearInfo(); } void DKIMManager::checkDKim(const KMime::Message::Ptr &message) { DKIMCheckSignatureJob *job = new DKIMCheckSignatureJob(this); connect(job, &DKIMCheckSignatureJob::storeKey, this, &DKIMManager::storeKey); connect(job, &DKIMCheckSignatureJob::result, this, &DKIMManager::slotCheckSignatureResult); job->setSaveKey(MessageViewer::MessageViewerSettings::self()->saveKey()); job->setMessage(message); job->start(); } void DKIMManager::storeKey(const QString &key, const QString &domain, const QString &selector) { if (MessageViewer::MessageViewerSettings::self()->saveKey()) { const MessageViewer::KeyInfo info {key, selector, domain}; MessageViewer::DKIMManagerKey::self()->addKey(info); } } void DKIMManager::storeResult(const DKIMCheckSignatureJob::CheckSignatureResult &checkResult) { if (MessageViewer::MessageViewerSettings::self()->saveDkimResult()) { - if (checkResult.status == DKIMCheckSignatureJob::DKIMStatus::Valid || - checkResult.status == DKIMCheckSignatureJob::DKIMStatus::Invalid || - checkResult.status == DKIMCheckSignatureJob::DKIMStatus::NeedToBeSigned) { + if (checkResult.status == DKIMCheckSignatureJob::DKIMStatus::Valid + || checkResult.status == DKIMCheckSignatureJob::DKIMStatus::Invalid + || checkResult.status == DKIMCheckSignatureJob::DKIMStatus::NeedToBeSigned) { DKIMStoreResultJob *job = new DKIMStoreResultJob(this); job->setResult(checkResult); job->start(); } } qCDebug(MESSAGEVIEWER_DKIMCHECKER_LOG) << "result : status " << checkResult.status << " error : " << checkResult.error << " warning " << checkResult.warning; Q_EMIT result(checkResult); } void DKIMManager::slotCheckSignatureResult(const DKIMCheckSignatureJob::CheckSignatureResult &checkResult) { if (MessageViewer::MessageViewerSettings::self()->checkIfEmailShouldBeSigned()) { DKIMCheckPolicyJob *job = new DKIMCheckPolicyJob(this); connect(job, &DKIMCheckPolicyJob::result, this, &DKIMManager::storeResult); job->setCheckResult(checkResult); job->setEmailAddress(checkResult.fromEmail); if (!job->start()) { storeResult(checkResult); //TODO Store or not ? } } else { storeResult(checkResult); } } diff --git a/messageviewer/src/dkim-verify/dmarcpolicyjob.cpp b/messageviewer/src/dkim-verify/dmarcpolicyjob.cpp index a7909cb1..9d8b6d10 100644 --- a/messageviewer/src/dkim-verify/dmarcpolicyjob.cpp +++ b/messageviewer/src/dkim-verify/dmarcpolicyjob.cpp @@ -1,178 +1,178 @@ /* 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 "dmarcpolicyjob.h" #include "dmarcrecordjob.h" #include "dmarcinfo.h" #include "dkimutil.h" #include "messageviewer_dkimcheckerdebug.h" using namespace MessageViewer; DMARCPolicyJob::DMARCPolicyJob(QObject *parent) : QObject(parent) { } DMARCPolicyJob::~DMARCPolicyJob() { } bool DMARCPolicyJob::canStart() const { return !mEmailAddress.isEmpty(); } bool DMARCPolicyJob::start() { if (!canStart()) { qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << " Impossible to start DMARCPolicyJob" << mEmailAddress; Q_EMIT result({}); deleteLater(); return false; } const QString emailDomainStr = emailDomain(); DMARCRecordJob *job = new DMARCRecordJob(this); job->setDomainName(emailDomainStr); connect(job, &MessageViewer::DMARCRecordJob::success, this, &DMARCPolicyJob::slotCheckDomain); connect(job, &MessageViewer::DMARCRecordJob::error, this, [this](const QString &err, const QString &domainName) { qDebug() << "error: " << err << " domain " << domainName; //Verify subdomain ? checkSubDomain(domainName); }); if (!job->start()) { Q_EMIT result({}); deleteLater(); return false; } return true; } QByteArray DMARCPolicyJob::generateDMARCFromList(const QList &lst) const { QByteArray ba; if (lst.count() != 1) { for (const QByteArray &b : lst) { ba += b; } qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "DMARCPolicyJob Key result has more that 1 element" << lst; } else { ba = lst.at(0); } return ba; } void DMARCPolicyJob::slotCheckSubDomain(const QList &lst, const QString &domainName) { const QByteArray ba = generateDMARCFromList(lst); DMARCInfo info; if (info.parseDMARC(QString::fromLocal8Bit(ba))) { - if ((info.version() != QLatin1String("DMARC1")) || info.policy().isEmpty() || (info.percentage() > 100 || info.percentage() < 0)) { + if ((info.version() != QLatin1String("DMARC1")) || info.policy().isEmpty() || (info.percentage() > 100 || info.percentage() < 0)) { Q_EMIT result({}); deleteLater(); return; } else { DMARCPolicyJob::DMARCResult val; val.mAdkim = info.adkim(); val.mPercentage = info.percentage(); val.mPolicy = info.subDomainPolicy().isEmpty() ? info.policy() : info.subDomainPolicy(); //TODO verify it ! val.mDomain = domainName; val.mSource = domainName; Q_EMIT result(val); deleteLater(); return; } } Q_EMIT result(DMARCResult()); } void DMARCPolicyJob::checkSubDomain(const QString &domainName) { const QString subDomain = emailSubDomain(domainName); if (subDomain != domainName) { DMARCRecordJob *job = new DMARCRecordJob(this); job->setDomainName(subDomain); connect(job, &MessageViewer::DMARCRecordJob::success, this, &DMARCPolicyJob::slotCheckSubDomain); connect(job, &MessageViewer::DMARCRecordJob::error, this, [this](const QString &err, const QString &domainName) { qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "error: " << err << " domain " << domainName; Q_EMIT result({}); deleteLater(); }); if (!job->start()) { deleteLater(); Q_EMIT result({}); return; } } else { //Invalid Q_EMIT result({}); deleteLater(); return; } } void DMARCPolicyJob::slotCheckDomain(const QList &lst, const QString &domainName) { const QByteArray ba = generateDMARCFromList(lst); DMARCInfo info; if (info.parseDMARC(QString::fromLocal8Bit(ba))) { - if ((info.version() != QLatin1String("DMARC1")) || info.policy().isEmpty() - || (info.percentage() != -1 && (info.percentage() > 100 || info.percentage() < 0))) { + if ((info.version() != QLatin1String("DMARC1")) || info.policy().isEmpty() + || (info.percentage() != -1 && (info.percentage() > 100 || info.percentage() < 0))) { //Invalid //Check subdomain checkSubDomain(domainName); } else { DMARCPolicyJob::DMARCResult val; val.mAdkim = info.adkim(); val.mPercentage = info.percentage(); val.mPolicy = info.policy(); val.mDomain = domainName; val.mSource = domainName; Q_EMIT result(val); deleteLater(); return; } } else { //Check subdomain checkSubDomain(domainName); } qDebug() << "domainName: " << domainName << " lst " << lst; //Parse result } QString DMARCPolicyJob::emailDomain() const { return MessageViewer::DKIMUtil::emailDomain(mEmailAddress); } QString DMARCPolicyJob::emailSubDomain(const QString &domainName) const { return MessageViewer::DKIMUtil::emailSubDomain(domainName); } QString DMARCPolicyJob::emailAddress() const { return mEmailAddress; } void DMARCPolicyJob::setEmailAddress(const QString &emailAddress) { mEmailAddress = emailAddress; } diff --git a/messageviewer/src/dkim-verify/dmarcpolicyjob.h b/messageviewer/src/dkim-verify/dmarcpolicyjob.h index 71b9f219..150a99cb 100644 --- a/messageviewer/src/dkim-verify/dmarcpolicyjob.h +++ b/messageviewer/src/dkim-verify/dmarcpolicyjob.h @@ -1,74 +1,76 @@ /* 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. */ #ifndef DMARCPOLICYJOB_H #define DMARCPOLICYJOB_H #include #include "dmarcinfo.h" #include "messageviewer_private_export.h" namespace MessageViewer { class MESSAGEVIEWER_TESTS_EXPORT DMARCPolicyJob : public QObject { Q_OBJECT public: struct DMARCResult { - bool isValid() const { + bool isValid() const + { return !mAdkim.isEmpty() && !mPolicy.isEmpty() && !mDomain.isEmpty() && !mSource.isEmpty() && (mPercentage != -1); } + Q_REQUIRED_RESULT bool operator==(const DMARCPolicyJob::DMARCResult &other) const { return mAdkim == other.mAdkim && mPolicy == other.mPolicy && mDomain == other.mDomain && mSource == other.mSource && mPercentage == other.mPercentage; } Q_REQUIRED_RESULT bool operator!=(const DMARCPolicyJob::DMARCResult &other) const { return !DMARCResult::operator==(other); } + QString mAdkim; QString mPolicy; QString mDomain; QString mSource; int mPercentage = -1; }; - explicit DMARCPolicyJob(QObject *parent = nullptr); ~DMARCPolicyJob(); Q_REQUIRED_RESULT bool canStart() const; Q_REQUIRED_RESULT bool start(); Q_REQUIRED_RESULT QString emailAddress() const; void setEmailAddress(const QString &emailAddress); Q_SIGNALS: void result(const MessageViewer::DMARCPolicyJob::DMARCResult &value); private: void checkSubDomain(const QString &domainName); void slotCheckDomain(const QList &lst, const QString &domainName); void slotCheckSubDomain(const QList &lst, const QString &domainName); Q_REQUIRED_RESULT QByteArray generateDMARCFromList(const QList &lst) const; Q_REQUIRED_RESULT QString emailDomain() const; Q_REQUIRED_RESULT QString emailSubDomain(const QString &domainName) const; QString mEmailAddress; }; } #endif // DMARCPOLICYJOB_H