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.fetchAttribute<ErrorAttribute>(); 00051 scope.setCacheOnly( true ); 00052 return scope; 00053 } 00054 00055 bool SendQueuedAction::itemAccepted( const Item &item ) const 00056 { 00057 if( !item.hasAttribute<DispatchModeAttribute>() ) { 00058 kWarning() << "Item doesn't have DispatchModeAttribute."; 00059 return false; 00060 } 00061 00062 return item.attribute<DispatchModeAttribute>()->dispatchMode() == DispatchModeAttribute::Manual; 00063 } 00064 00065 Job *SendQueuedAction::itemAction( const Item &item, FilterActionJob *parent ) const 00066 { 00067 Item cp = item; 00068 cp.addAttribute( new DispatchModeAttribute ); // defaults to Automatic 00069 if( cp.hasAttribute<ErrorAttribute>() ) { 00070 cp.removeAttribute<ErrorAttribute>(); 00071 cp.clearFlag( Akonadi::MessageFlags::HasError ); 00072 } 00073 return new ItemModifyJob( cp, parent ); 00074 } 00075 00076 class MailTransport::ClearErrorAction::Private 00077 { 00078 }; 00079 00080 ClearErrorAction::ClearErrorAction() 00081 : d( new Private ) 00082 { 00083 } 00084 00085 ClearErrorAction::~ClearErrorAction() 00086 { 00087 delete d; 00088 } 00089 00090 ItemFetchScope ClearErrorAction::fetchScope() const 00091 { 00092 ItemFetchScope scope; 00093 scope.fetchFullPayload( false ); 00094 scope.fetchAttribute<ErrorAttribute>(); 00095 scope.setCacheOnly( true ); 00096 return scope; 00097 } 00098 00099 bool ClearErrorAction::itemAccepted( const Item &item ) const 00100 { 00101 return item.hasAttribute<ErrorAttribute>(); 00102 } 00103 00104 Job *ClearErrorAction::itemAction( const Item &item, FilterActionJob *parent ) const 00105 { 00106 Item cp = item; 00107 cp.removeAttribute<ErrorAttribute>(); 00108 cp.clearFlag( Akonadi::MessageFlags::HasError ); 00109 cp.setFlag( Akonadi::MessageFlags::Queued ); 00110 return new ItemModifyJob( cp, parent ); 00111 } 00112 00113 class MailTransport::DispatchManualTransportAction::Private 00114 { 00115 }; 00116 00117 DispatchManualTransportAction::DispatchManualTransportAction( int transportId ) 00118 : d( new Private ), mTransportId( transportId ) 00119 { 00120 } 00121 00122 DispatchManualTransportAction::~DispatchManualTransportAction() 00123 { 00124 delete d; 00125 } 00126 00127 ItemFetchScope DispatchManualTransportAction::fetchScope() const 00128 { 00129 ItemFetchScope scope; 00130 scope.fetchFullPayload( false ); 00131 scope.fetchAttribute<TransportAttribute>(); 00132 scope.fetchAttribute<DispatchModeAttribute>(); 00133 scope.setCacheOnly( true ); 00134 return scope; 00135 } 00136 00137 bool DispatchManualTransportAction::itemAccepted( const Item &item ) const 00138 { 00139 if( !item.hasAttribute<DispatchModeAttribute>() ) { 00140 kWarning() << "Item doesn't have DispatchModeAttribute."; 00141 return false; 00142 } 00143 00144 if( !item.hasAttribute<TransportAttribute>() ) { 00145 kWarning() << "Item doesn't have TransportAttribute."; 00146 return false; 00147 } 00148 00149 return item.attribute<DispatchModeAttribute>()->dispatchMode() == DispatchModeAttribute::Manual; 00150 } 00151 00152 Job *DispatchManualTransportAction::itemAction( const Item &item, FilterActionJob *parent ) const 00153 { 00154 Item cp = item; 00155 cp.attribute<TransportAttribute>()->setTransportId( mTransportId ); 00156 cp.removeAttribute<DispatchModeAttribute>(); 00157 cp.addAttribute( new DispatchModeAttribute ); // defaults to Automatic 00158 cp.setFlag( Akonadi::MessageFlags::Queued ); 00159 return new ItemModifyJob( cp, parent ); 00160 }