Messagelib

dkimmanager.cpp
1 /*
2  SPDX-FileCopyrightText: 2019-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "dkimmanager.h"
8 #include "dkimcheckfulljob.h"
9 #include "dkimmanagerkey.h"
10 #include "dkimresultattribute.h"
11 #include "messageviewer_dkimcheckerdebug.h"
12 #include "settings/messageviewersettings.h"
13 #include <Akonadi/AttributeFactory>
14 
15 using namespace MessageViewer;
16 DKIMManager::DKIMManager(QObject *parent)
17  : QObject(parent)
18 {
19  // Initialize QCA
20  MessageViewer::DKIMManagerKey::self();
21  Akonadi::AttributeFactory::registerAttribute<MessageViewer::DKIMResultAttribute>();
22 }
23 
24 DKIMManager::~DKIMManager() = default;
25 
26 DKIMManager *DKIMManager::self()
27 {
28  static DKIMManager s_self;
29  return &s_self;
30 }
31 
32 void DKIMManager::clearInfoWidget()
33 {
34  Q_EMIT clearInfo();
35 }
36 
37 DKIMCheckPolicy DKIMManager::policy() const
38 {
39  return mCheckPolicy;
40 }
41 
42 void DKIMManager::setPolicy(const DKIMCheckPolicy &policy)
43 {
44  mCheckPolicy = policy;
45 }
46 
47 void DKIMManager::recheckDKim(const Akonadi::Item &item)
48 {
49  checkFullInfo(item);
50 }
51 
52 void DKIMManager::checkDKim(const Akonadi::Item &item)
53 {
54  if (mCheckPolicy.saveDkimResult()) {
55  if (item.hasAttribute<MessageViewer::DKIMResultAttribute>()) {
56  const auto *const attr = item.attribute<MessageViewer::DKIMResultAttribute>();
57  if (attr) {
58  DKIMCheckSignatureJob::CheckSignatureResult checkResult;
59  checkResult.error = static_cast<DKIMCheckSignatureJob::DKIMError>(attr->error());
60  checkResult.warning = static_cast<DKIMCheckSignatureJob::DKIMWarning>(attr->warning());
61  checkResult.status = static_cast<DKIMCheckSignatureJob::DKIMStatus>(attr->status());
62  qCDebug(MESSAGEVIEWER_DKIMCHECKER_LOG)
63  << "result : status " << checkResult.status << " error : " << checkResult.error << " warning " << checkResult.warning;
64  Q_EMIT result(checkResult, item.id());
65  return;
66  }
67  }
68  }
69  checkFullInfo(item);
70 }
71 
72 void DKIMManager::checkFullInfo(const Akonadi::Item &item)
73 {
74  auto job = new DKIMCheckFullJob(this);
75  job->setPolicy(mCheckPolicy);
76  connect(job, &DKIMCheckFullJob::result, this, &DKIMManager::result);
77  job->startCheckFullInfo(item);
78 }
79 
80 void DKIMManager::checkDKim(const KMime::Message::Ptr &message)
81 {
82  auto job = new DKIMCheckFullJob(this);
83  job->setPolicy(mCheckPolicy);
84  connect(job, &DKIMCheckFullJob::result, this, &DKIMManager::result);
85  job->startCheckFullInfo(message);
86 }
Id id() const
Attribute * attribute(const QByteArray &name)
The DKIMManager class.
Definition: dkimmanager.h:21
The DKIMCheckPolicy class.
bool hasAttribute(const QByteArray &name) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Nov 30 2021 23:05:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.