Messagelib

dkimdownloadkeyjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2019-2023 Laurent Montel <[email protected]>
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>
11 using namespace MessageViewer;
12 DKIMDownloadKeyJob::DKIMDownloadKeyJob(QObject *parent)
13  : QObject(parent)
14 {
15 }
16 
17 DKIMDownloadKeyJob::~DKIMDownloadKeyJob() = default;
18 
19 bool DKIMDownloadKeyJob::start()
20 {
21  if (!canStart()) {
22  qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "Impossible to start download public keys";
23  deleteLater();
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 
35 bool DKIMDownloadKeyJob::canStart() const
36 {
37  return !mDomainName.isEmpty() && !mSelectorName.isEmpty();
38 }
39 
40 QString DKIMDownloadKeyJob::domainName() const
41 {
42  return mDomainName;
43 }
44 
45 void DKIMDownloadKeyJob::setDomainName(const QString &domainName)
46 {
47  mDomainName = domainName;
48 }
49 
50 QString DKIMDownloadKeyJob::selectorName() const
51 {
52  return mSelectorName;
53 }
54 
55 void DKIMDownloadKeyJob::setSelectorName(const QString &selectorName)
56 {
57  mSelectorName = selectorName;
58 }
59 
60 QString DKIMDownloadKeyJob::resolvDnsValue() const
61 {
62  const QString name = mSelectorName + QLatin1String("._domainkey.") + mDomainName;
63  qDebug(MESSAGEVIEWER_DKIMCHECKER_LOG) << "DKIMDownloadKeyJob::resolvDnsValue" << name;
64  return name;
65 }
66 
67 QDnsLookup *DKIMDownloadKeyJob::dnsLookup() const
68 {
69  return mDnsLookup;
70 }
71 
72 void 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());
78  deleteLater();
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);
91  deleteLater();
92 }
93 
94 #include "moc_dkimdownloadkeyjob.cpp"
Q_EMITQ_EMIT
void lookup()
void setName(const QString &name)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void reserve(int alloc)
void finished()
void deleteLater()
QList< QDnsTextRecord > textRecords() const const
bool isEmpty() const const
void setType(QDnsLookup::Type)
const char * name(StandardAction id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Oct 1 2023 03:53:34 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.