KIMAP2

getquotarootjob.cpp
1/*
2 Copyright (c) 2009 Andras Mantia <amantia@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 "getquotarootjob.h"
21
22#include "quotajobbase_p.h"
23#include "message_p.h"
24#include "session_p.h"
25#include "rfccodecs.h"
26
27namespace KIMAP2
28{
29class GetQuotaRootJobPrivate : public QuotaJobBasePrivate
30{
31public:
32 GetQuotaRootJobPrivate(Session *session, const QString &name) : QuotaJobBasePrivate(session, name) { }
33 ~GetQuotaRootJobPrivate() { }
34
35 QString mailBox;
36 QList<QByteArray> rootList;
38};
39}
40
41using namespace KIMAP2;
42
43GetQuotaRootJob::GetQuotaRootJob(Session *session)
44 : QuotaJobBase(*new GetQuotaRootJobPrivate(session, "GetQuotaRoot"))
45{
46}
47
48GetQuotaRootJob::~GetQuotaRootJob()
49{
50}
51
52void GetQuotaRootJob::doStart()
53{
55 d->sendCommand("GETQUOTAROOT", '\"' + KIMAP2::encodeImapFolderName(d->mailBox.toUtf8()) + '\"');
56}
57
58void GetQuotaRootJob::handleResponse(const Message &response)
59{
61 if (handleErrorReplies(response) == NotHandled) {
62 if (response.content.size() >= 3) {
63 if (response.content[1].toString() == "QUOTAROOT") {
64 d->rootList.clear();
65 //some impls don't give the root a name which for us seems as if
66 //there were no message part
67 if (response.content.size() == 3) {
68 d->rootList.append("");
69 } else {
70 int i = 3;
71 while (i < response.content.size()) {
72 d->rootList.append(response.content[i].toString());
73 i++;
74 }
75 }
76 } else if (response.content[1].toString() == "QUOTA") {
77 QByteArray rootName;
78 int quotaContentIndex = 3;
79 //some impls don't give the root a name in the response
80 if (response.content.size() == 3) {
81 quotaContentIndex = 2;
82 } else {
83 rootName = response.content[2].toString();
84 }
85
86 const QMap<QByteArray, QPair<qint64, qint64> > &quota = d->readQuota(response.content[quotaContentIndex]);
87 if (d->quotas.contains(rootName)) {
88 d->quotas[ rootName ].unite(quota);
89 } else {
90 d->quotas[ rootName ] = quota;
91 }
92 }
93 }
94 }
95}
96
98{
100 d->mailBox = mailBox;
101}
102
104{
105 Q_D(const GetQuotaRootJob);
106 return d->mailBox;
107}
108
110{
111 Q_D(const GetQuotaRootJob);
112 return d->rootList;
113}
114
115qint64 GetQuotaRootJob::usage(const QByteArray &root, const QByteArray &resource) const
116{
117 Q_D(const GetQuotaRootJob);
118 QByteArray r = resource.toUpper();
119
120 if (d->quotas.contains(root) && d->quotas[root].contains(r)) {
121 return d->quotas[root][r].first;
122 }
123 return -1;
124}
125
126qint64 GetQuotaRootJob::limit(const QByteArray &root, const QByteArray &resource) const
127{
128 Q_D(const GetQuotaRootJob);
129
130 QByteArray r = resource.toUpper();
131
132 if (d->quotas.contains(root) && d->quotas[root].contains(r)) {
133 return d->quotas[root][r].second;
134 }
135 return -1;
136}
137
139{
140 Q_D(const GetQuotaRootJob);
141
143
144 if (d->quotas.contains(root)) {
145 const QMap< QByteArray, QPair<qint64, qint64> > quota = d->quotas[root];
147 while (it.hasNext()) {
148 it.next();
149 result[it.key()] = it.value().first;
150 }
151 }
152 return result;
153}
154
156{
157 Q_D(const GetQuotaRootJob);
158
160
161 if (d->quotas.contains(root)) {
162 const QMap< QByteArray, QPair<qint64, qint64> > quota = d->quotas[root];
164 while (it.hasNext()) {
165 it.next();
166 result[it.key()] = it.value().second;
167 }
168 }
169 return result;
170}
Gets the quota root and resource limits for a mailbox.
qint64 usage(const QByteArray &root, const QByteArray &resource) const
Get the current usage for a resource.
QString mailBox() const
The mailbox that the quota roots will be fetched for.
QList< QByteArray > roots() const
The quota roots for the mailbox.
qint64 limit(const QByteArray &root, const QByteArray &resource) const
Get the current limit for a resource.
void setMailBox(const QString &mailBox)
Set the mailbox to get the quota roots for.
QMap< QByteArray, qint64 > allLimits(const QByteArray &root) const
Get a map containing all resource limits for a quota root.
QMap< QByteArray, qint64 > allUsages(const QByteArray &root) const
Get a map containing all resource usage figures for a quota root.
Base class for jobs that operate on mailbox quotas.
void result(KJob *job)
QString name(StandardShortcut id)
QByteArray first(qsizetype n) const const
QByteArray toUpper() const const
bool hasNext() const const
const Key & key() const const
const T & value() const const
This file is part of the IMAP support library and defines the RfcCodecs class.
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:18 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.