7#include "dmarcpolicyjob.h"
10#include "dmarcrecordjob.h"
11#include "messageviewer_dkimcheckerdebug.h"
12using namespace MessageViewer;
14DMARCPolicyJob::DMARCPolicyJob(
QObject *parent)
19DMARCPolicyJob::~DMARCPolicyJob() =
default;
21bool DMARCPolicyJob::canStart()
const
23 return !mEmailAddress.
isEmpty();
26bool DMARCPolicyJob::start()
29 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
" Impossible to start DMARCPolicyJob" << mEmailAddress;
30 Q_EMIT result({}, mEmailAddress);
35 auto job =
new DMARCRecordJob(
this);
36 job->setDomainName(emailDomain());
37 connect(job, &MessageViewer::DMARCRecordJob::success,
this, &DMARCPolicyJob::slotCheckDomain);
38 connect(job, &MessageViewer::DMARCRecordJob::error,
this, [
this](
const QString &err,
const QString &domainName) {
39 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
"error: " << err <<
" domain " << domainName;
41 checkSubDomain(domainName);
44 Q_EMIT result({}, mEmailAddress);
54 if (lst.
count() != 1) {
58 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
"DMARCPolicyJob Key result has more that 1 element" << lst;
67 const QByteArray ba = generateDMARCFromList(lst);
70 if ((info.version() !=
QLatin1StringView(
"DMARC1")) || info.policy().
isEmpty() || (info.percentage() > 100 || info.percentage() < 0)) {
71 Q_EMIT result({}, mEmailAddress);
75 DMARCPolicyJob::DMARCResult val;
76 val.mAdkim = info.adkim();
77 val.mPercentage = info.percentage();
78 val.mPolicy = info.subDomainPolicy().
isEmpty() ? info.policy() : info.subDomainPolicy();
80 val.mDomain = domainName;
81 val.mSource = domainName;
82 Q_EMIT result(val, mEmailAddress);
87 Q_EMIT result({}, mEmailAddress);
90void DMARCPolicyJob::checkSubDomain(
const QString &domainName)
92 const QString subDomain = emailSubDomain(domainName);
93 if (subDomain != domainName) {
94 auto job =
new DMARCRecordJob(
this);
95 job->setDomainName(subDomain);
96 connect(job, &MessageViewer::DMARCRecordJob::success,
this, &DMARCPolicyJob::slotCheckSubDomain);
97 connect(job, &MessageViewer::DMARCRecordJob::error,
this, [
this](
const QString &err,
const QString &domainName) {
98 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
"error: " << err <<
" domain " << domainName;
99 Q_EMIT result({}, mEmailAddress);
103 Q_EMIT result({}, mEmailAddress);
109 Q_EMIT result({}, mEmailAddress);
117 const QByteArray ba = generateDMARCFromList(lst);
121 || (info.percentage() != -1 && (info.percentage() > 100 || info.percentage() < 0))) {
124 checkSubDomain(domainName);
126 DMARCPolicyJob::DMARCResult val;
127 val.mAdkim = info.adkim();
128 val.mPercentage = info.percentage();
129 val.mPolicy = info.policy();
130 val.mDomain = domainName;
131 val.mSource = domainName;
132 Q_EMIT result(val, mEmailAddress);
138 checkSubDomain(domainName);
142QString DMARCPolicyJob::emailDomain()
const
144 return MessageViewer::DKIMUtil::emailDomain(mEmailAddress);
147QString DMARCPolicyJob::emailSubDomain(
const QString &domainName)
const
149 return MessageViewer::DKIMUtil::emailSubDomain(domainName);
152QString DMARCPolicyJob::emailAddress()
const
154 return mEmailAddress;
157void DMARCPolicyJob::setEmailAddress(
const QString &emailAddress)
159 mEmailAddress = emailAddress;
162#include "moc_dmarcpolicyjob.cpp"
const_reference at(qsizetype i) const const
qsizetype count() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString fromLocal8Bit(QByteArrayView str)
bool isEmpty() const const