KIMAP

getquotarootjob.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Andras Mantia <amantia@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "getquotarootjob.h"
8
9#include <KLocalizedString>
10
11#include "quotajobbase_p.h"
12#include "response_p.h"
13#include "rfccodecs.h"
14#include "session_p.h"
15
16namespace KIMAP
17{
18class GetQuotaRootJobPrivate : public QuotaJobBasePrivate
19{
20public:
21 GetQuotaRootJobPrivate(Session *session, const QString &name)
22 : QuotaJobBasePrivate(session, name)
23 {
24 }
25 ~GetQuotaRootJobPrivate()
26 {
27 }
28
29 QString mailBox;
30 QList<QByteArray> rootList;
32};
33}
34
35using namespace KIMAP;
36
37GetQuotaRootJob::GetQuotaRootJob(Session *session)
38 : QuotaJobBase(*new GetQuotaRootJobPrivate(session, i18n("GetQuotaRoot")))
39{
40}
41
42GetQuotaRootJob::~GetQuotaRootJob()
43{
44}
45
46void GetQuotaRootJob::doStart()
47{
49 d->tags << d->sessionInternal()->sendCommand("GETQUOTAROOT", '\"' + KIMAP::encodeImapFolderName(d->mailBox.toUtf8()) + '\"');
50}
51
52void GetQuotaRootJob::handleResponse(const Response &response)
53{
55 if (handleErrorReplies(response) == NotHandled) {
56 if (response.content.size() >= 3) {
57 if (response.content[1].toString() == "QUOTAROOT") {
58 d->rootList.clear();
59 // some impls don't give the root a name which for us seems as if
60 // there were no message part
61 if (response.content.size() == 3) {
62 d->rootList.append("");
63 } else {
64 int i = 3;
65 while (i < response.content.size()) {
66 d->rootList.append(response.content[i].toString());
67 i++;
68 }
69 }
70 } else if (response.content[1].toString() == "QUOTA") {
71 QByteArray rootName;
72 int quotaContentIndex = 3;
73 // some impls don't give the root a name in the response
74 if (response.content.size() == 3) {
75 quotaContentIndex = 2;
76 } else {
77 rootName = response.content[2].toString();
78 }
79
80 const QMap<QByteArray, QPair<qint64, qint64>> &quota = d->readQuota(response.content[quotaContentIndex]);
81 if (d->quotas.contains(rootName)) {
82 d->quotas[rootName].insert(quota);
83 } else {
84 d->quotas[rootName] = quota;
85 }
86 }
87 }
88 }
89}
90
92{
94 d->mailBox = mailBox;
95}
96
98{
99 Q_D(const GetQuotaRootJob);
100 return d->mailBox;
101}
102
104{
105 Q_D(const GetQuotaRootJob);
106 return d->rootList;
107}
108
109qint64 GetQuotaRootJob::usage(const QByteArray &root, const QByteArray &resource) const
110{
111 Q_D(const GetQuotaRootJob);
112 QByteArray r = resource.toUpper();
113
114 if (d->quotas.contains(root) && d->quotas[root].contains(r)) {
115 return d->quotas[root][r].first;
116 }
117 return -1;
118}
119
120qint64 GetQuotaRootJob::limit(const QByteArray &root, const QByteArray &resource) const
121{
122 Q_D(const GetQuotaRootJob);
123
124 QByteArray r = resource.toUpper();
125
126 if (d->quotas.contains(root) && d->quotas[root].contains(r)) {
127 return d->quotas[root][r].second;
128 }
129 return -1;
130}
131
133{
134 Q_D(const GetQuotaRootJob);
135
137
138 if (d->quotas.contains(root)) {
139 const QMap<QByteArray, QPair<qint64, qint64>> quota = d->quotas[root];
140 QMap<QByteArray, QPair<qint64, qint64>>::const_iterator it = quota.cbegin();
141 const QMap<QByteArray, QPair<qint64, qint64>>::const_iterator itEnd = quota.cend();
142 for (; it != itEnd; ++it) {
143 result[it.key()] = it.value().first;
144 }
145 }
146 return result;
147}
148
150{
151 Q_D(const GetQuotaRootJob);
152
154
155 if (d->quotas.contains(root)) {
156 const QMap<QByteArray, QPair<qint64, qint64>> quota = d->quotas[root];
157 QMap<QByteArray, QPair<qint64, qint64>>::const_iterator it = quota.cbegin();
158 const QMap<QByteArray, QPair<qint64, qint64>>::const_iterator itEnd = quota.cend();
159 for (; it != itEnd; ++it) {
160 result[it.key()] = it.value().second;
161 }
162 }
163 return result;
164}
165
166#include "moc_getquotarootjob.cpp"
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 i18n(const char *text, const TYPE &arg...)
QString name(StandardAction id)
QByteArray toUpper() const const
const_iterator cbegin() const const
const_iterator cend() const const
Key key(const T &value, const Key &defaultKey) const const
T value(const Key &key, const T &defaultValue) 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 Mon Nov 18 2024 12:09:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.