Messagelib

dkimstoreresultjob.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 "dkimstoreresultjob.h"
8 #include "dkimresultattribute.h"
9 #include "messageviewer_dkimcheckerdebug.h"
10 #include <Akonadi/ItemModifyJob>
11 
12 using namespace MessageViewer;
13 DKIMStoreResultJob::DKIMStoreResultJob(QObject *parent)
14  : QObject(parent)
15 {
16 }
17 
18 DKIMStoreResultJob::~DKIMStoreResultJob() = default;
19 
20 void DKIMStoreResultJob::start()
21 {
22  if (!canStart()) {
23  qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "Impossible to store dkim result";
24  deleteLater();
25  return;
26  }
27  auto attr = mItem.attribute<MessageViewer::DKIMResultAttribute>(Akonadi::Item::AddIfMissing);
28  attr->setError(static_cast<int>(mResult.error));
29  attr->setWarning(static_cast<int>(mResult.warning));
30  attr->setStatus(static_cast<int>(mResult.status));
31  auto modify = new Akonadi::ItemModifyJob(mItem);
32  modify->setIgnorePayload(true);
33  modify->disableRevisionCheck();
34  connect(modify, &KJob::result, this, &DKIMStoreResultJob::slotModifyItemDone);
35 }
36 
37 void DKIMStoreResultJob::slotModifyItemDone(KJob *job)
38 {
39  if (job->error()) {
40  qCDebug(MESSAGEVIEWER_DKIMCHECKER_LOG) << "DKIMStoreResultJob: modify item failed " << job->errorString();
41  }
42  deleteLater();
43 }
44 
45 bool DKIMStoreResultJob::canStart() const
46 {
47  if (mItem.isValid() && mResult.isValid()) {
48  return true;
49  }
50  return false;
51 }
52 
53 void DKIMStoreResultJob::setResult(const DKIMCheckSignatureJob::CheckSignatureResult &checkResult)
54 {
55  mResult = checkResult;
56 }
57 
58 void DKIMStoreResultJob::setItem(const Akonadi::Item &item)
59 {
60  mItem = item;
61 }
virtual QString errorString() const
void result(KJob *job)
int error() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Dec 4 2021 23:12:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.