• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

mailtransport

sendmailjob.cpp

00001 /*
00002     Copyright (c) 2007 Volker Krause <vkrause@kde.org>
00003     Copyright (c) 2007 KovoKs <kovoks@kovoks.nl>
00004 
00005     Based on KMail code by:
00006     Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
00007 
00008     This library is free software; you can redistribute it and/or modify it
00009     under the terms of the GNU Library General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or (at your
00011     option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful, but WITHOUT
00014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00016     License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to the
00020     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00021     02110-1301, USA.
00022 */
00023 
00024 #include "sendmailjob.h"
00025 #include "transport.h"
00026 
00027 #include <KLocalizedString>
00028 
00029 #include <QtCore/QProcess>
00030 #include <QtCore/QBuffer>
00031 
00032 using namespace MailTransport;
00033 
00038 class SendMailJobPrivate
00039 {
00040   public:
00041     QProcess *process;
00042     QString lastError;
00043 };
00044 
00045 SendmailJob::SendmailJob( Transport *transport, QObject *parent )
00046   : TransportJob( transport, parent ), d( new SendMailJobPrivate )
00047 {
00048   d->process = new QProcess( this );
00049   connect( d->process,
00050            SIGNAL(finished(int, QProcess::ExitStatus)),
00051            SLOT(sendmailExited(int, QProcess::ExitStatus)) );
00052   connect( d->process, SIGNAL(error(QProcess::ProcessError)),
00053            SLOT(receivedError()) );
00054   connect( d->process, SIGNAL(readyReadStandardError()),
00055            SLOT(receivedStdErr()) );
00056 }
00057 
00058 SendmailJob::~ SendmailJob()
00059 {
00060   delete d;
00061 }
00062 
00063 void SendmailJob::doStart()
00064 {
00065   QStringList arguments;
00066   arguments << QLatin1String( "-i" ) << QLatin1String( "-f" )
00067             << sender() << to() << cc() << bcc();
00068   d->process->start( transport()->host(), arguments );
00069 
00070   if ( !d->process->waitForStarted() ) {
00071     setError( UserDefinedError );
00072     setErrorText( i18n( "Failed to execute mailer program %1", transport()->host() ) );
00073     emitResult();
00074   } else {
00075     d->process->write( buffer()->readAll() );
00076     d->process->closeWriteChannel();
00077   }
00078 }
00079 
00080 void SendmailJob::sendmailExited( int exitCode, QProcess::ExitStatus exitStatus )
00081 {
00082   if ( exitStatus != 0 || exitCode != 0 ) {
00083     setError( UserDefinedError );
00084     if ( d->lastError.isEmpty() ) {
00085       setErrorText( i18n( "Sendmail exited abnormally." ) );
00086     } else {
00087       setErrorText( i18n( "Sendmail exited abnormally: %1", d->lastError ) );
00088     }
00089   }
00090   emitResult();
00091 }
00092 
00093 void SendmailJob::receivedError()
00094 {
00095   d->lastError += d->process->errorString();
00096 }
00097 
00098 void SendmailJob::receivedStdErr()
00099 {
00100   d->lastError += QLatin1String( d->process->readAllStandardError() );
00101 }
00102 
00103 bool SendmailJob::doKill()
00104 {
00105   delete d->process;
00106   d->process = 0;
00107   return true;
00108 }
00109 
00110 #include "sendmailjob.moc"

mailtransport

Skip menu "mailtransport"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal