diff --git a/outboxinterface/CMakeLists.txt b/outboxinterface/CMakeLists.txt index 033bdfd1e..65a7e77b3 100644 --- a/outboxinterface/CMakeLists.txt +++ b/outboxinterface/CMakeLists.txt @@ -1,44 +1,39 @@ -#include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES} ${KDEPIMLIBS_INCLUDE_DIRS}) - -# TODO: 5324 is mailtransport. we need one of our own! add_definitions( -DKDE_DEFAULT_DEBUG_AREA=5324 ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}" ) add_subdirectory( tests ) -set(outboxinterface_lib_srcs - dispatcherinterface.cpp - outboxactions.cpp - messagequeuejob.cpp +set( outboxinterface_lib_srcs + dispatcherinterface.cpp + messagequeuejob.cpp + outboxactions.cpp - addressattribute.cpp - dispatchmodeattribute.cpp - errorattribute.cpp - sentbehaviourattribute.cpp - transportattribute.cpp + addressattribute.cpp + dispatchmodeattribute.cpp + errorattribute.cpp + sentbehaviourattribute.cpp + transportattribute.cpp ) -# qt4_add_dbus_interface( outboxinterface_lib_srcs interfaces/org.kde.Akonadi.MailDispatcher.xml mdainterface ) -# install( FILES interfaces/org.kde.Akonadi.MailDispatcher.xml DESTINATION ${DBUS_INTERFACES_INSTALL_DIR} ) - -kde4_add_library(outboxinterface SHARED ${outboxinterface_lib_srcs}) +kde4_add_library( outboxinterface SHARED ${outboxinterface_lib_srcs} ) target_link_libraries( outboxinterface ${KDE4_KIO_LIBS} akonadi-kde akonadi-kmime kmime mailtransport ) -set_target_properties(outboxinterface PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} ) +set_target_properties( outboxinterface PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} ) - -install(TARGETS outboxinterface ${INSTALL_TARGETS_DEFAULT_ARGS}) +install( TARGETS outboxinterface ${INSTALL_TARGETS_DEFAULT_ARGS} ) install( FILES - outboxinterface_export.h - dispatcherinterface.h - messagequeuejob.h + outboxinterface_export.h + + dispatcherinterface.h + messagequeuejob.h + outboxactions.h - addressattribute.h - dispatchmodeattribute.h - errorattribute.h - sentbehaviourattribute.h - transportattribute.h + addressattribute.h + dispatchmodeattribute.h + errorattribute.h + sentbehaviourattribute.h + transportattribute.h - DESTINATION ${INCLUDE_INSTALL_DIR}/outboxinterface COMPONENT Devel) + DESTINATION ${INCLUDE_INSTALL_DIR}/outboxinterface COMPONENT Devel ) diff --git a/outboxinterface/TODO b/outboxinterface/TODO index be69631b6..0b53d3218 100644 --- a/outboxinterface/TODO +++ b/outboxinterface/TODO @@ -1,16 +1,9 @@ -* figure out a better name (than outboxinterface), and decide where to merge - (in mailtransport?) -* better name for MessageQueuer? -* Figure out a better way to configure the resource via D-Bus. -* Krazy wants me to use private d-pointers in the attributes -- probably a good - idea since this is a library?... -* if stuff like dispatchManually (stuff that modifies the outbox in general) - stays in DispatcherInterface, then it should really be called OutboxInterface - (too bad that's a conflict). -* provide a dispatcherReady() signal in DispatcherInterface, and think of what - should happen if it is not ready... -* provide a job to modify items in the outbox such as - - remove error attribute and re-queue - - change Never dispatch mode to Immediately +Design: +* Use d-pointers for the attributes? Or rely on having SomeAttrV2 in case + something needs to be added? * Currently apps have to call DispatcherInterface::self() for the attributes to - be registered. Find a way to do this automatically. + get registered. Find a way to do this automatically. + +Build: +* Get our own debug area. + diff --git a/outboxinterface/addressattribute.cpp b/outboxinterface/addressattribute.cpp index 8b6b2f461..50afb69fd 100644 --- a/outboxinterface/addressattribute.cpp +++ b/outboxinterface/addressattribute.cpp @@ -1,113 +1,112 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "addressattribute.h" #include #include using namespace Akonadi; using namespace OutboxInterface; AddressAttribute::AddressAttribute( const QString &from, const QStringList &to, const QStringList &cc, const QStringList &bcc ) : mFrom( from ), mTo( to ), mCc( cc ), mBcc( bcc ) { } AddressAttribute::~AddressAttribute() { } AddressAttribute* AddressAttribute::clone() const { - return new AddressAttribute( mFrom, mTo, mCc, mBcc ); + return new AddressAttribute( mFrom, mTo, mCc, mBcc ); } QByteArray AddressAttribute::type() const { - static const QByteArray sType( "AddressAttribute" ); - return sType; + static const QByteArray sType( "AddressAttribute" ); + return sType; } QByteArray AddressAttribute::serialized() const { QByteArray serializedData; QDataStream serializer( &serializedData, QIODevice::WriteOnly ); serializer.setVersion( QDataStream::Qt_4_5 ); serializer << mFrom; serializer << mTo; serializer << mCc; serializer << mBcc; return serializedData; } void AddressAttribute::deserialize( const QByteArray &data ) { QDataStream deserializer( data ); - // TODO: is this enough to make sure new versions won't trick us? deserializer.setVersion( QDataStream::Qt_4_5 ); deserializer >> mFrom; deserializer >> mTo; deserializer >> mCc; deserializer >> mBcc; } QString AddressAttribute::from() const { return mFrom; } void AddressAttribute::setFrom( const QString &from ) { mFrom = from; } QStringList AddressAttribute::to() const { return mTo; } void AddressAttribute::setTo( const QStringList &to ) { mTo = to; } QStringList AddressAttribute::cc() const { return mCc; } void AddressAttribute::setCc( const QStringList &cc ) { mCc = cc; } QStringList AddressAttribute::bcc() const { return mBcc; } void AddressAttribute::setBcc( const QStringList &bcc ) { mBcc = bcc; } diff --git a/outboxinterface/addressattribute.h b/outboxinterface/addressattribute.h index c9090d12f..0484776ca 100644 --- a/outboxinterface/addressattribute.h +++ b/outboxinterface/addressattribute.h @@ -1,79 +1,114 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OUTBOXINTERFACE_ADDRESSATTRIBUTE_H #define OUTBOXINTERFACE_ADDRESSATTRIBUTE_H #include #include #include #include - -namespace MailTransport -{ +namespace MailTransport { class Transport; } - -namespace OutboxInterface -{ - +namespace OutboxInterface { /** - * Attribute storing the From, To, CC, BCC addresses of a message. - */ + Attribute storing the From, To, Cc, Bcc addresses of a message. + + @author Constantin Berzan + @since 4.4 +*/ class OUTBOXINTERFACE_EXPORT AddressAttribute : public Akonadi::Attribute { public: + /** + Creates a new AddressAttribute. + */ explicit AddressAttribute( const QString &from = QString(), const QStringList &to = QStringList(), const QStringList &cc = QStringList(), const QStringList &bcc = QStringList() ); + /** + Destroys the AddressAttribute. + */ virtual ~AddressAttribute(); + + /* reimpl */ virtual AddressAttribute* clone() const; virtual QByteArray type() const; virtual QByteArray serialized() const; virtual void deserialize( const QByteArray &data ); + /** + Returns the address of the sender. + */ QString from() const; + + /** + Sets the address of the sender. + */ void setFrom( const QString &from ); + + /** + Returns the addresses of the "To:" receivers. + */ QStringList to() const; + + /** + Sets the addresses of the "To:" receivers." + */ void setTo( const QStringList &to ); + + /** + Returns the addresses of the "Cc:" receivers. + */ QStringList cc() const; + + /** + Sets the addresses of the "Cc:" receivers." + */ void setCc( const QStringList &cc ); + + /** + Returns the addresses of the "Bcc:" receivers. + */ QStringList bcc() const; + + /** + Sets the addresses of the "Bcc:" receivers." + */ void setBcc( const QStringList &bcc ); private: QString mFrom; QStringList mTo; QStringList mCc; QStringList mBcc; }; +} // namespace OutboxInterface -} - - -#endif +#endif // OUTBOXINTERFACE_ADDRESSATTRIBUTE_H diff --git a/outboxinterface/dispatcherinterface.cpp b/outboxinterface/dispatcherinterface.cpp index b886b8f7c..cb02e0969 100644 --- a/outboxinterface/dispatcherinterface.cpp +++ b/outboxinterface/dispatcherinterface.cpp @@ -1,136 +1,130 @@ /* Copyright (c) 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "dispatcherinterface.h" #include "addressattribute.h" #include "dispatchmodeattribute.h" #include "errorattribute.h" #include "outboxactions.h" #include "sentbehaviourattribute.h" #include "transportattribute.h" -#include - #include #include #include #include #include #include #include #include using namespace Akonadi; using namespace OutboxInterface; - /** - * Private class that helps to provide binary compatibility between releases. - * @internal - */ + @internal +*/ class OutboxInterface::DispatcherInterfacePrivate { public: DispatcherInterfacePrivate(); ~DispatcherInterfacePrivate(); DispatcherInterface *instance; // slots void massModifyResult( KJob *job ); }; K_GLOBAL_STATIC( DispatcherInterfacePrivate, sInstance ) DispatcherInterfacePrivate::DispatcherInterfacePrivate() : instance( new DispatcherInterface( this ) ) { } DispatcherInterfacePrivate::~DispatcherInterfacePrivate() { delete instance; } void DispatcherInterfacePrivate::massModifyResult( KJob *job ) { // Nothing to do here, really. If the job fails, the user can retry it. if( job->error() ) { kDebug() << "failed" << job->errorString(); } else { kDebug() << "succeeded."; } } DispatcherInterface::DispatcherInterface( DispatcherInterfacePrivate *dd ) : QObject() , d( dd ) { // register attributes AttributeFactory::registerAttribute(); AttributeFactory::registerAttribute(); AttributeFactory::registerAttribute(); AttributeFactory::registerAttribute(); AttributeFactory::registerAttribute(); } DispatcherInterface *DispatcherInterface::self() { return sInstance->instance; } AgentInstance DispatcherInterface::dispatcherInstance() const { AgentInstance a = AgentManager::self()->instance( QLatin1String( "akonadi_maildispatcher_agent" ) ); if( !a.isValid() ) { kWarning() << "Could not get MDA instance."; } return a; } void DispatcherInterface::dispatchManually() { if( !LocalFolders::self()->isReady() ) { kWarning() << "LocalFolders not ready."; return; } FilterActionJob *mjob = new FilterActionJob( LocalFolders::self()->outbox(), new SendQueuedAction, this ); connect( mjob, SIGNAL(result(KJob*)), this, SLOT(massModifyResult(KJob*)) ); } void DispatcherInterface::retryDispatching() { if( !LocalFolders::self()->isReady() ) { kWarning() << "LocalFolders not ready."; return; } FilterActionJob *mjob = new FilterActionJob( LocalFolders::self()->outbox(), new ClearErrorAction, this ); connect( mjob, SIGNAL(result(KJob*)), this, SLOT(massModifyResult(KJob*)) ); } - - #include "dispatcherinterface.moc" diff --git a/outboxinterface/dispatcherinterface.h b/outboxinterface/dispatcherinterface.h index 0d1651de4..5fe9d81e6 100644 --- a/outboxinterface/dispatcherinterface.h +++ b/outboxinterface/dispatcherinterface.h @@ -1,85 +1,87 @@ /* Copyright (c) 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OUTBOXINTERFACE_DISPATCHERINTERFACE_H #define OUTBOXINTERFACE_DISPATCHERINTERFACE_H #include #include #include namespace OutboxInterface { class DispatcherInterfacePrivate; /** - An interface for apps to interact with the MDA. - Provides methods such as send queued messages and retry sending. + @short An interface for applications to interact with the dispatcher agent. - TODO dispatchManually and retryDispatching functions should be offered on a - per-item basis as well, I imagine when the user will have a messageView of - the outbox. Then do we need global ones here (i.e. for all items in the - outbox)? + This class provides methods such as send queued messages (@see + dispatchManually) and retry sending (@see retryDispatching). + + This class also takes care of registering the attributes that the MDA and + OutboxInterface use. The attributes are registered the first time you call + self(), so do that early in your application. + + @author Constantin Berzan + @since 4.4 */ class OUTBOXINTERFACE_EXPORT DispatcherInterface : public QObject { Q_OBJECT public: /** Returns the DispatcherInterface instance. */ static DispatcherInterface *self(); /** Returns the current instance of the MDA. May return an invalid AgentInstance in case it cannot find the MDA. */ Akonadi::AgentInstance dispatcherInstance() const; /** Looks for messages in the outbox with DispatchMode::Never and marks them DispatchMode::Immediately for sending. */ void dispatchManually(); /** Looks for messages in the outbox with ErrorAttribute, and clears them and queues them again for sending. */ void retryDispatching(); private: friend class DispatcherInterfacePrivate; DispatcherInterfacePrivate *const d; // singleton class; the only instance resides in sInstance->instance DispatcherInterface( DispatcherInterfacePrivate *dd ); Q_PRIVATE_SLOT( d, void massModifyResult( KJob* ) ) }; +} // namespace OutboxInterface -} - - -#endif +#endif // OUTBOXINTERFACE_DISPATCHERINTERFACE_H diff --git a/outboxinterface/dispatchmodeattribute.cpp b/outboxinterface/dispatchmodeattribute.cpp index 300f96ab2..3cbc5de41 100644 --- a/outboxinterface/dispatchmodeattribute.cpp +++ b/outboxinterface/dispatchmodeattribute.cpp @@ -1,97 +1,95 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "dispatchmodeattribute.h" #include using namespace Akonadi; using namespace OutboxInterface; - DispatchModeAttribute::DispatchModeAttribute( DispatchMode mode, const QDateTime &date ) - : mMode(mode) - , mDueDate(date) + : mMode( mode ) + , mDueDate( date ) { } DispatchModeAttribute::~DispatchModeAttribute() { } DispatchModeAttribute* DispatchModeAttribute::clone() const { - return new DispatchModeAttribute( mMode, mDueDate ); + return new DispatchModeAttribute( mMode, mDueDate ); } QByteArray DispatchModeAttribute::type() const { - static const QByteArray sType( "DispatchModeAttribute" ); - return sType; + static const QByteArray sType( "DispatchModeAttribute" ); + return sType; } QByteArray DispatchModeAttribute::serialized() const { - switch ( mMode ) - { + switch( mMode ) { case Immediately: return "immediately"; case AfterDueDate: return "after" + mDueDate.toString(Qt::ISODate).toLatin1(); case Never: return "never"; } - Q_ASSERT(false); + Q_ASSERT( false ); return QByteArray(); // suppress control-reaches-end-of-non-void-function warning } void DispatchModeAttribute::deserialize( const QByteArray &data ) { mDueDate = QDateTime(); if ( data == "immediately" ) { mMode = Immediately; } else if ( data == "never" ) { mMode = Never; } else if ( data.startsWith( QByteArray( "after" ) ) ) { mMode = AfterDueDate; mDueDate = QDateTime::fromString( data.mid(5), Qt::ISODate ); - // NOTE: 5 is the strlen of "after". Not very maintenance-friendly. + // NOTE: 5 is the strlen of "after". } else { kWarning() << "Failed to deserialize data [" << data << "]"; } } DispatchModeAttribute::DispatchMode DispatchModeAttribute::dispatchMode() const { return mMode; } void DispatchModeAttribute::setDispatchMode( DispatchMode mode ) { mMode = mode; } QDateTime DispatchModeAttribute::dueDate() const { return mDueDate; } void DispatchModeAttribute::setDueDate( const QDateTime &date ) { mDueDate = date; } diff --git a/outboxinterface/dispatchmodeattribute.h b/outboxinterface/dispatchmodeattribute.h index 3b143a8e3..fde5536de 100644 --- a/outboxinterface/dispatchmodeattribute.h +++ b/outboxinterface/dispatchmodeattribute.h @@ -1,77 +1,101 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OUTBOXINTERFACE_DISPATCHMODEATTRIBUTE_H #define OUTBOXINTERFACE_DISPATCHMODEATTRIBUTE_H #include #include #include - -namespace OutboxInterface -{ - +namespace OutboxInterface { /** - * Attribute determining how and when a message from the outbox is dispatched. - * - * TODO: name: SendPolicy? SendingPolicy? - */ + Attribute determining how and when a message from the outbox should be + dispatched. Messages can be sent immediately, sent only when the user + explicitly requests it, or sent automatically at a certain date and time. + + @author Constantin Berzan + @since 4.4 +*/ class OUTBOXINTERFACE_EXPORT DispatchModeAttribute : public Akonadi::Attribute { public: + /** + Determines how the message is sent. + */ enum DispatchMode { - Immediately, - AfterDueDate, - Never + Immediately, ///< Send message as soon as possible. + AfterDueDate, ///< Send message at a certain date/time. + Never ///< Send message only when the user requests so. }; + /** + Creates a new DispatchModeAttribute. + */ explicit DispatchModeAttribute( DispatchMode mode = Immediately, const QDateTime &date = QDateTime() ); + + /** + Destroys the DispatchModeAttribute. + */ virtual ~DispatchModeAttribute(); + /* reimpl */ virtual DispatchModeAttribute* clone() const; virtual QByteArray type() const; virtual QByteArray serialized() const; virtual void deserialize( const QByteArray &data ); + /** + Returns the dispatch mode for the message. + @see DispatchMode. + */ DispatchMode dispatchMode() const; + + /** + Sets the dispatch mode for the message. + @see DispatchMode. + */ void setDispatchMode( DispatchMode mode ); /** - The due date for sending the message. + Returns the date and time when the message should be sent. Only valid if dispatchMode() is AfterDueDate. */ QDateTime dueDate() const; + + /** + Sets the date and time when the message should be sent. + Make sure you set the DispatchMode to AfterDueDate first. + @see setDispatchMode. + */ void setDueDate( const QDateTime &date ); private: DispatchMode mMode; QDateTime mDueDate; }; +} // namespace OutboxInterface -} - - -#endif +#endif // OUTBOXINTERFACE_DISPATCHMODEATTRIBUTE_H diff --git a/outboxinterface/errorattribute.cpp b/outboxinterface/errorattribute.cpp index 3e79b9c92..3a7b6f397 100644 --- a/outboxinterface/errorattribute.cpp +++ b/outboxinterface/errorattribute.cpp @@ -1,69 +1,68 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "errorattribute.h" #include #include using namespace Akonadi; using namespace OutboxInterface; - ErrorAttribute::ErrorAttribute( const QString &msg ) : mMessage( msg ) { } ErrorAttribute::~ErrorAttribute() { } ErrorAttribute* ErrorAttribute::clone() const { - return new ErrorAttribute( mMessage ); + return new ErrorAttribute( mMessage ); } QByteArray ErrorAttribute::type() const { - static const QByteArray sType( "ErrorAttribute" ); - return sType; + static const QByteArray sType( "ErrorAttribute" ); + return sType; } QByteArray ErrorAttribute::serialized() const { - return mMessage.toLocal8Bit(); + return mMessage.toUtf8(); } void ErrorAttribute::deserialize( const QByteArray &data ) { - mMessage = QString::fromLocal8Bit( data ); + mMessage = QString::fromUtf8( data ); } QString ErrorAttribute::message() const { return mMessage; } void ErrorAttribute::setMessage( const QString &msg ) { mMessage = msg; } diff --git a/outboxinterface/errorattribute.h b/outboxinterface/errorattribute.h index 6070a9e16..912553c4c 100644 --- a/outboxinterface/errorattribute.h +++ b/outboxinterface/errorattribute.h @@ -1,63 +1,74 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OUTBOXINTERFACE_ERRORATTRIBUTE_H #define OUTBOXINTERFACE_ERRORATTRIBUTE_H #include #include #include - -namespace OutboxInterface -{ - +namespace OutboxInterface { /** - * Attribute storing the status of a message in the outbox. - */ + Attribute given to the messages that failed to be sent. Contains the error + message encountered. + + @author Constantin Berzan + @since 4.4 +*/ class OUTBOXINTERFACE_EXPORT ErrorAttribute : public Akonadi::Attribute { public: + /** + Creates a new ErrorAttribute. + */ ErrorAttribute( const QString &msg = QString() ); + + /** + Destroys this ErrorAttribute. + */ virtual ~ErrorAttribute(); + /* reimpl */ virtual ErrorAttribute* clone() const; virtual QByteArray type() const; virtual QByteArray serialized() const; virtual void deserialize( const QByteArray &data ); /** - Textual explanation of error. + Returns the i18n'ed error message. */ QString message() const; + + /** + Sets the error message. + */ void setMessage( const QString &msg ); private: QString mMessage; }; +} // namespace OutboxInterface -} - - -#endif +#endif // OUTBOXINTERFACE_ERRORATTRIBUTE_H diff --git a/outboxinterface/interfaces/org.kde.Akonadi.MailDispatcher.xml b/outboxinterface/interfaces/org.kde.Akonadi.MailDispatcher.xml deleted file mode 100644 index 7c91ccc86..000000000 --- a/outboxinterface/interfaces/org.kde.Akonadi.MailDispatcher.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/outboxinterface/messagequeuejob.cpp b/outboxinterface/messagequeuejob.cpp index 15becac8e..99c8d59a2 100644 --- a/outboxinterface/messagequeuejob.cpp +++ b/outboxinterface/messagequeuejob.cpp @@ -1,320 +1,292 @@ /* Copyright (c) 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "messagequeuejob.h" #include "addressattribute.h" #include "transportattribute.h" -#include - #include #include #include #include #include #include #include #include - using namespace Akonadi; using namespace KMime; using namespace MailTransport; using namespace OutboxInterface; - /** - * Private class that helps to provide binary compatibility between releases. - * @internal - */ + @internal +*/ class OutboxInterface::MessageQueueJob::Private { public: Private( MessageQueueJob *qq ) : q( qq ) { transport = -1; dispatchMode = DispatchModeAttribute::Immediately; sentBehaviour = SentBehaviourAttribute::MoveToDefaultSentCollection; moveToCollection = -1; started = false; } MessageQueueJob *const q; Message::Ptr message; int transport; DispatchModeAttribute::DispatchMode dispatchMode; QDateTime dueDate; SentBehaviourAttribute::SentBehaviour sentBehaviour; Collection::Id moveToCollection; QString from; QStringList to; QStringList cc; QStringList bcc; bool started; - - void readAddressesFromMime(); - /** - Checks that this message has everything it needs and is ready to be sent. + Returns true if this message has everything it needs and is ready to be + sent. */ bool validate(); // slot void doStart(); }; - -void MessageQueueJob::Private::readAddressesFromMime() -{ - kDebug() << "implement me"; - // big TODO -} - bool MessageQueueJob::Private::validate() { if( !message ) { q->setError( UserDefinedError ); q->setErrorText( i18n( "Empty message." ) ); q->emitResult(); return false; - - // NOTE: the MDA also asserts that msg->encodedContent(true) is non-empty. } if( to.count() + cc.count() + bcc.count() == 0 ) { q->setError( UserDefinedError ); q->setErrorText( i18n( "Message has no recipients." ) ); q->emitResult(); return false; } if( dispatchMode == DispatchModeAttribute::AfterDueDate && !dueDate.isValid() ) { q->setError( UserDefinedError ); q->setErrorText( i18n( "Message has invalid due date." ) ); q->emitResult(); return false; } if( TransportManager::self()->transportById( transport, false ) == 0 ) { q->setError( UserDefinedError ); q->setErrorText( i18n( "Message has invalid transport." ) ); q->emitResult(); return false; } if( sentBehaviour == SentBehaviourAttribute::MoveToCollection && moveToCollection < 0 ) { q->setError( UserDefinedError ); q->setErrorText( i18n( "Message has invalid sent-mail folder." ) ); q->emitResult(); return false; } else if( sentBehaviour == SentBehaviourAttribute::MoveToDefaultSentCollection ) { Q_ASSERT( LocalFolders::self()->isReady() ); Q_ASSERT( LocalFolders::self()->sentMail().isValid() ); } return true; // all ok } void MessageQueueJob::Private::doStart() { LocalFolders::self()->disconnect( q ); - //kDebug() << q << "starting"; Q_ASSERT( !started ); started = true; if( !validate() ) { // The error has been set; the result has been emitted. return; } - // create item + // Create item. Item item; item.setMimeType( "message/rfc822" ); item.setPayload( message ); - //kDebug() << "message:" << message->encodedContent( true ); - // set attributes + // Set attributes. AddressAttribute *addrA = new AddressAttribute( from, to, cc, bcc ); DispatchModeAttribute *dmA = new DispatchModeAttribute( dispatchMode, dueDate ); SentBehaviourAttribute *sA = new SentBehaviourAttribute( sentBehaviour, moveToCollection ); TransportAttribute *tA = new TransportAttribute( transport ); item.addAttribute( addrA ); item.addAttribute( dmA ); item.addAttribute( sA ); item.addAttribute( tA ); - // set flags + // Set flags. item.setFlag( "queued" ); - // put item in Akonadi storage + // Store the item in the outbox. Q_ASSERT( LocalFolders::self()->isReady() ); Collection col = LocalFolders::self()->outbox(); ItemCreateJob *job = new ItemCreateJob( item, col ); // job autostarts q->addSubjob( job ); } MessageQueueJob::MessageQueueJob( QObject *parent ) : KCompositeJob( parent ) , d( new Private( this ) ) { - //kDebug() << this << "created"; } MessageQueueJob::~MessageQueueJob() { - //kDebug() << this << "destroyed"; delete d; } - Message::Ptr MessageQueueJob::message() const { return d->message; } int MessageQueueJob::transportId() const { return d->transport; } DispatchModeAttribute::DispatchMode MessageQueueJob::dispatchMode() const { return d->dispatchMode; } QDateTime MessageQueueJob::sendDueDate() const { if( d->dispatchMode != DispatchModeAttribute::AfterDueDate ) { kWarning() << "Called when dispatchMode is not AfterDueDate."; } return d->dueDate; } Collection::Id MessageQueueJob::moveToCollection() const { if( d->sentBehaviour != SentBehaviourAttribute::MoveToCollection ) { kWarning() << "Called when sentBehaviour is not MoveToCollection."; } return d->moveToCollection; } QString MessageQueueJob::from() const { return d->from; } QStringList MessageQueueJob::to() const { return d->to; } QStringList MessageQueueJob::cc() const { return d->cc; } QStringList MessageQueueJob::bcc() const { return d->bcc; } void MessageQueueJob::setMessage( Message::Ptr message ) { d->message = message; } void MessageQueueJob::setTransportId( int id ) { d->transport = id; } void MessageQueueJob::setDispatchMode( DispatchModeAttribute::DispatchMode mode ) { d->dispatchMode = mode; } void MessageQueueJob::setDueDate( const QDateTime &date ) { d->dueDate = date; } void MessageQueueJob::setSentBehaviour( SentBehaviourAttribute::SentBehaviour beh ) { d->sentBehaviour = beh; } void MessageQueueJob::setMoveToCollection( Collection::Id cid ) { d->moveToCollection = cid; } void MessageQueueJob::setFrom( const QString &from ) { d->from = from; } void MessageQueueJob::setTo( const QStringList &to ) { d->to = to; } void MessageQueueJob::setCc( const QStringList &cc ) { d->cc = cc; } void MessageQueueJob::setBcc( const QStringList &bcc ) { d->bcc = bcc; } -void MessageQueueJob::readAddressesFromMime() -{ - d->readAddressesFromMime(); -} - void MessageQueueJob::start() { LocalFolders *folders = LocalFolders::self(); - connect( folders, SIGNAL( foldersReady() ), - this, SLOT( doStart() ) ); + connect( folders, SIGNAL( foldersReady() ), this, SLOT( doStart() ) ); folders->fetch(); // will emit foldersReady() } void MessageQueueJob::slotResult( KJob *job ) { // error handling KCompositeJob::slotResult( job ); if( !error() ) { - //kDebug() << "item created ok. emitting result."; emitResult(); } } #include "messagequeuejob.moc" diff --git a/outboxinterface/messagequeuejob.h b/outboxinterface/messagequeuejob.h index 48bb80bfb..9270b971a 100644 --- a/outboxinterface/messagequeuejob.h +++ b/outboxinterface/messagequeuejob.h @@ -1,121 +1,255 @@ /* Copyright (c) 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OUTBOXINTERFACE_MESSAGEQUEUEJOB_H #define OUTBOXINTERFACE_MESSAGEQUEUEJOB_H #include #include "dispatchmodeattribute.h" #include "sentbehaviourattribute.h" #include #include #include #include #include #include #include - namespace OutboxInterface { - /** - This is the preferred interface for sending email from applications. + @short Provides an interface for sending email. + + This class takes a KMime::Message and some related info such as sender and + recipient addresses, and places the message in the outbox. The mail + dispatcher agent will then take it from there and send it. + + This is the preferred way for applications to send email. + + This job requires some options to be set before being started. These are + setMessage, setTransportId, setFrom, and one of setTo, setCc, or setBcc. + Other settings are optional: setDispatchMode, setSentBehaviour. Example: @code - TODO + MessageQueueJob *job = new MessageQueueJob( this ); + job->setMessage( msg ); // msg is a Message::Ptr + job->setTransportId( TransportManager::self()->defaultTransportId() ); + // Use the default dispatch mode. + // Use the default sent-behaviour. + job->setFrom( from ); // from is a QString + job->setTo( to ); // to is a QStringList + connect( job, SIGNAL(result(KJob*)), this, SLOT(jobResult(KJob*)) ); + job->start(); + @endcode + + @see DispatchModeAttribute + @see SentBehaviourAttribute + + @author Constantin Berzan + @since 4.4 */ class OUTBOXINTERFACE_EXPORT MessageQueueJob : public KCompositeJob { Q_OBJECT public: + /** + Creates a new MessageQueueJob. + This is not an autostarting job; you need to call start() yourself. + */ explicit MessageQueueJob( QObject *parent = 0 ); + + /** + Destroys the MessageQueueJob. + This job deletes itself after finishing. + */ virtual ~MessageQueueJob(); - //TODO there is a lot of duplication between these and the attributes. - // Any better way to handle this? - - //TODO document all of these + /** + Returns the message to be sent. + */ KMime::Message::Ptr message() const; + + /** + Returns the transport id to use for sending the message. + @see TransportManager. + */ int transportId() const; + + /** + Returns the dispatch mode for this message. + @see DispatchModeAttribute. + */ DispatchModeAttribute::DispatchMode dispatchMode() const; + + /** + Returns the date and time when this message should be sent. + Only valid if dispatchMode() is AfterDueDate. + @see DispatchModeAttribute. + */ QDateTime sendDueDate() const; + + /** + Returns the sent-behaviour of this message. + This determines what will happen to the message after it is sent. + @see SentBehaviourAttribute. + */ SentBehaviourAttribute::SentBehaviour sentBehaviour() const; + + /** + Returns the collection to which the message will be moved after it is + sent. + Only valid if sentBehaviour() is MoveToCollection. + @see SentBehaviourAttribute. + */ Akonadi::Collection::Id moveToCollection() const; + + /** + Returns the address of the sender. + */ QString from() const; + + /** + Returns the addresses of the "To:" receivers. + */ QStringList to() const; + + /** + Returns the addresses of the "Cc:" receivers. + */ QStringList cc() const; + + /** + Returns the addresses of the "Bcc:" receivers. + */ QStringList bcc() const; + /** + Sets the message to be sent. + */ void setMessage( KMime::Message::Ptr message ); + + /** + Sets the transport id to use for sending the message. If you want to + use the default transport, you must specify so explicitly: + + @code + job->setTransportId( TransportManager::self()->defaultTransportId() ); + @endcode + + @see TransportManager. + */ void setTransportId( int id ); + + /** + Sets the dispatch mode for this message. + The default dispatch mode is Immediately (meaning the message will be + sent as soon as possible). + @see DispatchModeAttribute. + */ void setDispatchMode( DispatchModeAttribute::DispatchMode mode ); + + /** + Sets the date and time when this message should be sent. + + @code + job->setDispatchMode( DispatchModeAttribute::AfterDueDate ); + job->setDueDate( ... ); + @endcode + + @see DispatchModeAttribute. + */ void setDueDate( const QDateTime &date ); + + /** + Sets the sent-behaviour of this message. + This determines what will happen to the message after it is sent. + The default sent-behaviour is MoveToDefaultSentCollection, which moves + the message to the default sent-mail collection. + @see SentBehaviourAttribute. + */ void setSentBehaviour( SentBehaviourAttribute::SentBehaviour beh ); + + /** + Sets the collection to which the message will be moved after it is + sent. + + @code + job->setSentBehaviour( SentBehaviourAttribute::MoveToCollection ); + job->setMoveToCollection( ... ); + @endcode + + @see SentBehaviourAttribute. + */ void setMoveToCollection( Akonadi::Collection::Id cid ); + + /** + Sets the address of the sender. + */ void setFrom( const QString &from ); + + /** + Sets the addresses of the "To:" receivers." + */ void setTo( const QStringList &to ); + + /** + Sets the addresses of the "Cc:" receivers." + */ void setCc( const QStringList &cc ); - void setBcc( const QStringList &bcc ); /** - Reads From, To, Cc, Bcc from the MIME message. + Sets the addresses of the "Bcc:" receivers." */ - void readAddressesFromMime(); + void setBcc( const QStringList &bcc ); /** Creates the item and places it in the outbox. It is now queued for sending by the mail dispatcher agent. - - (reimplemented from KJob) */ virtual void start(); protected Q_SLOTS: /** - Called when the subjob finishes. + Called when the ItemCreateJob subjob finishes. (reimplemented from KCompositeJob) */ virtual void slotResult( KJob * ); private: class Private; - //friend class Private; - + friend class Private; Private *const d; Q_PRIVATE_SLOT( d, void doStart() ) }; +} // namespace OutboxInterface -} - - -#endif +#endif // OUTBOXINTERFACE_MESSAGEQUEUEJOB_H diff --git a/outboxinterface/outboxactions.cpp b/outboxinterface/outboxactions.cpp index 082f7bf36..f3898f756 100644 --- a/outboxinterface/outboxactions.cpp +++ b/outboxinterface/outboxactions.cpp @@ -1,79 +1,78 @@ /* Copyright (c) 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "outboxactions.h" #include "dispatchmodeattribute.h" #include "errorattribute.h" #include using namespace Akonadi; using namespace OutboxInterface; - ItemFetchScope SendQueuedAction::fetchScope() const { ItemFetchScope scope; scope.fetchFullPayload( false ); scope.fetchAttribute(); return scope; } bool SendQueuedAction::itemAccepted( const Item &item ) const { if( !item.hasAttribute() ) { kWarning() << "Item doesn't have DispatchModeAttribute."; return false; } return item.attribute()->dispatchMode() == DispatchModeAttribute::Never; } Job *SendQueuedAction::itemAction( const Item &item ) const { Item cp = item; cp.addAttribute( new DispatchModeAttribute ); // defaults to Immediately return new ItemModifyJob( cp ); } ItemFetchScope ClearErrorAction::fetchScope() const { ItemFetchScope scope; scope.fetchFullPayload( false ); scope.fetchAttribute(); return scope; } bool ClearErrorAction::itemAccepted( const Item &item ) const { return item.hasAttribute(); } Job *ClearErrorAction::itemAction( const Item &item ) const { Item cp = item; cp.removeAttribute(); cp.clearFlag( "error" ); cp.setFlag( "queued" ); return new ItemModifyJob( cp ); } diff --git a/outboxinterface/outboxactions.h b/outboxinterface/outboxactions.h index 517d4838a..2bdbfa64c 100644 --- a/outboxinterface/outboxactions.h +++ b/outboxinterface/outboxactions.h @@ -1,63 +1,74 @@ /* Copyright (c) 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OUTBOXINTERFACE_OUTBOXACTIONS_H #define OUTBOXINTERFACE_OUTBOXACTIONS_H #include #include #include #include -namespace OutboxInterface -{ +namespace OutboxInterface { /** - FilterActionJob functor that finds all messages with a DispatchMode of Never + FilterAction that finds all messages with a DispatchMode of Never and assigns them a DispatchMode of Immediately. This is used to send "queued" messages on demand. + + @see FilterActionJob + + @author Constantin Berzan + @since 4.4 */ class OUTBOXINTERFACE_EXPORT SendQueuedAction : public Akonadi::FilterAction { public: + /* reimpl */ virtual Akonadi::ItemFetchScope fetchScope() const; virtual bool itemAccepted( const Akonadi::Item &item ) const; virtual Akonadi::Job *itemAction( const Akonadi::Item &item ) const; }; /** - FilterActionJob functor that finds all messages with an ErrorAttribute, + FilterAction that finds all messages with an ErrorAttribute, removes the attribute, and sets the "queued" flag. - This is used to send failed messages again. + This is used to retry sending messages that failed. + + @see FilterActionJob + + @author Constantin Berzan + @since 4.4 */ class OUTBOXINTERFACE_EXPORT ClearErrorAction : public Akonadi::FilterAction { public: + /* reimpl */ virtual Akonadi::ItemFetchScope fetchScope() const; virtual bool itemAccepted( const Akonadi::Item &item ) const; virtual Akonadi::Job *itemAction( const Akonadi::Item &item ) const; }; -} +} // namespace OutboxInterface -#endif +#endif // OUTBOXINTERFACE_OUTBOXACTIONS_H diff --git a/outboxinterface/outboxinterface_export.h b/outboxinterface/outboxinterface_export.h index 2bc35dcbc..b95bb011d 100644 --- a/outboxinterface/outboxinterface_export.h +++ b/outboxinterface/outboxinterface_export.h @@ -1,39 +1,35 @@ /* Copyright (c) 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -// stolen from kdepimlibs/mailtransport/mailtransport_export.h - - #ifndef OUTBOXINTERFACE_OUTBOXINTERFACE_EXPORT_H #define OUTBOXINTERFACE_OUTBOXINTERFACE_EXPORT_H #include #ifndef OUTBOXINTERFACE_EXPORT # if defined(MAKE_OUTBOXINTERFACE_LIB) /* We are building this library */ # define OUTBOXINTERFACE_EXPORT KDE_EXPORT # else /* We are using this library */ # define OUTBOXINTERFACE_EXPORT KDE_IMPORT # endif #endif #endif diff --git a/outboxinterface/sentbehaviourattribute.cpp b/outboxinterface/sentbehaviourattribute.cpp index 60d43b290..73026f25d 100644 --- a/outboxinterface/sentbehaviourattribute.cpp +++ b/outboxinterface/sentbehaviourattribute.cpp @@ -1,98 +1,97 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sentbehaviourattribute.h" #include #include using namespace Akonadi; using namespace OutboxInterface; - SentBehaviourAttribute::SentBehaviourAttribute( SentBehaviour beh, Collection::Id moveToCollection ) : mBehaviour( beh ) , mMoveToCollection( moveToCollection ) { } SentBehaviourAttribute::~SentBehaviourAttribute() { } SentBehaviourAttribute* SentBehaviourAttribute::clone() const { return new SentBehaviourAttribute( mBehaviour, mMoveToCollection ); } QByteArray SentBehaviourAttribute::type() const { static const QByteArray sType( "SentBehaviourAttribute" ); return sType; } QByteArray SentBehaviourAttribute::serialized() const { switch( mBehaviour ) { case Delete: return "delete"; case MoveToCollection: return "moveTo" + QByteArray::number( mMoveToCollection ); case MoveToDefaultSentCollection: return "moveToDefault"; } Q_ASSERT( false ); return QByteArray(); } void SentBehaviourAttribute::deserialize( const QByteArray &data ) { mMoveToCollection = -1; if ( data == "delete" ) { mBehaviour = Delete; } else if ( data == "moveToDefault" ) { mBehaviour = MoveToDefaultSentCollection; } else if ( data.startsWith( QByteArray( "moveTo" ) ) ) { mBehaviour = MoveToCollection; mMoveToCollection = data.mid(6).toLongLong(); // NOTE: 6 is the strlen of "moveTo". } else { Q_ASSERT( false ); } } SentBehaviourAttribute::SentBehaviour SentBehaviourAttribute::sentBehaviour() const { return mBehaviour; } void SentBehaviourAttribute::setSentBehaviour( SentBehaviour beh ) { mBehaviour = beh; } Collection::Id SentBehaviourAttribute::moveToCollection() const { return mMoveToCollection; } void SentBehaviourAttribute::setMoveToCollection( Collection::Id moveToCollection ) { mMoveToCollection = moveToCollection; } diff --git a/outboxinterface/sentbehaviourattribute.h b/outboxinterface/sentbehaviourattribute.h index 0b7f92f13..8d063e2bd 100644 --- a/outboxinterface/sentbehaviourattribute.h +++ b/outboxinterface/sentbehaviourattribute.h @@ -1,79 +1,101 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OUTBOXINTERFACE_SENTBEHAVIOURATTRIBUTE_H #define OUTBOXINTERFACE_SENTBEHAVIOURATTRIBUTE_H #include #include #include - -namespace OutboxInterface -{ - +namespace OutboxInterface { /** - * Attribute storing the id of the sent-mail collection for a message. The - * dispatcher agent will move the item to that collection after it is sent. - */ + Attribute determining what will happen to a message after it is sent. The + message can be deleted from the Outbox, moved to the default sent-mail + collection, or moved to a custom collection. + + @author Constantin Berzan + @since 4.4 +*/ class OUTBOXINTERFACE_EXPORT SentBehaviourAttribute : public Akonadi::Attribute { public: /** What to do with the item in the outbox after it has been sent successfully. */ enum SentBehaviour { - Delete, - MoveToCollection, - MoveToDefaultSentCollection + Delete, ///< Delete the item from the outbox. + MoveToCollection, ///< Move the item to the default sent-mail collection. + MoveToDefaultSentCollection ///< Move the item to a custom collection. }; + /** + Creates a new SentBehaviourAttribute. + */ explicit SentBehaviourAttribute( SentBehaviour beh = MoveToDefaultSentCollection, Akonadi::Collection::Id moveToCollection = -1 ); + + /** + Destroys the SentBehaviourAttribute. + */ virtual ~SentBehaviourAttribute(); + /* reimpl */ virtual SentBehaviourAttribute* clone() const; virtual QByteArray type() const; virtual QByteArray serialized() const; virtual void deserialize( const QByteArray &data ); + /** + Returns the sent-behaviour of the message. + @see SentBehaviour. + */ SentBehaviour sentBehaviour() const; + + /** + Sets the sent-behaviour of the message. + @see SentBehaviour. + */ void setSentBehaviour( SentBehaviour beh ); /** - The collection to move the item to after it is sent. + Returns the collection to which the item should be moved after it is sent. Only valid if sentBehaviour() is MoveToCollection. */ Akonadi::Collection::Id moveToCollection() const; + + /** + Sets the collection to which the item should be moved after it is sent. + Make sure you set the SentBehaviour to MoveToCollection first. + @see setSentBehaviour. + */ void setMoveToCollection( Akonadi::Collection::Id moveToCollection ); private: SentBehaviour mBehaviour; Akonadi::Collection::Id mMoveToCollection; }; +} // namespace OutboxInterface -} - - -#endif +#endif // OUTBOXINTERFACE_SENTBEHAVIOURATTRIBUTE_H diff --git a/outboxinterface/transportattribute.cpp b/outboxinterface/transportattribute.cpp index 78ded7435..da2e28022 100644 --- a/outboxinterface/transportattribute.cpp +++ b/outboxinterface/transportattribute.cpp @@ -1,75 +1,74 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "transportattribute.h" #include #include "mailtransport/transportmanager.h" using namespace Akonadi; using namespace MailTransport; using namespace OutboxInterface; - TransportAttribute::TransportAttribute( int id ) : mId( id ) { } TransportAttribute::~TransportAttribute() { } TransportAttribute* TransportAttribute::clone() const { - return new TransportAttribute( mId ); + return new TransportAttribute( mId ); } QByteArray TransportAttribute::type() const { - static const QByteArray sType( "TransportAttribute" ); - return sType; + static const QByteArray sType( "TransportAttribute" ); + return sType; } QByteArray TransportAttribute::serialized() const { return QByteArray::number( mId ); } void TransportAttribute::deserialize( const QByteArray &data ) { mId = data.toInt(); } int TransportAttribute::transportId() const { return mId; } Transport* TransportAttribute::transport() const { return TransportManager::self()->transportById( mId, false ); } void TransportAttribute::setTransportId( int id ) { mId = id; } diff --git a/outboxinterface/transportattribute.h b/outboxinterface/transportattribute.h index bc2f65718..4c39d63ba 100644 --- a/outboxinterface/transportattribute.h +++ b/outboxinterface/transportattribute.h @@ -1,66 +1,86 @@ /* Copyright 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef OUTBOXINTERFACE_TRANSPORTATTRIBUTE_H #define OUTBOXINTERFACE_TRANSPORTATTRIBUTE_H #include #include - -namespace MailTransport -{ +namespace MailTransport { class Transport; } +namespace OutboxInterface { -namespace OutboxInterface -{ +/** + Attribute determining which transport to use for sending a message. + @see mailtransport + @see TransportManager. -/** - * Attribute determining which transport to use for sending a message. - * @see mailtransport - */ + @author Constantin Berzan + @since 4.4 +*/ class OUTBOXINTERFACE_EXPORT TransportAttribute : public Akonadi::Attribute { public: + /** + Creates a new TransportAttribute. + */ TransportAttribute( int id = -1 ); + + /** + Destroys this TransportAttribute. + */ virtual ~TransportAttribute(); + /* reimpl */ virtual TransportAttribute* clone() const; virtual QByteArray type() const; virtual QByteArray serialized() const; virtual void deserialize( const QByteArray &data ); + /** + Returns the transport id to use for sending this message. + @see TransportManager. + */ int transportId() const; + + /** + Returns the transport object corresponding to the transport id contained + in this attribute. + @see Transport. + */ MailTransport::Transport* transport() const; + + /** + Sets the transport id to use for sending this message. + */ void setTransportId( int id ); private: int mId; }; +} // namespace OutboxInterface -} - - -#endif +#endif // OUTBOXINTERFACE_TRANSPORTATTRIBUTE_H