KIMAP2

statusjob.cpp
1/*
2 Copyright (c) 2016 Daniel Vrátil <dvratil@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "statusjob.h"
21#include "job_p.h"
22#include "message_p.h"
23#include "session_p.h"
24#include "rfccodecs.h"
25#include "kimap_debug.h"
26
27namespace KIMAP2
28{
29
30class StatusJobPrivate : public JobPrivate
31{
32public:
33 explicit StatusJobPrivate(Session *session, const QString &name)
34 : JobPrivate(session, name)
35 {
36 }
37
38 ~StatusJobPrivate()
39 {
40 }
41
42 QString mailBox;
43 QList<QByteArray> dataItems;
45};
46
47}
48
49using namespace KIMAP2;
50
51StatusJob::StatusJob(Session *session)
52 : Job(*new StatusJobPrivate(session, "Status"))
53{
54}
55
56StatusJob::~StatusJob()
57{
58}
59
60void StatusJob::setMailBox(const QString &mailBox)
61{
62 Q_D(StatusJob);
63 d->mailBox = mailBox;
64}
65
66QString StatusJob::mailBox() const
67{
68 Q_D(const StatusJob);
69 return d->mailBox;
70}
71
72void StatusJob::setDataItems(const QList<QByteArray> &dataItems)
73{
74 Q_D(StatusJob);
75 d->dataItems = dataItems;
76}
77
78QList<QByteArray> StatusJob::dataItems() const
79{
80 Q_D(const StatusJob);
81 return d->dataItems;
82}
83
84QList<QPair<QByteArray, qint64>> StatusJob::status() const
85{
86 Q_D(const StatusJob);
87 return d->status;
88}
89
90void StatusJob::doStart()
91{
92 Q_D(StatusJob);
93
94 const QByteArray params = '\"' + KIMAP2::encodeImapFolderName(d->mailBox.toUtf8()) + "\" ("
95 + d->dataItems.join(' ') + ')';
96
97 d->sendCommand("STATUS", params);
98}
99
100void StatusJob::handleResponse(const Message &response)
101{
102 Q_D(StatusJob);
103
104 if (handleErrorReplies(response) == NotHandled) {
105 if (response.content.size() >= 3) {
106 const QByteArray code = response.content[1].toString();
107 if (code == "STATUS") {
108
109 const QList<QByteArray> resp = response.content[3].toList();
110 for (int i = 0; i < resp.size(); i += 2) {
111 d->status << (qMakePair(resp[i], resp[i + 1].toLongLong()));
112 }
113
114 } else if (code == "OK") {
115 return;
116 } else {
117 qCDebug(KIMAP2_LOG) << response.toString();
118 }
119 }
120 }
121}
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.
KIMAP2_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 Sat Dec 21 2024 16:56:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.