• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.12
  • kdepim
  • kmail
mailserviceimpl.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2  *
3  * This file is part of KMail, the KDE mail client.
4  * Copyright (c) 2003 Zack Rusin <zack@kde.org>
5  *
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.
9  *
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.
14  *
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
18  *
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.
29  */
30 
31 #include "mailserviceimpl.h"
32 #include "mailserviceimpl.moc"
33 #include <serviceadaptor.h>
34 #include "editor/composer.h"
35 #include "kmkernel.h"
36 
37 // kdepim includes
38 #include "messagecomposer/helper/messagehelper.h"
39 
40 #include <kurl.h>
41 #include <kdebug.h>
42 
43 #include <QDBusConnection>
44 
45 namespace KMail {
46 
47 
48 MailServiceImpl::MailServiceImpl()
49 {
50  new ServiceAdaptor( this );
51  QDBusConnection::sessionBus().registerObject( QLatin1String("/MailTransportService"), this );
52 }
53 
54 bool MailServiceImpl::sendMessage( const QString& from, const QString& to,
55  const QString& cc, const QString& bcc,
56  const QString& subject, const QString& body,
57  const QStringList& attachments )
58 {
59  if ( to.isEmpty() && cc.isEmpty() && bcc.isEmpty() )
60  return false;
61 
62  KMime::Message::Ptr msg( new KMime::Message );
63  MessageHelper::initHeader( msg, KMKernel::self()->identityManager() );
64 
65  msg->contentType()->setCharset( "utf-8" );
66 
67  if ( !from.isEmpty() ) msg->from()->fromUnicodeString( from, "utf-8" );
68  if ( !to.isEmpty() ) msg->to()->fromUnicodeString( to, "utf-8" );
69  if ( !cc.isEmpty() ) msg->cc()->fromUnicodeString( cc, "utf-8" );
70  if ( !bcc.isEmpty() ) msg->bcc()->fromUnicodeString( bcc, "utf-8" );
71  if ( !subject.isEmpty() ) msg->subject()->fromUnicodeString( subject, "utf-8" );
72  if ( !body.isEmpty() ) msg->setBody( body.toUtf8() );
73 
74  KMail::Composer * cWin = KMail::makeComposer( msg );
75 
76  KUrl::List attachUrls;
77  const int nbAttachments = attachments.count();
78  for ( int i = 0; i < nbAttachments; ++i ) {
79  attachUrls += KUrl( attachments[i] );
80  }
81 
82  cWin->addAttachmentsAndSend( attachUrls, QString(), 1 );//send now
83  return true;
84 }
85 
86 
87 bool MailServiceImpl::sendMessage( const QString& from, const QString& to,
88  const QString& cc, const QString& bcc,
89  const QString& subject, const QString& body,
90  const QByteArray& attachment )
91 {
92  if ( to.isEmpty() && cc.isEmpty() && bcc.isEmpty() )
93  return false;
94 
95  KMime::Message::Ptr msg( new KMime::Message );
96  MessageHelper::initHeader( msg, KMKernel::self()->identityManager() );
97 
98  msg->contentType()->setCharset( "utf-8" );
99 
100  if ( !from.isEmpty() ) msg->from()->fromUnicodeString( from, "utf-8" );
101  if ( !to.isEmpty() ) msg->to()->fromUnicodeString( to, "utf-8" );
102  if ( !cc.isEmpty() ) msg->cc()->fromUnicodeString( cc, "utf-8" );
103  if ( !bcc.isEmpty() ) msg->bcc()->fromUnicodeString( bcc, "utf-8" );
104  if ( !subject.isEmpty() ) msg->subject()->fromUnicodeString( subject, "utf-8" );
105  if ( !body.isEmpty() ) msg->setBody( body.toUtf8() );
106 
107  KMime::Content *part = new KMime::Content;
108  part->contentTransferEncoding()->from7BitString( "base64" );
109  part->setBody( attachment ); //TODO: check it!
110  msg->addContent( part );
111 
112  KMail::makeComposer( msg, false, false );
113  return true;
114 }
115 
116 
117 
118 }//end namespace KMail
119 
KMail::MailServiceImpl::sendMessage
bool sendMessage(const QString &from, const QString &to, const QString &cc, const QString &bcc, const QString &subject, const QString &body, const QStringList &attachments)
Definition: mailserviceimpl.cpp:54
KMail::Composer::addAttachmentsAndSend
virtual void addAttachmentsAndSend(const KUrl::List &urls, const QString &comment, int how)=0
from
QString from() const
KMail::Composer
Definition: composer.h:37
KMKernel::self
static KMKernel * self()
normal control stuff
Definition: kmkernel.cpp:1451
to
QString to() const
subject
QString subject() const
KMail::MailServiceImpl::MailServiceImpl
MailServiceImpl()
Definition: mailserviceimpl.cpp:48
kmkernel.h
composer.h
mailserviceimpl.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:52 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal