File indexing completed on 2024-05-12 05:11:11

0001 /*
0002     SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "outboxactions_p.h"
0008 
0009 #include "akonadi_mime_debug.h"
0010 #include "dispatchmodeattribute.h"
0011 #include "errorattribute.h"
0012 
0013 #include <Akonadi/ItemModifyJob>
0014 #include <Akonadi/MessageFlags>
0015 
0016 using namespace Akonadi;
0017 
0018 SendQueuedAction::SendQueuedAction() = default;
0019 
0020 SendQueuedAction::~SendQueuedAction() = default;
0021 
0022 ItemFetchScope SendQueuedAction::fetchScope() const
0023 {
0024     ItemFetchScope scope;
0025     scope.fetchFullPayload(false);
0026     scope.fetchAttribute<DispatchModeAttribute>();
0027     scope.fetchAttribute<ErrorAttribute>();
0028     scope.setCacheOnly(true);
0029     return scope;
0030 }
0031 
0032 bool SendQueuedAction::itemAccepted(const Item &item) const
0033 {
0034     if (!item.hasAttribute<DispatchModeAttribute>()) {
0035         qCWarning(AKONADIMIME_LOG) << "Item doesn't have DispatchModeAttribute.";
0036         return false;
0037     }
0038 
0039     return item.attribute<DispatchModeAttribute>()->dispatchMode() == DispatchModeAttribute::Manual;
0040 }
0041 
0042 Job *SendQueuedAction::itemAction(const Item &item, FilterActionJob *parent) const
0043 {
0044     Item cp = item;
0045     cp.addAttribute(new DispatchModeAttribute); // defaults to Automatic
0046     if (cp.hasAttribute<ErrorAttribute>()) {
0047         cp.removeAttribute<ErrorAttribute>();
0048         cp.clearFlag(Akonadi::MessageFlags::HasError);
0049     }
0050     return new ItemModifyJob(cp, parent);
0051 }
0052 
0053 ClearErrorAction::ClearErrorAction() = default;
0054 
0055 ClearErrorAction::~ClearErrorAction() = default;
0056 
0057 ItemFetchScope ClearErrorAction::fetchScope() const
0058 {
0059     ItemFetchScope scope;
0060     scope.fetchFullPayload(false);
0061     scope.fetchAttribute<ErrorAttribute>();
0062     scope.setCacheOnly(true);
0063     return scope;
0064 }
0065 
0066 bool ClearErrorAction::itemAccepted(const Item &item) const
0067 {
0068     return item.hasAttribute<ErrorAttribute>();
0069 }
0070 
0071 Job *ClearErrorAction::itemAction(const Item &item, FilterActionJob *parent) const
0072 {
0073     Item cp = item;
0074     cp.removeAttribute<ErrorAttribute>();
0075     cp.clearFlag(Akonadi::MessageFlags::HasError);
0076     cp.setFlag(Akonadi::MessageFlags::Queued);
0077     return new ItemModifyJob(cp, parent);
0078 }
0079 
0080 DispatchManualTransportAction::DispatchManualTransportAction(int transportId)
0081     : mTransportId(transportId)
0082 {
0083 }
0084 
0085 DispatchManualTransportAction::~DispatchManualTransportAction() = default;
0086 
0087 ItemFetchScope DispatchManualTransportAction::fetchScope() const
0088 {
0089     ItemFetchScope scope;
0090     scope.fetchFullPayload(false);
0091     scope.fetchAttribute<TransportAttribute>();
0092     scope.fetchAttribute<DispatchModeAttribute>();
0093     scope.setCacheOnly(true);
0094     return scope;
0095 }
0096 
0097 bool DispatchManualTransportAction::itemAccepted(const Item &item) const
0098 {
0099     if (!item.hasAttribute<DispatchModeAttribute>()) {
0100         qCWarning(AKONADIMIME_LOG) << "Item doesn't have DispatchModeAttribute.";
0101         return false;
0102     }
0103 
0104     if (!item.hasAttribute<TransportAttribute>()) {
0105         qCWarning(AKONADIMIME_LOG) << "Item doesn't have TransportAttribute.";
0106         return false;
0107     }
0108 
0109     return item.attribute<DispatchModeAttribute>()->dispatchMode() == DispatchModeAttribute::Manual;
0110 }
0111 
0112 Job *DispatchManualTransportAction::itemAction(const Item &item, FilterActionJob *parent) const
0113 {
0114     Item cp = item;
0115     cp.attribute<TransportAttribute>()->setTransportId(mTransportId);
0116     cp.removeAttribute<DispatchModeAttribute>();
0117     cp.addAttribute(new DispatchModeAttribute); // defaults to Automatic
0118     cp.setFlag(Akonadi::MessageFlags::Queued);
0119     return new ItemModifyJob(cp, parent);
0120 }