MailTransport

transportjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2007 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "transportjob.h"
8 #include "transport.h"
9 
10 #include <QBuffer>
11 
12 #include <KLocalizedString>
13 
14 using namespace MailTransport;
15 
16 class MailTransport::TransportJobPrivate
17 {
18 public:
19  QString sender;
20  QStringList to;
21  QStringList cc;
22  QStringList bcc;
23  QByteArray data;
24  bool dsn = false;
25  Transport *transport = nullptr;
26  QBuffer *buffer = nullptr;
27 };
28 
30  : KCompositeJob(parent)
31  , d(new TransportJobPrivate)
32 {
33  d->transport = transport;
34  d->buffer = nullptr;
35 }
36 
38 {
39  delete d->transport;
40 }
41 
42 void TransportJob::setSender(const QString &sender)
43 {
44  d->sender = sender;
45 }
46 
48 {
49  d->to = to;
50 }
51 
53 {
54  d->cc = cc;
55 }
56 
58 {
59  d->bcc = bcc;
60 }
61 
63 {
64  d->data = data;
65 }
66 
68 {
69  return d->transport;
70 }
71 
73 {
74  d->dsn = enabled;
75 }
76 
78 {
79  return d->sender;
80 }
81 
83 {
84  return d->to;
85 }
86 
88 {
89  return d->cc;
90 }
91 
93 {
94  return d->bcc;
95 }
96 
98 {
99  return d->data;
100 }
101 
103 {
104  if (!d->buffer) {
105  d->buffer = new QBuffer(this);
106  d->buffer->setData(d->data);
107  d->buffer->open(QIODevice::ReadOnly);
108  Q_ASSERT(d->buffer->isOpen());
109  }
110  return d->buffer;
111 }
112 
114 {
115  return d->dsn;
116 }
117 
119 {
120  if (!transport()->isValid()) {
121  setError(UserDefinedError);
122  setErrorText(i18n("The outgoing account \"%1\" is not correctly configured.", transport()->name()));
123  emitResult();
124  return;
125  }
126  doStart();
127 }
QStringList bcc() const
Returns the "Bcc" receiver(s) of the mail.
QByteArray & buffer()
void setSender(const QString &sender)
Sets the sender of the mail.
void setErrorText(const QString &errorText)
void setDeliveryStatusNotification(bool enabled)
Sets the content of the mail.
bool deliveryStatusNotification() const
Returns true if DSN is enabled.
QByteArray data() const
Returns the data of the mail.
QBuffer * buffer()
Returns a QBuffer opened on the message data.
void setTo(const QStringList &to)
Sets the "To" receiver(s) of the mail.
QStringList to() const
Returns the "To" receiver(s) of the mail.
Transport * transport() const
Returns the Transport object containing the mail transport settings.
QStringList cc() const
Returns the "Cc" receiver(s) of the mail.
QString sender() const
Returns the sender of the mail.
QString i18n(const char *text, const TYPE &arg...)
void setBcc(const QStringList &bcc)
Sets the "Bcc" receiver(s) of the mail.
TransportJob(Transport *transport, QObject *parent=nullptr)
Creates a new mail transport job.
virtual void doStart()=0
Do the actual work, implement in your subclass.
~TransportJob() override
Deletes this transport job.
void start() override
Starts this job.
Represents the settings of a specific mail transport.
Definition: transport.h:32
void setData(const QByteArray &data)
Sets the content of the mail.
void setCc(const QStringList &cc)
Sets the "Cc" receiver(s) of the mail.
void emitResult()
void setError(int errorCode)
char * data()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:58:25 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.