Make the boss happy.
[kdepim.git] / kmail / mailserviceimpl.cpp
blobf975cbed64781188988167a2b44c7eb1b7dd0816
1 /* -*- mode: C++; c-file-style: "gnu" -*-
3 * This file is part of KMail, the KDE mail client.
4 * Copyright (c) 2003 Zack Rusin <zack@kde.org>
6 * KMail is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License, version 2, as
8 * published by the Free Software Foundation.
10 * KMail is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * In addition, as a special exception, the copyright holders give
20 * permission to link the code of this program with any edition of
21 * the Qt library by Trolltech AS, Norway (or with modified versions
22 * of Qt that use the same license as Qt), and distribute linked
23 * combinations including the two. You must obey the GNU General
24 * Public License in all respects for all of the code used other than
25 * Qt. If you modify this file, you may extend this exception to
26 * your version of the file, but you are not obligated to do so. If
27 * you do not wish to do so, delete this exception statement from
28 * your version.
31 #include "mailserviceimpl.h"
32 #include "mailserviceimpl.moc"
33 #include <serviceadaptor.h>
34 #include "composer.h"
35 #include "kmkernel.h"
37 // kdepim includes
38 #include "messagecomposer/messagehelper.h"
40 #include <kurl.h>
41 #include <kdebug.h>
43 #include <QString>
44 #include <QDBusConnection>
46 namespace KMail {
49 MailServiceImpl::MailServiceImpl()
51 new ServiceAdaptor( this );
52 QDBusConnection::sessionBus().registerObject( "/MailTransportService", this );
55 bool MailServiceImpl::sendMessage( const QString& from, const QString& to,
56 const QString& cc, const QString& bcc,
57 const QString& subject, const QString& body,
58 const QStringList& attachments )
60 if ( to.isEmpty() && cc.isEmpty() && bcc.isEmpty() )
61 return false;
63 KMime::Message::Ptr msg( new KMime::Message );
64 MessageHelper::initHeader( msg, KMKernel::self()->identityManager() );
66 msg->contentType()->setCharset( "utf-8" );
68 if ( !from.isEmpty() ) msg->from()->fromUnicodeString( from, "utf-8" );
69 if ( !to.isEmpty() ) msg->to()->fromUnicodeString( to, "utf-8" );
70 if ( !cc.isEmpty() ) msg->cc()->fromUnicodeString( cc, "utf-8" );
71 if ( !bcc.isEmpty() ) msg->bcc()->fromUnicodeString( bcc, "utf-8" );
72 if ( !subject.isEmpty() ) msg->subject()->fromUnicodeString( subject, "utf-8" );
73 if ( !body.isEmpty() ) msg->setBody( body.toUtf8() );
75 KMail::Composer * cWin = KMail::makeComposer( msg );
77 KUrl::List attachUrls;
78 const int nbAttachments = attachments.count();
79 for ( int i = 0; i < nbAttachments; ++i ) {
80 attachUrls += KUrl( attachments[i] );
83 cWin->addAttachmentsAndSend( attachUrls, "", 1 );//send now
84 return true;
88 bool MailServiceImpl::sendMessage( const QString& from, const QString& to,
89 const QString& cc, const QString& bcc,
90 const QString& subject, const QString& body,
91 const QByteArray& attachment )
93 if ( to.isEmpty() && cc.isEmpty() && bcc.isEmpty() )
94 return false;
96 KMime::Message::Ptr msg( new KMime::Message );
97 MessageHelper::initHeader( msg, KMKernel::self()->identityManager() );
99 msg->contentType()->setCharset( "utf-8" );
101 if ( !from.isEmpty() ) msg->from()->fromUnicodeString( from, "utf-8" );
102 if ( !to.isEmpty() ) msg->to()->fromUnicodeString( to, "utf-8" );
103 if ( !cc.isEmpty() ) msg->cc()->fromUnicodeString( cc, "utf-8" );
104 if ( !bcc.isEmpty() ) msg->bcc()->fromUnicodeString( bcc, "utf-8" );
105 if ( !subject.isEmpty() ) msg->subject()->fromUnicodeString( subject, "utf-8" );
106 if ( !body.isEmpty() ) msg->setBody( body.toUtf8() );
108 KMime::Content *part = new KMime::Content;
109 part->contentTransferEncoding()->from7BitString( "base64" );
110 part->setBody( attachment ); //TODO: check it!
111 msg->addContent( part );
113 KMail::Composer * cWin = KMail::makeComposer( msg );
114 return true;
119 }//end namespace KMail