mailtransport
outboxactions.cpp
00001 /* 00002 Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com> 00003 00004 This library is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU Library General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or (at your 00007 option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to the 00016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301, USA. 00018 */ 00019 00020 #include "outboxactions_p.h" 00021 00022 #include "dispatchmodeattribute.h" 00023 #include "errorattribute.h" 00024 00025 #include <akonadi/itemmodifyjob.h> 00026 #include <akonadi/kmime/messageflags.h> 00027 00028 using namespace Akonadi; 00029 using namespace MailTransport; 00030 00031 class MailTransport::SendQueuedAction::Private 00032 { 00033 }; 00034 00035 SendQueuedAction::SendQueuedAction() 00036 : d( new Private ) 00037 { 00038 } 00039 00040 SendQueuedAction::~SendQueuedAction() 00041 { 00042 delete d; 00043 } 00044 00045 ItemFetchScope SendQueuedAction::fetchScope() const 00046 { 00047 ItemFetchScope scope; 00048 scope.fetchFullPayload( false ); 00049 scope.fetchAttribute<DispatchModeAttribute>(); 00050 scope.setCacheOnly( true ); 00051 return scope; 00052 } 00053 00054 bool SendQueuedAction::itemAccepted( const Item &item ) const 00055 { 00056 if( !item.hasAttribute<DispatchModeAttribute>() ) { 00057 kWarning() << "Item doesn't have DispatchModeAttribute."; 00058 return false; 00059 } 00060 00061 return item.attribute<DispatchModeAttribute>()->dispatchMode() == DispatchModeAttribute::Manual; 00062 } 00063 00064 Job *SendQueuedAction::itemAction( const Item &item, FilterActionJob *parent ) const 00065 { 00066 Item cp = item; 00067 cp.addAttribute( new DispatchModeAttribute ); // defaults to Automatic 00068 return new ItemModifyJob( cp, parent ); 00069 } 00070 00071 class MailTransport::ClearErrorAction::Private 00072 { 00073 }; 00074 00075 ClearErrorAction::ClearErrorAction() 00076 : d( new Private ) 00077 { 00078 } 00079 00080 ClearErrorAction::~ClearErrorAction() 00081 { 00082 delete d; 00083 } 00084 00085 ItemFetchScope ClearErrorAction::fetchScope() const 00086 { 00087 ItemFetchScope scope; 00088 scope.fetchFullPayload( false ); 00089 scope.fetchAttribute<ErrorAttribute>(); 00090 scope.setCacheOnly( true ); 00091 return scope; 00092 } 00093 00094 bool ClearErrorAction::itemAccepted( const Item &item ) const 00095 { 00096 return item.hasAttribute<ErrorAttribute>(); 00097 } 00098 00099 Job *ClearErrorAction::itemAction( const Item &item, FilterActionJob *parent ) const 00100 { 00101 Item cp = item; 00102 cp.removeAttribute<ErrorAttribute>(); 00103 cp.clearFlag( Akonadi::MessageFlags::HasError ); 00104 cp.setFlag( Akonadi::MessageFlags::Queued ); 00105 return new ItemModifyJob( cp, parent ); 00106 } 00107 00108 class MailTransport::DispatchManualTransportAction::Private 00109 { 00110 }; 00111 00112 DispatchManualTransportAction::DispatchManualTransportAction( int transportId ) 00113 : d( new Private ), mTransportId( transportId ) 00114 { 00115 } 00116 00117 DispatchManualTransportAction::~DispatchManualTransportAction() 00118 { 00119 delete d; 00120 } 00121 00122 ItemFetchScope DispatchManualTransportAction::fetchScope() const 00123 { 00124 ItemFetchScope scope; 00125 scope.fetchFullPayload( false ); 00126 scope.fetchAttribute<TransportAttribute>(); 00127 scope.fetchAttribute<DispatchModeAttribute>(); 00128 scope.setCacheOnly( true ); 00129 return scope; 00130 } 00131 00132 bool DispatchManualTransportAction::itemAccepted( const Item &item ) const 00133 { 00134 if( !item.hasAttribute<DispatchModeAttribute>() ) { 00135 kWarning() << "Item doesn't have DispatchModeAttribute."; 00136 return false; 00137 } 00138 00139 if( !item.hasAttribute<TransportAttribute>() ) { 00140 kWarning() << "Item doesn't have TransportAttribute."; 00141 return false; 00142 } 00143 00144 return item.attribute<DispatchModeAttribute>()->dispatchMode() == DispatchModeAttribute::Manual; 00145 } 00146 00147 Job *DispatchManualTransportAction::itemAction( const Item &item, FilterActionJob *parent ) const 00148 { 00149 Item cp = item; 00150 cp.attribute<TransportAttribute>()->setTransportId( mTransportId ); 00151 cp.removeAttribute<DispatchModeAttribute>(); 00152 cp.addAttribute( new DispatchModeAttribute ); // defaults to Automatic 00153 cp.setFlag( Akonadi::MessageFlags::Queued ); 00154 return new ItemModifyJob( cp, parent ); 00155 }