Messagelib

dkimmanager.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 "dkimmanager.h"
8#include "dkimcheckfulljob.h"
9#include "dkimmanagerkey.h"
10#include "dkimresultattribute.h"
11#include "messageviewer_dkimcheckerdebug.h"
12#include <Akonadi/AttributeFactory>
13
14using namespace MessageViewer;
15DKIMManager::DKIMManager(QObject *parent)
16 : QObject(parent)
17{
18 // Initialize QCA
19 MessageViewer::DKIMManagerKey::self();
20 Akonadi::AttributeFactory::registerAttribute<MessageViewer::DKIMResultAttribute>();
21}
22
23DKIMManager::~DKIMManager() = default;
24
25DKIMManager *DKIMManager::self()
26{
27 static DKIMManager s_self;
28 return &s_self;
29}
30
31void DKIMManager::clearInfoWidget()
32{
33 Q_EMIT clearInfo();
34}
35
36DKIMCheckPolicy DKIMManager::policy() const
37{
38 return mCheckPolicy;
39}
40
41void DKIMManager::setPolicy(const DKIMCheckPolicy &policy)
42{
43 mCheckPolicy = policy;
44}
45
46void DKIMManager::recheckDKim(const Akonadi::Item &item)
47{
48 checkFullInfo(item);
49}
50
51void DKIMManager::checkDKim(const Akonadi::Item &item)
52{
53 if (mCheckPolicy.saveDkimResult()) {
54 if (item.hasAttribute<MessageViewer::DKIMResultAttribute>()) {
55 const auto *const attr = item.attribute<MessageViewer::DKIMResultAttribute>();
56 if (attr) {
57 DKIMCheckSignatureJob::CheckSignatureResult checkResult;
58 checkResult.error = static_cast<DKIMCheckSignatureJob::DKIMError>(attr->error());
59 checkResult.warning = static_cast<DKIMCheckSignatureJob::DKIMWarning>(attr->warning());
60 checkResult.status = static_cast<DKIMCheckSignatureJob::DKIMStatus>(attr->status());
62 << "result : status " << checkResult.status << " error : " << checkResult.error << " warning " << checkResult.warning;
63 Q_EMIT result(checkResult, item.id());
64 return;
65 }
66 }
67 }
68 checkFullInfo(item);
69}
70
71void DKIMManager::checkFullInfo(const Akonadi::Item &item)
72{
73 auto job = new DKIMCheckFullJob(this);
74 job->setPolicy(mCheckPolicy);
75 connect(job, &DKIMCheckFullJob::result, this, &DKIMManager::result);
76 job->startCheckFullInfo(item);
77}
78
79void DKIMManager::checkDKim(const KMime::Message::Ptr &message)
80{
81 auto job = new DKIMCheckFullJob(this);
82 job->setPolicy(mCheckPolicy);
83 connect(job, &DKIMCheckFullJob::result, this, &DKIMManager::result);
84 job->startCheckFullInfo(message);
85}
86
87#include "moc_dkimmanager.cpp"
bool hasAttribute() const
Id id() const
const T * attribute() const
The DKIMCheckPolicy class.
The DKIMManager class.
Definition dkimmanager.h:22
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:49:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.