Messagelib

dmarcrecordjob.cpp
1/*
2 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "dmarcrecordjob.h"
8#include "messageviewer_dkimcheckerdebug.h"
9
10#include <QDnsLookup>
11
12using namespace MessageViewer;
13// see https://tools.ietf.org/html/rfc7489
14DMARCRecordJob::DMARCRecordJob(QObject *parent)
15 : QObject(parent)
16{
17}
18
19DMARCRecordJob::~DMARCRecordJob() = default;
20
21bool DMARCRecordJob::start()
22{
23 if (!canStart()) {
24 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "Impossible to start download dmarc key.";
26 return false;
27 }
28 mDnsLookup = new QDnsLookup(this);
29 connect(mDnsLookup, &QDnsLookup::finished, this, &DMARCRecordJob::resolvDnsDone);
30
31 mDnsLookup->setType(QDnsLookup::TXT);
32 mDnsLookup->setName(resolvDnsValue());
33 mDnsLookup->lookup();
34 return true;
35}
36
37QString DMARCRecordJob::resolvDnsValue() const
38{
39 const QString name = QLatin1StringView("_dmarc.") + mDomainName;
40 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "DMARCRecordJob::resolvDnsValue" << name;
41 return name;
42}
43
44void DMARCRecordJob::resolvDnsDone()
45{
46 // Check the lookup succeeded.
47 if (mDnsLookup->error() != QDnsLookup::NoError) {
48 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "Error during resolving: " << mDnsLookup->errorString() << " mDnsLookup->error() " << mDnsLookup->error();
49 Q_EMIT error(mDnsLookup->errorString(), mDomainName);
51 return;
52 }
53
54 // Handle the results.
55 const auto records = mDnsLookup->textRecords();
56 QList<QByteArray> textRecordResult;
57 textRecordResult.reserve(records.count());
58 for (const QDnsTextRecord &record : records) {
59 textRecordResult << record.values();
60 }
61
62 Q_EMIT success(textRecordResult, mDomainName);
64}
65
66bool DMARCRecordJob::canStart() const
67{
68 return !mDomainName.isEmpty();
69}
70
71QString DMARCRecordJob::domainName() const
72{
73 return mDomainName;
74}
75
76void DMARCRecordJob::setDomainName(const QString &domainName)
77{
78 mDomainName = domainName;
79}
80
81#include "moc_dmarcrecordjob.cpp"
QString name(GameStandardAction id)
void finished()
void lookup()
void setName(const QString &name)
QList< QDnsTextRecord > textRecords() const const
void setType(QDnsLookup::Type)
void reserve(qsizetype size)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.