diff --git a/mailtransport/dispatcherinterface.cpp b/mailtransport/dispatcherinterface.cpp index 2965a8c4c..8b02e8eb4 100644 --- a/mailtransport/dispatcherinterface.cpp +++ b/mailtransport/dispatcherinterface.cpp @@ -1,118 +1,118 @@ /* 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 "outboxactions.h" #include #include #include #include #include #include #include using namespace Akonadi; using namespace MailTransport; /** @internal */ class MailTransport::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 ) + : QObject(), d( dd ) { } DispatcherInterface *DispatcherInterface::self() { return sInstance->instance; } AgentInstance DispatcherInterface::dispatcherInstance() const { - AgentInstance a = AgentManager::self()->instance( QLatin1String( "akonadi_maildispatcher_agent" ) ); + 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 ); + 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 ); + 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/mailtransport/dispatchmodeattribute.cpp b/mailtransport/dispatchmodeattribute.cpp index e7320a268..8e59ecb61 100644 --- a/mailtransport/dispatchmodeattribute.cpp +++ b/mailtransport/dispatchmodeattribute.cpp @@ -1,106 +1,106 @@ /* 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 #include "akonadi/attributefactory.h" using namespace Akonadi; using namespace MailTransport; class DispatchModeAttribute::Private { public: DispatchMode mMode; QDateTime mDueDate; }; DispatchModeAttribute::DispatchModeAttribute( DispatchMode mode, const QDateTime &date ) : d( new Private ) { d->mMode = mode; d->mDueDate = date; } DispatchModeAttribute::~DispatchModeAttribute() { delete d; } -DispatchModeAttribute* DispatchModeAttribute::clone() const +DispatchModeAttribute *DispatchModeAttribute::clone() const { return new DispatchModeAttribute( d->mMode, d->mDueDate ); } QByteArray DispatchModeAttribute::type() const { static const QByteArray sType( "DispatchModeAttribute" ); return sType; } QByteArray DispatchModeAttribute::serialized() const { switch( d->mMode ) { case Immediately: return "immediately"; case AfterDueDate: return "after" + d->mDueDate.toString(Qt::ISODate).toLatin1(); case Never: return "never"; } Q_ASSERT( false ); return QByteArray(); // suppress control-reaches-end-of-non-void-function warning } void DispatchModeAttribute::deserialize( const QByteArray &data ) { d->mDueDate = QDateTime(); if ( data == "immediately" ) { d->mMode = Immediately; } else if ( data == "never" ) { d->mMode = Never; } else if ( data.startsWith( QByteArray( "after" ) ) ) { d->mMode = AfterDueDate; d->mDueDate = QDateTime::fromString( QString::fromLatin1( data.mid(5) ), Qt::ISODate ); // NOTE: 5 is the strlen of "after". } else { kWarning() << "Failed to deserialize data [" << data << "]"; } } DispatchModeAttribute::DispatchMode DispatchModeAttribute::dispatchMode() const { return d->mMode; } void DispatchModeAttribute::setDispatchMode( DispatchMode mode ) { d->mMode = mode; } - + QDateTime DispatchModeAttribute::dueDate() const { return d->mDueDate; } void DispatchModeAttribute::setDueDate( const QDateTime &date ) { d->mDueDate = date; } diff --git a/mailtransport/dispatchmodeattribute.h b/mailtransport/dispatchmodeattribute.h index 6bd9e636e..7c03a24a2 100644 --- a/mailtransport/dispatchmodeattribute.h +++ b/mailtransport/dispatchmodeattribute.h @@ -1,101 +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 MAILTRANSPORT_DISPATCHMODEATTRIBUTE_H #define MAILTRANSPORT_DISPATCHMODEATTRIBUTE_H #include #include #include namespace MailTransport { /** 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 MAILTRANSPORT_EXPORT DispatchModeAttribute : public Akonadi::Attribute { public: /** Determines how the message is sent. */ - enum DispatchMode - { + enum DispatchMode { 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() ); + explicit DispatchModeAttribute( DispatchMode mode = Immediately, + const QDateTime &date = QDateTime() ); /** Destroys the DispatchModeAttribute. */ virtual ~DispatchModeAttribute(); /* reimpl */ - virtual DispatchModeAttribute* clone() const; + 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 ); /** 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: class Private; Private *const d; }; } // namespace MailTransport #endif // MAILTRANSPORT_DISPATCHMODEATTRIBUTE_H diff --git a/mailtransport/errorattribute.cpp b/mailtransport/errorattribute.cpp index e2393cd4d..a35f9500f 100644 --- a/mailtransport/errorattribute.cpp +++ b/mailtransport/errorattribute.cpp @@ -1,76 +1,76 @@ /* 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 MailTransport; class ErrorAttribute::Private { public: QString mMessage; }; ErrorAttribute::ErrorAttribute( const QString &msg ) : d( new Private ) { d->mMessage = msg; } ErrorAttribute::~ErrorAttribute() { delete d; } -ErrorAttribute* ErrorAttribute::clone() const +ErrorAttribute *ErrorAttribute::clone() const { return new ErrorAttribute( d->mMessage ); } QByteArray ErrorAttribute::type() const { static const QByteArray sType( "ErrorAttribute" ); return sType; } QByteArray ErrorAttribute::serialized() const { return d->mMessage.toUtf8(); } void ErrorAttribute::deserialize( const QByteArray &data ) { d->mMessage = QString::fromUtf8( data ); } QString ErrorAttribute::message() const { return d->mMessage; } void ErrorAttribute::setMessage( const QString &msg ) { d->mMessage = msg; } diff --git a/mailtransport/errorattribute.h b/mailtransport/errorattribute.h index 26e42c510..37dda6270 100644 --- a/mailtransport/errorattribute.h +++ b/mailtransport/errorattribute.h @@ -1,75 +1,75 @@ /* 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 MAILTRANSPORT_ERRORATTRIBUTE_H #define MAILTRANSPORT_ERRORATTRIBUTE_H #include #include #include namespace MailTransport { /** Attribute given to the messages that failed to be sent. Contains the error message encountered. @author Constantin Berzan @since 4.4 */ class MAILTRANSPORT_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 ErrorAttribute *clone() const; virtual QByteArray type() const; virtual QByteArray serialized() const; virtual void deserialize( const QByteArray &data ); /** Returns the i18n'ed error message. */ QString message() const; /** Sets the error message. */ void setMessage( const QString &msg ); private: class Private; Private *const d; }; } // namespace MailTransport #endif // MAILTRANSPORT_ERRORATTRIBUTE_H diff --git a/mailtransport/mailtransport_export.h b/mailtransport/mailtransport_export.h index 49c366f58..3f1e6104c 100644 --- a/mailtransport/mailtransport_export.h +++ b/mailtransport/mailtransport_export.h @@ -1,51 +1,50 @@ /* Copyright (c) 2006 Volker Krause 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 MAILTRANSPORT_MAILTRANSPORT_EXPORT_H #define MAILTRANSPORT_MAILTRANSPORT_EXPORT_H #include #ifndef MAILTRANSPORT_EXPORT # if defined(MAKE_MAILTRANSPORT_LIB) /* We are building this library */ # define MAILTRANSPORT_EXPORT KDE_EXPORT # else /* We are using this library */ # define MAILTRANSPORT_EXPORT KDE_IMPORT # endif #endif // TODO KDE5: Get rid of all this. #ifndef MAILTRANSPORT_DEPRECATED # if defined( USES_DEPRECATED_MAILTRANSPORT_API ) /* Avoid deprecated warnings from ourselves and the MDA. */ # define MAILTRANSPORT_DEPRECATED # else /* Show deprecated warnings for anyone else. */ # define MAILTRANSPORT_DEPRECATED KDE_DEPRECATED # endif #endif #ifndef MAILTRANSPORT_EXPORT_DEPRECATED # define MAILTRANSPORT_EXPORT_DEPRECATED MAILTRANSPORT_DEPRECATED MAILTRANSPORT_EXPORT #endif - #endif diff --git a/mailtransport/messagequeuejob.cpp b/mailtransport/messagequeuejob.cpp index 0e4c5f733..9f3ae344c 100644 --- a/mailtransport/messagequeuejob.cpp +++ b/mailtransport/messagequeuejob.cpp @@ -1,290 +1,287 @@ /* 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 "transport.h" #include "transportattribute.h" #include "transportmanager.h" #include #include #include #include #include #include #include using namespace Akonadi; using namespace KMime; using namespace MailTransport; /** @internal */ class MailTransport::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; /** Returns true if this message has everything it needs and is ready to be sent. */ bool validate(); // slot void doStart(); }; bool MessageQueueJob::Private::validate() { if( !message ) { q->setError( UserDefinedError ); q->setErrorText( i18n( "Empty message." ) ); q->emitResult(); return false; } 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 ); Q_ASSERT( !started ); started = true; if( !validate() ) { // The error has been set; the result has been emitted. return; } // Create item. Item item; item.setMimeType( QLatin1String( "message/rfc822" ) ); item.setPayload( message ); // 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. item.setFlag( "queued" ); // 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 ) ) + : KCompositeJob( parent ), d( new Private( this ) ) { } MessageQueueJob::~MessageQueueJob() { 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::start() { LocalFolders *folders = LocalFolders::self(); connect( folders, SIGNAL( foldersReady() ), this, SLOT( doStart() ) ); folders->fetch(); // will emit foldersReady() } void MessageQueueJob::slotResult( KJob *job ) { // error handling KCompositeJob::slotResult( job ); if( !error() ) { emitResult(); } } #include "messagequeuejob.moc" diff --git a/mailtransport/messagequeuejob.h b/mailtransport/messagequeuejob.h index ee337a44d..ae8e2ec48 100644 --- a/mailtransport/messagequeuejob.h +++ b/mailtransport/messagequeuejob.h @@ -1,255 +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 MAILTRANSPORT_MESSAGEQUEUEJOB_H #define MAILTRANSPORT_MESSAGEQUEUEJOB_H #include #include "dispatchmodeattribute.h" #include "sentbehaviourattribute.h" #include #include #include #include #include #include #include namespace MailTransport { /** @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 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 MAILTRANSPORT_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(); /** 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 ); /** Sets the addresses of the "Bcc:" receivers." */ 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. */ virtual void start(); protected Q_SLOTS: /** Called when the ItemCreateJob subjob finishes. (reimplemented from KCompositeJob) */ virtual void slotResult( KJob * ); private: class Private; friend class Private; Private *const d; Q_PRIVATE_SLOT( d, void doStart() ) }; } // namespace MailTransport #endif // MAILTRANSPORT_MESSAGEQUEUEJOB_H diff --git a/mailtransport/outboxactions.cpp b/mailtransport/outboxactions.cpp index a5240acd8..0dbff9142 100644 --- a/mailtransport/outboxactions.cpp +++ b/mailtransport/outboxactions.cpp @@ -1,78 +1,76 @@ /* 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 MailTransport; 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/mailtransport/outboxactions.h b/mailtransport/outboxactions.h index a852b072d..ba6bd0f2c 100644 --- a/mailtransport/outboxactions.h +++ b/mailtransport/outboxactions.h @@ -1,74 +1,73 @@ /* 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 MAILTRANSPORT_OUTBOXACTIONS_H #define MAILTRANSPORT_OUTBOXACTIONS_H #include #include #include #include namespace MailTransport { /** 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 MAILTRANSPORT_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; }; - /** FilterAction that finds all messages with an ErrorAttribute, removes the attribute, and sets the "queued" flag. This is used to retry sending messages that failed. @see FilterActionJob @author Constantin Berzan @since 4.4 */ class MAILTRANSPORT_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 MailTransport #endif // MAILTRANSPORT_OUTBOXACTIONS_H diff --git a/mailtransport/resourcesendjob.cpp b/mailtransport/resourcesendjob.cpp index 192b8c77f..b53e00cc2 100644 --- a/mailtransport/resourcesendjob.cpp +++ b/mailtransport/resourcesendjob.cpp @@ -1,96 +1,95 @@ /* 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 "resourcesendjob.h" #include "messagequeuejob.h" #include "transport.h" #include #include #include #include #include #include #include #include #include #include #include - using namespace Akonadi; using namespace KMime; using namespace MailTransport; /** * Private class that helps to provide binary compatibility between releases. * @internal */ class MailTransport::ResourceSendJobPrivate { public: ResourceSendJobPrivate( ResourceSendJob *qq ) : q( qq ) { } void slotEmitResult(); // slot ResourceSendJob *const q; }; void ResourceSendJobPrivate::slotEmitResult() { // KCompositeJob took care of the error. q->emitResult(); } ResourceSendJob::ResourceSendJob( Transport *transport, QObject *parent ) : TransportJob( transport, parent ), d( new ResourceSendJobPrivate( this ) ) { } ResourceSendJob::~ResourceSendJob() { delete d; } void ResourceSendJob::doStart() { Message::Ptr msg = Message::Ptr( new Message ); msg->setContent( data() ); MessageQueueJob *job = new MessageQueueJob; job->setMessage( msg ); job->setTransportId( transport()->id() ); // Default dispatch mode (send now). // Move to default sent-mail collection. job->setFrom( sender() ); job->setTo( to() ); job->setCc( cc() ); job->setBcc( bcc() ); addSubjob( job ); // Once the item is in the outbox, there is nothing more we can do. connect( job, SIGNAL(result(KJob*)), this, SLOT(slotEmitResult()) ); job->start(); } #include "resourcesendjob.moc" diff --git a/mailtransport/sentbehaviourattribute.cpp b/mailtransport/sentbehaviourattribute.cpp index 42e35e7de..6c072a0ce 100644 --- a/mailtransport/sentbehaviourattribute.cpp +++ b/mailtransport/sentbehaviourattribute.cpp @@ -1,106 +1,106 @@ /* 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 MailTransport; class SentBehaviourAttribute::Private { public: SentBehaviour mBehaviour; Akonadi::Collection::Id mMoveToCollection; }; SentBehaviourAttribute::SentBehaviourAttribute( SentBehaviour beh, Collection::Id moveToCollection ) : d( new Private ) { d->mBehaviour = beh; d->mMoveToCollection = moveToCollection; } SentBehaviourAttribute::~SentBehaviourAttribute() { delete d; } -SentBehaviourAttribute* SentBehaviourAttribute::clone() const +SentBehaviourAttribute *SentBehaviourAttribute::clone() const { return new SentBehaviourAttribute( d->mBehaviour, d->mMoveToCollection ); } QByteArray SentBehaviourAttribute::type() const { static const QByteArray sType( "SentBehaviourAttribute" ); return sType; } QByteArray SentBehaviourAttribute::serialized() const { switch( d->mBehaviour ) { case Delete: return "delete"; case MoveToCollection: return "moveTo" + QByteArray::number( d->mMoveToCollection ); case MoveToDefaultSentCollection: return "moveToDefault"; } Q_ASSERT( false ); return QByteArray(); } void SentBehaviourAttribute::deserialize( const QByteArray &data ) { d->mMoveToCollection = -1; if ( data == "delete" ) { d->mBehaviour = Delete; } else if ( data == "moveToDefault" ) { d->mBehaviour = MoveToDefaultSentCollection; } else if ( data.startsWith( QByteArray( "moveTo" ) ) ) { d->mBehaviour = MoveToCollection; d->mMoveToCollection = data.mid(6).toLongLong(); // NOTE: 6 is the strlen of "moveTo". } else { Q_ASSERT( false ); } } SentBehaviourAttribute::SentBehaviour SentBehaviourAttribute::sentBehaviour() const { return d->mBehaviour; } void SentBehaviourAttribute::setSentBehaviour( SentBehaviour beh ) { d->mBehaviour = beh; } Collection::Id SentBehaviourAttribute::moveToCollection() const { return d->mMoveToCollection; } void SentBehaviourAttribute::setMoveToCollection( Collection::Id moveToCollection ) { d->mMoveToCollection = moveToCollection; } diff --git a/mailtransport/sentbehaviourattribute.h b/mailtransport/sentbehaviourattribute.h index 3f784774d..aac5801fb 100644 --- a/mailtransport/sentbehaviourattribute.h +++ b/mailtransport/sentbehaviourattribute.h @@ -1,101 +1,100 @@ /* 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 MAILTRANSPORT_SENTBEHAVIOURATTRIBUTE_H #define MAILTRANSPORT_SENTBEHAVIOURATTRIBUTE_H #include #include #include namespace MailTransport { /** 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 MAILTRANSPORT_EXPORT SentBehaviourAttribute : public Akonadi::Attribute { public: /** What to do with the item in the outbox after it has been sent successfully. */ - enum SentBehaviour - { + enum SentBehaviour { 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 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 ); /** 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: class Private; Private *const d; }; } // namespace MailTransport #endif // MAILTRANSPORT_SENTBEHAVIOURATTRIBUTE_H diff --git a/mailtransport/transportattribute.cpp b/mailtransport/transportattribute.cpp index 1e738ba13..c8771cd27 100644 --- a/mailtransport/transportattribute.cpp +++ b/mailtransport/transportattribute.cpp @@ -1,81 +1,81 @@ /* 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 "transportmanager.h" #include using namespace Akonadi; using namespace MailTransport; class TransportAttribute::Private { public: int mId; }; TransportAttribute::TransportAttribute( int id ) : d( new Private ) { d->mId = id; } TransportAttribute::~TransportAttribute() { delete d; } -TransportAttribute* TransportAttribute::clone() const +TransportAttribute *TransportAttribute::clone() const { return new TransportAttribute( d->mId ); } QByteArray TransportAttribute::type() const { static const QByteArray sType( "TransportAttribute" ); return sType; } QByteArray TransportAttribute::serialized() const { return QByteArray::number( d->mId ); } void TransportAttribute::deserialize( const QByteArray &data ) { d->mId = data.toInt(); } int TransportAttribute::transportId() const { return d->mId; } -Transport* TransportAttribute::transport() const +Transport *TransportAttribute::transport() const { return TransportManager::self()->transportById( d->mId, false ); } void TransportAttribute::setTransportId( int id ) { d->mId = id; } diff --git a/mailtransport/transportattribute.h b/mailtransport/transportattribute.h index 93f613120..2bf43cbd3 100644 --- a/mailtransport/transportattribute.h +++ b/mailtransport/transportattribute.h @@ -1,85 +1,85 @@ /* 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 MAILTRANSPORT_TRANSPORTATTRIBUTE_H #define MAILTRANSPORT_TRANSPORTATTRIBUTE_H #include #include namespace MailTransport { class Transport; -/** +/** Attribute determining which transport to use for sending a message. @see mailtransport @see TransportManager. @author Constantin Berzan @since 4.4 */ class MAILTRANSPORT_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 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. */ - Transport* transport() const; + Transport *transport() const; /** Sets the transport id to use for sending this message. */ void setTransportId( int id ); private: class Private; Private *const d; }; } // namespace MailTransport #endif // MAILTRANSPORT_TRANSPORTATTRIBUTE_H