kmail

mailserviceimpl.cpp

Go to the documentation of this file.
00001 /*  -*- mode: C++; c-file-style: "gnu" -*-
00002  *
00003  *  This file is part of KMail, the KDE mail client.
00004  *  Copyright (c) 2003 Zack Rusin <zack@kde.org>
00005  *
00006  *  KMail is free software; you can redistribute it and/or modify it
00007  *  under the terms of the GNU General Public License, version 2, as
00008  *  published by the Free Software Foundation.
00009  *
00010  *  KMail is distributed in the hope that it will be useful, but
00011  *  WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018  *
00019  *  In addition, as a special exception, the copyright holders give
00020  *  permission to link the code of this program with any edition of
00021  *  the Qt library by Trolltech AS, Norway (or with modified versions
00022  *  of Qt that use the same license as Qt), and distribute linked
00023  *  combinations including the two.  You must obey the GNU General
00024  *  Public License in all respects for all of the code used other than
00025  *  Qt.  If you modify this file, you may extend this exception to
00026  *  your version of the file, but you are not obligated to do so.  If
00027  *  you do not wish to do so, delete this exception statement from
00028  *  your version.
00029  */
00030 
00031 #ifdef HAVE_CONFIG_H
00032 #include <config.h>
00033 #endif
00034 
00035 #include "mailserviceimpl.h"
00036 
00037 #include "composer.h"
00038 
00039 #include "kmmessage.h"
00040 #include "kmmsgpart.h"
00041 
00042 #include <dcopobject.h>
00043 #include <kurl.h>
00044 #include <kdebug.h>
00045 #include <qstring.h>
00046 
00047 namespace KMail {
00048 
00049 
00050 MailServiceImpl::MailServiceImpl()
00051   : DCOPObject( "MailTransportServiceIface" )
00052 {
00053 }
00054 
00055 bool MailServiceImpl::sendMessage( const QString& from, const QString& to,
00056                                    const QString& cc, const QString& bcc,
00057                                    const QString& subject, const QString& body,
00058                                    const KURL::List& attachments )
00059 {
00060   if ( to.isEmpty() && cc.isEmpty() && bcc.isEmpty() )
00061     return false;
00062 
00063   KMMessage *msg = new KMMessage;
00064   msg->initHeader();
00065 
00066   msg->setCharset( "utf-8" );
00067 
00068   if ( !from.isEmpty() )    msg->setFrom( from );
00069   if ( !to.isEmpty() )      msg->setTo( to );
00070   if ( !cc.isEmpty() )      msg->setCc( cc );
00071   if ( !bcc.isEmpty() )     msg->setBcc( bcc );
00072   if ( !subject.isEmpty() ) msg->setSubject( subject );
00073   if ( !body.isEmpty() )    msg->setBody( body.utf8() );
00074 
00075   KMail::Composer * cWin = KMail::makeComposer( msg );
00076   cWin->setCharset("", TRUE);
00077 
00078   cWin->addAttachmentsAndSend(attachments, "", 1);//send now
00079   return true;
00080 }
00081 
00082 bool MailServiceImpl::sendMessage( const QString& to,
00083                                    const QString& cc, const QString& bcc,
00084                                    const QString& subject, const QString& body,
00085                                    const KURL::List& attachments )
00086 {
00087   kdDebug(5006) << "DCOP call MailTransportServiceIface bool sendMessage(QString to,QString cc,QString bcc,QString subject,QString body,KURL::List attachments)" << endl;
00088   kdDebug(5006) << "This DCOP call is deprecated. Use the corresponding DCOP call with the additional parameter QString from instead." << endl;
00089   return sendMessage( QString::null, to, cc, bcc, subject, body, attachments );
00090 }
00091 
00092 
00093 bool MailServiceImpl::sendMessage( const QString& from, const QString& to,
00094                                    const QString& cc, const QString& bcc,
00095                                    const QString& subject, const QString& body,
00096                                    const QByteArray& attachment )
00097 {
00098   if ( to.isEmpty() && cc.isEmpty() && bcc.isEmpty() )
00099     return false;
00100 
00101   KMMessage *msg = new KMMessage;
00102   msg->initHeader();
00103 
00104   msg->setCharset( "utf-8" );
00105 
00106   if ( !from.isEmpty() )    msg->setFrom( from );
00107   if ( !to.isEmpty() )      msg->setTo( to );
00108   if ( !cc.isEmpty() )      msg->setCc( cc );
00109   if ( !bcc.isEmpty() )     msg->setBcc( bcc );
00110   if ( !subject.isEmpty() ) msg->setSubject( subject );
00111   if ( !body.isEmpty() )    msg->setBody( body.utf8() );
00112 
00113   KMMessagePart *part = new KMMessagePart;
00114   part->setCteStr( "base64" );
00115   part->setBodyEncodedBinary( attachment );
00116   msg->addBodyPart( part );
00117 
00118   KMail::Composer * cWin = KMail::makeComposer( msg );
00119   cWin->setCharset("", TRUE);
00120   return true;
00121 }
00122 
00123 
00124 bool MailServiceImpl::sendMessage( const QString& to,
00125                                    const QString& cc, const QString& bcc,
00126                                    const QString& subject, const QString& body,
00127                                    const QByteArray& attachment )
00128 {
00129   kdDebug(5006) << "DCOP call MailTransportServiceIface bool sendMessage(QString to,QString cc,QString bcc,QString subject,QString body,QByteArray attachment)" << endl;
00130   kdDebug(5006) << "This DCOP call is deprecated. Use the corresponding DCOP call with the additional parameter QString from instead." << endl;
00131   return sendMessage( QString::null, to, cc, bcc, subject, body, attachment );
00132 }
00133 
00134 }//end namespace KMail
00135