File indexing completed on 2025-03-09 04:54:31

0001 /*
0002    SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "dkimstoreresultjob.h"
0008 #include "dkimresultattribute.h"
0009 #include "messageviewer_dkimcheckerdebug.h"
0010 #include <Akonadi/ItemModifyJob>
0011 
0012 using namespace MessageViewer;
0013 DKIMStoreResultJob::DKIMStoreResultJob(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 DKIMStoreResultJob::~DKIMStoreResultJob() = default;
0019 
0020 void DKIMStoreResultJob::start()
0021 {
0022     if (!canStart()) {
0023         qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "Impossible to store dkim result";
0024         deleteLater();
0025         return;
0026     }
0027     auto attr = mItem.attribute<MessageViewer::DKIMResultAttribute>(Akonadi::Item::AddIfMissing);
0028     attr->setError(static_cast<int>(mResult.error));
0029     attr->setWarning(static_cast<int>(mResult.warning));
0030     attr->setStatus(static_cast<int>(mResult.status));
0031     auto modify = new Akonadi::ItemModifyJob(mItem);
0032     modify->setIgnorePayload(true);
0033     modify->disableRevisionCheck();
0034     connect(modify, &KJob::result, this, &DKIMStoreResultJob::slotModifyItemDone);
0035 }
0036 
0037 void DKIMStoreResultJob::slotModifyItemDone(KJob *job)
0038 {
0039     if (job->error()) {
0040         qCDebug(MESSAGEVIEWER_DKIMCHECKER_LOG) << "DKIMStoreResultJob: modify item failed " << job->errorString();
0041     }
0042     deleteLater();
0043 }
0044 
0045 bool DKIMStoreResultJob::canStart() const
0046 {
0047     if (mItem.isValid() && mResult.isValid()) {
0048         return true;
0049     }
0050     return false;
0051 }
0052 
0053 void DKIMStoreResultJob::setResult(const DKIMCheckSignatureJob::CheckSignatureResult &checkResult)
0054 {
0055     mResult = checkResult;
0056 }
0057 
0058 void DKIMStoreResultJob::setItem(const Akonadi::Item &item)
0059 {
0060     mItem = item;
0061 }
0062 
0063 #include "moc_dkimstoreresultjob.cpp"