20#include "messagequeuejob.h"
23#include "transportattribute.h"
24#include "transportmanager.h"
27#include <KLocalizedString>
29#include <akonadi/collection.h>
30#include <akonadi/item.h>
31#include <akonadi/itemcreatejob.h>
32#include <akonadi/kmime/addressattribute.h>
33#include <akonadi/kmime/messageflags.h>
34#include <akonadi/kmime/specialmailcollections.h>
35#include <akonadi/kmime/specialmailcollectionsrequestjob.h>
37using namespace Akonadi;
39using namespace MailTransport;
44class MailTransport::MessageQueueJob::Private
56 TransportAttribute transportAttribute;
57 DispatchModeAttribute dispatchModeAttribute;
58 SentBehaviourAttribute sentBehaviourAttribute;
59 SentActionAttribute sentActionAttribute;
60 AddressAttribute addressAttribute;
70 void outboxRequestResult( KJob *job );
74bool MessageQueueJob::Private::validate()
77 q->setError( UserDefinedError );
78 q->setErrorText( i18n(
"Empty message." ) );
83 if ( addressAttribute.to().count() + addressAttribute.cc().count() +
84 addressAttribute.bcc().count() == 0 ) {
85 q->setError( UserDefinedError );
86 q->setErrorText( i18n(
"Message has no recipients." ) );
91 const int transport = transportAttribute.transportId();
93 q->setError( UserDefinedError );
94 q->setErrorText( i18n(
"Message has invalid transport." ) );
100 !( sentBehaviourAttribute.moveToCollection().isValid() ) ) {
101 q->setError( UserDefinedError );
102 q->setErrorText( i18n(
"Message has invalid sent-mail folder." ) );
105 }
else if ( sentBehaviourAttribute.sentBehaviour() ==
113void MessageQueueJob::Private::outboxRequestResult( KJob *job )
115 Q_ASSERT( !started );
118 if ( job->error() ) {
119 kError() <<
"Failed to get the Outbox folder:" << job->error() << job->errorString();
120 q->setError( job->error() );
130 SpecialMailCollectionsRequestJob *requestJob =
131 qobject_cast<SpecialMailCollectionsRequestJob*>( job );
138 item.setMimeType( QLatin1String(
"message/rfc822" ) );
139 item.setPayload<Message::Ptr>(
message );
148 Akonadi::MessageFlags::copyMessageFlags(*
message, item);
151 item.setFlag( Akonadi::MessageFlags::Queued );
154 const Collection collection = requestJob->collection();
155 Q_ASSERT( collection.isValid() );
156 ItemCreateJob *cjob =
new ItemCreateJob( item, collection );
157 q->addSubjob( cjob );
161 : KCompositeJob( parent ), d( new Private( this ) )
177 return d->dispatchModeAttribute;
182 return d->addressAttribute;
187 return d->transportAttribute;
192 return d->sentBehaviourAttribute;
197 return d->sentActionAttribute;
207 SpecialMailCollectionsRequestJob *rjob =
new SpecialMailCollectionsRequestJob(
this );
208 rjob->requestDefaultCollection( SpecialMailCollections::Outbox );
209 connect( rjob, SIGNAL(result(KJob*)),
this, SLOT(outboxRequestResult(KJob*)) );
216 KCompositeJob::slotResult( job );
223#include "moc_messagequeuejob.cpp"
Attribute determining how and when a message from the outbox should be dispatched.
KMime::Message::Ptr message() const
Returns the message to be sent.
DispatchModeAttribute & dispatchModeAttribute()
Returns a reference to the dispatch mode attribue for this message.
Akonadi::AddressAttribute & addressAttribute()
Returns a reference to the address attribue for this message.
void setMessage(KMime::Message::Ptr message)
Sets the message to be sent.
TransportAttribute & transportAttribute()
Returns a reference to the transport attribue for this message.
MessageQueueJob(QObject *parent=0)
Creates a new MessageQueueJob.
SentBehaviourAttribute & sentBehaviourAttribute()
Returns a reference to the sent behaviour attribue for this message.
virtual void slotResult(KJob *)
Called when the ItemCreateJob subjob finishes.
virtual void start()
Creates the item and places it in the outbox.
SentActionAttribute & sentActionAttribute()
Returns a reference to the sent action attribue for this message.
virtual ~MessageQueueJob()
Destroys the MessageQueueJob.
An Attribute that stores the action to execute after sending.
Attribute determining what will happen to a message after it is sent.
@ MoveToDefaultSentCollection
Move the item to the default sent-mail collection.
@ MoveToCollection
Move the item to a custom collection.
Attribute determining which transport to use for sending a message.
static TransportManager * self()
Returns the TransportManager instance.