1/*
2 Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "outboxactions_p.h"
21
22#include "dispatchmodeattribute.h"
23#include "errorattribute.h"
24
25#include <akonadi/itemmodifyjob.h>
26#include <akonadi/kmime/messageflags.h>
27
28using namespace Akonadi;
29using namespace MailTransport;
30
31class MailTransport::SendQueuedAction::Private
32{
33};
34
35SendQueuedAction::SendQueuedAction()
36 : d( new Private )
37{
38}
39
40SendQueuedAction::~SendQueuedAction()
41{
42 delete d;
43}
44
45ItemFetchScope SendQueuedAction::fetchScope() const
46{
47 ItemFetchScope scope;
48 scope.fetchFullPayload( false );
49 scope.fetchAttribute<DispatchModeAttribute>();
50 scope.fetchAttribute<ErrorAttribute>();
51 scope.setCacheOnly( true );
52 return scope;
53}
54
55bool SendQueuedAction::itemAccepted( const Item &item ) const
56{
57 if ( !item.hasAttribute<DispatchModeAttribute>() ) {
58 kWarning() << "Item doesn't have DispatchModeAttribute.";
59 return false;
60 }
61
62 return item.attribute<DispatchModeAttribute>()->dispatchMode() == DispatchModeAttribute::Manual;
63}
64
65Job *SendQueuedAction::itemAction( const Item &item, FilterActionJob *parent ) const
66{
67 Item cp = item;
68 cp.addAttribute( new DispatchModeAttribute ); // defaults to Automatic
69 if ( cp.hasAttribute<ErrorAttribute>() ) {
70 cp.removeAttribute<ErrorAttribute>();
71 cp.clearFlag( Akonadi::MessageFlags::HasError );
72 }
73 return new ItemModifyJob( cp, parent );
74}
75
76class MailTransport::ClearErrorAction::Private
77{
78};
79
80ClearErrorAction::ClearErrorAction()
81 : d( new Private )
82{
83}
84
85ClearErrorAction::~ClearErrorAction()
86{
87 delete d;
88}
89
90ItemFetchScope ClearErrorAction::fetchScope() const
91{
92 ItemFetchScope scope;
93 scope.fetchFullPayload( false );
94 scope.fetchAttribute<ErrorAttribute>();
95 scope.setCacheOnly( true );
96 return scope;
97}
98
99bool ClearErrorAction::itemAccepted( const Item &item ) const
100{
101 return item.hasAttribute<ErrorAttribute>();
102}
103
104Job *ClearErrorAction::itemAction( const Item &item, FilterActionJob *parent ) const
105{
106 Item cp = item;
107 cp.removeAttribute<ErrorAttribute>();
108 cp.clearFlag( Akonadi::MessageFlags::HasError );
109 cp.setFlag( Akonadi::MessageFlags::Queued );
110 return new ItemModifyJob( cp, parent );
111}
112
113class MailTransport::DispatchManualTransportAction::Private
114{
115};
116
117DispatchManualTransportAction::DispatchManualTransportAction( int transportId )
118 : d( new Private ), mTransportId( transportId )
119{
120}
121
122DispatchManualTransportAction::~DispatchManualTransportAction()
123{
124 delete d;
125}
126
127ItemFetchScope DispatchManualTransportAction::fetchScope() const
128{
129 ItemFetchScope scope;
130 scope.fetchFullPayload( false );
131 scope.fetchAttribute<TransportAttribute>();
132 scope.fetchAttribute<DispatchModeAttribute>();
133 scope.setCacheOnly( true );
134 return scope;
135}
136
137bool DispatchManualTransportAction::itemAccepted( const Item &item ) const
138{
139 if ( !item.hasAttribute<DispatchModeAttribute>() ) {
140 kWarning() << "Item doesn't have DispatchModeAttribute.";
141 return false;
142 }
143
144 if ( !item.hasAttribute<TransportAttribute>() ) {
145 kWarning() << "Item doesn't have TransportAttribute.";
146 return false;
147 }
148
149 return item.attribute<DispatchModeAttribute>()->dispatchMode() == DispatchModeAttribute::Manual;
150}
151
152Job *DispatchManualTransportAction::itemAction( const Item &item, FilterActionJob *parent ) const
153{
154 Item cp = item;
155 cp.attribute<TransportAttribute>()->setTransportId( mTransportId );
156 cp.removeAttribute<DispatchModeAttribute>();
157 cp.addAttribute( new DispatchModeAttribute ); // defaults to Automatic
158 cp.setFlag( Akonadi::MessageFlags::Queued );
159 return new ItemModifyJob( cp, parent );
160}
161