diff --git a/messageviewer/src/dkim-verify/dkimcheckpolicyjob.cpp b/messageviewer/src/dkim-verify/dkimcheckpolicyjob.cpp index 57e1a9b4..08c743f4 100644 --- a/messageviewer/src/dkim-verify/dkimcheckpolicyjob.cpp +++ b/messageviewer/src/dkim-verify/dkimcheckpolicyjob.cpp @@ -1,143 +1,145 @@ /* 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 "dkim-verify/dkimmanagerrules.h" #include "settings/messageviewersettings.h" #include "messageviewer_dkimcheckerdebug.h" using namespace MessageViewer; DKIMCheckPolicyJob::DKIMCheckPolicyJob(QObject *parent) : QObject(parent) { } DKIMCheckPolicyJob::~DKIMCheckPolicyJob() { } bool DKIMCheckPolicyJob::canStart() const { 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 (mPolicy.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 { if (mPolicy.useDefaultRules()) { compareWithDefaultRules(); } else { Q_EMIT result(mCheckResult); deleteLater(); } } return true; } void DKIMCheckPolicyJob::compareWithDefaultRules() { const QVector rules = DKIMManagerRules::self()->rules(); for (const DKIMRule &rule : rules) { if (rule.enabled()) { if (rule.from() == mEmailAddress || rule.from() == QLatin1Char('*')) { //Check SDID - if (mCheckResult.signedBy == rule.domain()) { - switch (rule.ruleType()) { - case DKIMRule::RuleType::Unknown: - // Invalid rule ! - qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "Invalid rule found " << rule; - break; - case DKIMRule::RuleType::MustBeSigned: - mCheckResult.status = DKIMCheckSignatureJob::DKIMStatus::NeedToBeSigned; - break; - case DKIMRule::RuleType::CanBeSigned: - //Show a warning ? - break; - case DKIMRule::RuleType::IgnoreEmailNotSigned: - //Nothing ! + for (const QString &ssid : rule.signedDomainIdentifier()) { + if (mCheckResult.signedBy == ssid) { + switch (rule.ruleType()) { + case DKIMRule::RuleType::Unknown: + // Invalid rule ! + qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "Invalid rule found " << rule; + break; + case DKIMRule::RuleType::MustBeSigned: + mCheckResult.status = DKIMCheckSignatureJob::DKIMStatus::NeedToBeSigned; + break; + case DKIMRule::RuleType::CanBeSigned: + //Show a warning ? + break; + case DKIMRule::RuleType::IgnoreEmailNotSigned: + //Nothing ! + break; + } break; } - break; } } } } Q_EMIT result(mCheckResult); deleteLater(); } void DKIMCheckPolicyJob::dmarcPolicyResult(const MessageViewer::DMARCPolicyJob::DMARCResult &value) { if (value.isValid()) { if (mCheckResult.status == DKIMCheckSignatureJob::DKIMStatus::EmailNotSigned) { mCheckResult.status = DKIMCheckSignatureJob::DKIMStatus::NeedToBeSigned; //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. */ #include "dkimgeneraterulejob.h" #include "dkimmanagerrules.h" #include "messageviewer_debug.h" using namespace MessageViewer; DKIMGenerateRuleJob::DKIMGenerateRuleJob(QObject *parent) : QObject(parent) { } DKIMGenerateRuleJob::~DKIMGenerateRuleJob() { } bool DKIMGenerateRuleJob::canStart() const { if (!mResult.isValid()) { qCWarning(MESSAGEVIEWER_LOG) << "Rule is not valid"; return false; } return true; } bool DKIMGenerateRuleJob::start() { if (!canStart()) { deleteLater(); qCWarning(MESSAGEVIEWER_LOG) << "Impossible to start DKIMGenerateRuleJob"; return false; } verifyAndGenerateRule(); return true; } void DKIMGenerateRuleJob::verifyAndGenerateRule() { DKIMRule rule; rule.setEnabled(true); rule.setFrom(mResult.fromEmail); - rule.setDomain(mResult.signedBy); //TODO verify ? - //rule.setListId(); - rule.setSignedDomainIdentifier(QStringList() << mResult.signedBy); //TODO verify + //rule.setDomain(mResult.signedBy); //TODO verify ? + rule.setSignedDomainIdentifier(QStringList() << mResult.signedBy); rule.setRuleType(DKIMRule::RuleType::MustBeSigned); deleteLater(); } DKIMCheckSignatureJob::CheckSignatureResult DKIMGenerateRuleJob::result() const { return mResult; } void DKIMGenerateRuleJob::setResult(const DKIMCheckSignatureJob::CheckSignatureResult &checkResult) { mResult = checkResult; }