1/*
2 Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "resourcesendjob_p.h"
21#include "messagequeuejob.h"
22#include "transport.h"
23
24#include <QDBusConnection>
25#include <QDBusConnectionInterface>
26
27
28#include <kmime/kmime_message.h>
29
30#include <akonadi/collection.h>
31#include <akonadi/itemcreatejob.h>
32#include <akonadi/itemfetchjob.h>
33#include <akonadi/itemfetchscope.h>
34#include <akonadi/kmime/addressattribute.h>
35
36using namespace Akonadi;
37using namespace KMime;
38using namespace MailTransport;
39
40/**
41 * Private class that helps to provide binary compatibility between releases.
42 * @internal
43 */
44class MailTransport::ResourceSendJobPrivate
45{
46 public:
47 ResourceSendJobPrivate( ResourceSendJob *qq )
48 : q( qq )
49 {
50 }
51
52 void slotEmitResult(); // slot
53
54 ResourceSendJob *const q;
55};
56
57void ResourceSendJobPrivate::slotEmitResult()
58{
59 // KCompositeJob took care of the error.
60 q->emitResult();
61}
62
63ResourceSendJob::ResourceSendJob( Transport *transport, QObject *parent )
64 : TransportJob( transport, parent ), d( new ResourceSendJobPrivate( this ) )
65{
66}
67
68ResourceSendJob::~ResourceSendJob()
69{
70 delete d;
71}
72
73void ResourceSendJob::doStart()
74{
75 Message::Ptr msg = Message::Ptr( new Message );
76 msg->setContent( data() );
77 MessageQueueJob *job = new MessageQueueJob;
78 job->setMessage( msg );
79 job->transportAttribute().setTransportId( transport()->id() );
80 // Default dispatch mode (send now).
81 // Move to default sent-mail collection.
82 job->addressAttribute().setFrom( sender() );
83 job->addressAttribute().setTo( to() );
84 job->addressAttribute().setCc( cc() );
85 job->addressAttribute().setBcc( bcc() );
86 addSubjob( job );
87 // Once the item is in the outbox, there is nothing more we can do.
88 connect( job, SIGNAL(result(KJob*)), this, SLOT(slotEmitResult()) );
89 job->start();
90}
91
92#include "moc_resourcesendjob_p.cpp"
93