Messagelib

dkimdownloadkeyjob.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 "dkimdownloadkeyjob.h"
8#include "messageviewer_dkimcheckerdebug.h"
9
10#include <QDnsLookup>
11using namespace MessageViewer;
12DKIMDownloadKeyJob::DKIMDownloadKeyJob(QObject *parent)
13 : QObject(parent)
14{
15}
16
17DKIMDownloadKeyJob::~DKIMDownloadKeyJob() = default;
18
19bool DKIMDownloadKeyJob::start()
20{
21 if (!canStart()) {
22 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "Impossible to start download public keys";
24 return false;
25 }
26 mDnsLookup = new QDnsLookup(this);
27 connect(mDnsLookup, &QDnsLookup::finished, this, &DKIMDownloadKeyJob::resolvDnsDone);
28
29 mDnsLookup->setType(QDnsLookup::TXT);
30 mDnsLookup->setName(resolvDnsValue());
31 mDnsLookup->lookup();
32 return true;
33}
34
35bool DKIMDownloadKeyJob::canStart() const
36{
37 return !mDomainName.isEmpty() && !mSelectorName.isEmpty();
38}
39
40QString DKIMDownloadKeyJob::domainName() const
41{
42 return mDomainName;
43}
44
45void DKIMDownloadKeyJob::setDomainName(const QString &domainName)
46{
47 mDomainName = domainName;
48}
49
50QString DKIMDownloadKeyJob::selectorName() const
51{
52 return mSelectorName;
53}
54
55void DKIMDownloadKeyJob::setSelectorName(const QString &selectorName)
56{
57 mSelectorName = selectorName;
58}
59
60QString DKIMDownloadKeyJob::resolvDnsValue() const
61{
62 const QString name = mSelectorName + QLatin1StringView("._domainkey.") + mDomainName;
63 qDebug(MESSAGEVIEWER_DKIMCHECKER_LOG) << "DKIMDownloadKeyJob::resolvDnsValue" << name;
64 return name;
65}
66
67QDnsLookup *DKIMDownloadKeyJob::dnsLookup() const
68{
69 return mDnsLookup;
70}
71
72void DKIMDownloadKeyJob::resolvDnsDone()
73{
74 // Check the lookup succeeded.
75 if (mDnsLookup->error() != QDnsLookup::NoError) {
76 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "Error during resolving: " << mDnsLookup->errorString();
77 Q_EMIT error(mDnsLookup->errorString());
79 return;
80 }
81
82 // Handle the results.
83 const auto records = mDnsLookup->textRecords();
84 QList<QByteArray> textRecordResult;
85 textRecordResult.reserve(records.count());
86 for (const QDnsTextRecord &record : records) {
87 textRecordResult << record.values();
88 }
89
90 Q_EMIT success(textRecordResult, mDomainName, mSelectorName);
92}
93
94#include "moc_dkimdownloadkeyjob.cpp"
QString name(StandardAction 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 Sat Dec 21 2024 16:59:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.