KIMAP

statusjob.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Daniel Vrátil <dvratil@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "statusjob.h"
8#include "job_p.h"
9#include "kimap_debug.h"
10#include "response_p.h"
11#include "rfccodecs.h"
12#include "session_p.h"
13
14#include <KLocalizedString>
15
16namespace KIMAP
17{
18class StatusJobPrivate : public JobPrivate
19{
20public:
21 explicit StatusJobPrivate(Session *session, const QString &name)
22 : JobPrivate(session, name)
23 {
24 }
25
26 ~StatusJobPrivate()
27 {
28 }
29
30 QString mailBox;
31 QList<QByteArray> dataItems;
33};
34
35}
36
37using namespace KIMAP;
38
39StatusJob::StatusJob(Session *session)
40 : Job(*new StatusJobPrivate(session, i18nc("name of the status job", "Status")))
41{
42}
43
44StatusJob::~StatusJob()
45{
46}
47
48void StatusJob::setMailBox(const QString &mailBox)
49{
50 Q_D(StatusJob);
51 d->mailBox = mailBox;
52}
53
54QString StatusJob::mailBox() const
55{
56 Q_D(const StatusJob);
57 return d->mailBox;
58}
59
60void StatusJob::setDataItems(const QList<QByteArray> &dataItems)
61{
62 Q_D(StatusJob);
63 d->dataItems = dataItems;
64}
65
66QList<QByteArray> StatusJob::dataItems() const
67{
68 Q_D(const StatusJob);
69 return d->dataItems;
70}
71
72QList<QPair<QByteArray, qint64>> StatusJob::status() const
73{
74 Q_D(const StatusJob);
75 return d->status;
76}
77
78void StatusJob::doStart()
79{
80 Q_D(StatusJob);
81
82 const QByteArray params = '\"' + KIMAP::encodeImapFolderName(d->mailBox.toUtf8()) + "\" (" + d->dataItems.join(' ') + ')';
83
84 d->tags << d->sessionInternal()->sendCommand("STATUS", params);
85}
86
87void StatusJob::handleResponse(const Response &response)
88{
89 Q_D(StatusJob);
90
91 if (handleErrorReplies(response) == NotHandled) {
92 if (response.content.size() >= 3) {
93 const QByteArray code = response.content[1].toString();
94 if (code == "STATUS") {
95 const QList<QByteArray> resp = response.content[3].toList();
96 for (int i = 0; i < resp.size(); i += 2) {
97 d->status << (qMakePair(resp[i], resp[i + 1].toLongLong()));
98 }
99
100 } else if (code == "OK") {
101 return;
102 } else {
103 qCDebug(KIMAP_LOG) << response.toString();
104 }
105 }
106 }
107}
108
109#include "moc_statusjob.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString name(StandardAction id)
QList< T > toList() const const
qsizetype size() const const
This file is part of the IMAP support library and defines the RfcCodecs class.
KIMAP_EXPORT QByteArray encodeImapFolderName(const QByteArray &src)
Converts an Unicode IMAP mailbox to a QByteArray which can be used in IMAP communication.
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:13:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.