KSMTP

job.cpp
1/*
2 SPDX-FileCopyrightText: 2010 BetterInbox <contact@betterinbox.com>
3 SPDX-FileContributor: Christophe Laveault <christophe@betterinbox.com>
4 SPDX-FileContributor: Gregory Schlomoff <gregory.schlomoff@gmail.com>
5
6 SPDX-License-Identifier: LGPL-2.1-or-later
7*/
8
9#include "job.h"
10#include "job_p.h"
11#include "serverresponse_p.h"
12#include "session_p.h"
13
14#include <KLocalizedString>
15
16using namespace KSmtp;
17
18Job::Job(Session *session)
19 : KJob(session)
20 , d_ptr(new JobPrivate(session, QStringLiteral("Job")))
21{
22}
23
24Job::Job(JobPrivate &dd)
25 : KJob(dd.m_session)
26 , d_ptr(&dd)
27{
28}
29
30Job::~Job() = default;
31
32Session *Job::session() const
33{
34 Q_D(const Job);
35 return d->m_session;
36}
37
38void Job::start()
39{
40 Q_D(Job);
41 d->sessionInternal()->addJob(this);
42}
43
44void Job::sendCommand(const QByteArray &cmd)
45{
46 Q_D(Job);
47 d->sessionInternal()->sendData(cmd);
48}
49
50void Job::handleErrors(const ServerResponse &r)
51{
52 if (r.isCode(4) || r.isCode(5)) {
53 setError(KJob::UserDefinedError);
54 // https://www.ietf.org/rfc/rfc2821.txt
55 // We could just use r.text(), but that might not be in the user's language, so try and prepend a translated message.
56 const QString serverText = QString::fromUtf8(r.text());
57 if (r.code() == 421) {
58 setErrorText(i18n("Service not available")); // e.g. the server is shutting down
59 } else if (r.code() == 450 || r.code() == 550) {
60 setErrorText(i18n("Mailbox unavailable. The server said: %1", serverText));
61 } else if (r.code() == 452 || r.code() == 552) {
62 setErrorText(i18n("Insufficient storage space on server. The server said: %1", serverText));
63 } else {
64 setErrorText(i18n("Server error: %1", serverText));
65 }
66 emitResult();
67 }
68}
69
70void Job::connectionLost()
71{
72 setError(KJob::UserDefinedError);
73 setErrorText(i18n("Connection to server lost."));
74 emitResult();
75}
76
77#include "moc_job.cpp"
void setErrorText(const QString &errorText)
void emitResult()
void setError(int errorCode)
The Job class.
Definition job.h:25
QString i18n(const char *text, const TYPE &arg...)
QString fromUtf8(QByteArrayView str)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:14:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.