KSMTP
11 #include "ksmtp_debug.h"
12 #include "serverresponse_p.h"
14 #include <KLocalizedString>
18 class SendJobPrivate :
public JobPrivate
21 enum Status { Idle, SendingReturnPath, SendingRecipients, SendingData };
24 : JobPrivate(session,
name)
31 void sendNextRecipient();
35 using MessagePart =
struct {
51 using namespace KSmtp;
53 SendJob::SendJob(
Session *session)
54 :
Job(*new SendJobPrivate(this, session,
i18n(
"SendJob")))
64 d->m_returnPath = QStringLiteral(
"<%1>").arg(from.
mid(start + 1, end - start - 1));
66 d->m_returnPath = QStringLiteral(
"<%1>").arg(from);
85 d->addRecipients(bcc);
94 d->m_data.
replace(
"\r\n.",
"\r\n..");
97 void SendJob::doStart()
103 setErrorText(
i18n(
"Could not send the message because either the sender or recipient field is missing or invalid"));
108 const int sizeLimit = session()->
sizeLimit();
109 if (sizeLimit > 0 &&
size() > sizeLimit) {
111 setErrorText(
i18n(
"Could not send the message because it exceeds the maximum allowed size of %1 bytes. (Message size: %2 bytes.)", sizeLimit,
size()));
116 d->m_status = SendJobPrivate::SendingReturnPath;
117 sendCommand(
"MAIL FROM:" + d->m_returnPath.toUtf8());
120 void SendJob::handleResponse(
const ServerResponse &r)
127 switch (d->m_status) {
128 case SendJobPrivate::Idle:
132 case SendJobPrivate::SendingReturnPath:
136 d->m_status = SendJobPrivate::SendingRecipients;
137 d->sendNextRecipient();
141 case SendJobPrivate::SendingRecipients:
145 if (d->m_recipientsCopy.isEmpty()) {
147 d->m_status = SendJobPrivate::SendingData;
149 d->sendNextRecipient();
154 case SendJobPrivate::SendingData:
159 sendCommand(d->m_data);
160 sendCommand(
"\r\n.");
171 void SendJobPrivate::sendNextRecipient()
173 const bool dsnSupport = m_session->allowsDsn() ? m_dsn :
false;
175 q->sendCommand(
"RCPT TO:<" + m_recipientsCopy.takeFirst().toUtf8() +
'>' + (dsnSupport ?
" NOTIFY=success,failure" :
""));
178 void SendJobPrivate::addRecipients(
const QStringList &rcpts)
180 for (
const auto &rcpt : rcpts) {
181 if (rcpt.isEmpty()) {
188 m_recipients.push_back(rcpt.mid(
start + 1, end -
start - 1));
190 m_recipients.push_back(rcpt);
195 bool SendJobPrivate::prepare()
197 if (m_data.isEmpty()) {
198 qCWarning(KSMTP_LOG) <<
"A message has to be set before starting a SendJob";
202 m_recipientsCopy = m_recipients;
204 if (m_recipients.isEmpty()) {
205 qCWarning(KSMTP_LOG) <<
"Message has no recipients";
216 return d->m_data.size();
225 #include "moc_sendjob.cpp"
void setErrorText(const QString &errorText)
Q_SCRIPTABLE Q_NOREPLY void start()
void setBcc(const QStringList &bcc)
Add recipients.
QString i18n(const char *text, const TYPE &arg...)
void setFrom(const QString &from)
Set the sender email address.
void setTo(const QStringList &to)
Add recipients.
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
QByteArray & replace(int pos, int len, const char *after)
int sizeLimit() const
Returns the maximum message size in bytes that the server accepts.
void setCc(const QStringList &cc)
Add recipients.
const char * name(StandardAction id)
int size() const
Returns size of the encoded message data.
void setDeliveryStatusNotification(bool b)
Set Delivery Status Notification.
void setData(const QByteArray &data)
Set the actual message data.
QString mid(int position, int n) const const
void setError(int errorCode)
const QList< QKeySequence > & end()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Nov 29 2023 04:08:02 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.