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

mailtransport

  • sources
  • kde-4.14
  • kdepimlibs
  • mailtransport
sendmailjob.cpp
1 /*
2  Copyright (c) 2007 Volker Krause <vkrause@kde.org>
3  Copyright (c) 2007 KovoKs <kovoks@kovoks.nl>
4 
5  Based on KMail code by:
6  Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
7 
8  This library is free software; you can redistribute it and/or modify it
9  under the terms of the GNU Library General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or (at your
11  option) any later version.
12 
13  This library is distributed in the hope that it will be useful, but WITHOUT
14  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
16  License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to the
20  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 */
23 
24 #include "sendmailjob.h"
25 #include "transport.h"
26 
27 #include <KLocalizedString>
28 
29 #include <QtCore/QProcess>
30 #include <QtCore/QBuffer>
31 
32 using namespace MailTransport;
33 
38 class SendMailJobPrivate
39 {
40  public:
41  QProcess *process;
42  QString lastError;
43 };
44 
45 SendmailJob::SendmailJob( Transport *transport, QObject *parent )
46  : TransportJob( transport, parent ), d( new SendMailJobPrivate )
47 {
48  d->process = new QProcess( this );
49  connect( d->process,
50  SIGNAL(finished(int,QProcess::ExitStatus)),
51  SLOT(sendmailExited(int,QProcess::ExitStatus)) );
52  connect( d->process, SIGNAL(error(QProcess::ProcessError)),
53  SLOT(receivedError()) );
54  connect( d->process, SIGNAL(readyReadStandardError()),
55  SLOT(receivedStdErr()) );
56 }
57 
58 SendmailJob::~ SendmailJob()
59 {
60  delete d;
61 }
62 
63 void SendmailJob::doStart()
64 {
65  QStringList arguments;
66  arguments << QLatin1String( "-i" ) << QLatin1String( "-f" )
67  << sender() << to() << cc() << bcc();
68  d->process->start( transport()->host(), arguments );
69 
70  if ( !d->process->waitForStarted() ) {
71  setError( UserDefinedError );
72  setErrorText( i18n( "Failed to execute mailer program %1", transport()->host() ) );
73  emitResult();
74  } else {
75  d->process->write( buffer()->readAll() );
76  d->process->closeWriteChannel();
77  }
78 }
79 
80 void SendmailJob::sendmailExited( int exitCode, QProcess::ExitStatus exitStatus )
81 {
82  if ( exitStatus != 0 || exitCode != 0 ) {
83  setError( UserDefinedError );
84  if ( d->lastError.isEmpty() ) {
85  setErrorText( i18n( "Sendmail exited abnormally." ) );
86  } else {
87  setErrorText( i18n( "Sendmail exited abnormally: %1", d->lastError ) );
88  }
89  }
90  emitResult();
91 }
92 
93 void SendmailJob::receivedError()
94 {
95  d->lastError += d->process->errorString();
96 }
97 
98 void SendmailJob::receivedStdErr()
99 {
100  d->lastError += QLatin1String( d->process->readAllStandardError() );
101 }
102 
103 bool SendmailJob::doKill()
104 {
105  delete d->process;
106  d->process = 0;
107  return true;
108 }
109 
MailTransport::TransportJob::bcc
QStringList bcc() const
Returns the "Bcc" receiver(s) of the mail.
Definition: transportjob.cpp:99
MailTransport::SendmailJob::~SendmailJob
virtual ~SendmailJob()
Destroys this job.
Definition: sendmailjob.cpp:58
QProcess
MailTransport::TransportJob::cc
QStringList cc() const
Returns the "Cc" receiver(s) of the mail.
Definition: transportjob.cpp:94
QObject
MailTransport::TransportJob::sender
QString sender() const
Returns the sender of the mail.
Definition: transportjob.cpp:84
MailTransport::SendmailJob::doStart
virtual void doStart()
Do the actual work, implement in your subclass.
Definition: sendmailjob.cpp:63
QString
QStringList
MailTransport::SendmailJob::SendmailJob
SendmailJob(Transport *transport, QObject *parent=0)
Creates a SendmailJob.
Definition: sendmailjob.cpp:45
MailTransport::TransportJob
Abstract base class for all mail transport jobs.
Definition: transportjob.h:41
QLatin1String
MailTransport::Transport
Represents the settings of a specific mail transport.
Definition: transport.h:50
MailTransport::TransportJob::to
QStringList to() const
Returns the "To" receiver(s) of the mail.
Definition: transportjob.cpp:89
MailTransport::TransportJob::transport
Transport * transport() const
Returns the Transport object containing the mail transport settings.
Definition: transportjob.cpp:79
MailTransport::TransportJob::buffer
QBuffer * buffer()
Returns a QBuffer opened on the message data.
Definition: transportjob.cpp:109
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:48 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailtransport

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

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

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