KIMAP

setquotajob.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Andras Mantia <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "setquotajob.h"
8 
9 #include <KLocalizedString>
10 #include "kimap_debug.h"
11 
12 #include "quotajobbase_p.h"
13 #include "response_p.h"
14 #include "session_p.h"
15 
16 namespace KIMAP
17 {
18 class SetQuotaJobPrivate : public QuotaJobBasePrivate
19 {
20 public:
21  SetQuotaJobPrivate(Session *session, const QString &name) : QuotaJobBasePrivate(session, name) { }
22  ~SetQuotaJobPrivate() { }
23 
25  QByteArray root;
26 };
27 }
28 
29 using namespace KIMAP;
30 
31 SetQuotaJob::SetQuotaJob(Session *session)
32  : QuotaJobBase(*new SetQuotaJobPrivate(session, i18n("SetQuota")))
33 {
34 }
35 
36 SetQuotaJob::~SetQuotaJob()
37 {
38 }
39 
40 void SetQuotaJob::doStart()
41 {
42  Q_D(SetQuotaJob);
43  QByteArray s;
44  s += '(';
45  for (QMap<QByteArray, qint64>::ConstIterator it = d->setList.constBegin(), end = d->setList.constEnd(); it != end; ++it) {
46  s += it.key() + ' ' + QByteArray::number(it.value()) + ' ';
47  }
48  if (d->setList.isEmpty()) {
49  s += ')';
50  } else {
51  s[s.length() - 1] = ')';
52  }
53 
54  qCDebug(KIMAP_LOG) << "SETQUOTA " << '\"' + d->root + "\" " + s;
55  //XXX: [alexmerry, 2010-07-24]: should d->root be quoted properly?
56  d->tags << d->sessionInternal()->sendCommand("SETQUOTA", '\"' + d->root + "\" " + s);
57 }
58 
59 void SetQuotaJob::handleResponse(const Response &response)
60 {
61  Q_D(SetQuotaJob);
62  if (handleErrorReplies(response) == NotHandled) {
63  if (response.content.size() >= 4 &&
64  response.content[1].toString() == "QUOTA") {
65  d->quota = d->readQuota(response.content[3]);
66  }
67  }
68 }
69 
70 void SetQuotaJob::setQuota(const QByteArray &resource, qint64 limit)
71 {
72  Q_D(SetQuotaJob);
73 
74  d->setList[resource.toUpper()] = limit;
75 }
76 
78 {
79  Q_D(SetQuotaJob);
80 
81  d->root = root;
82 }
83 
85 {
86  Q_D(const SetQuotaJob);
87 
88  return d->root;
89 }
Base class for jobs that operate on mailbox quotas.
Definition: quotajobbase.h:30
QMap::const_iterator constBegin() const const
QByteArray toUpper() const const
QByteArray root() const
The quota root that will be modified.
Definition: setquotajob.cpp:84
int length() const const
void setRoot(const QByteArray &root)
Set the quota root the resource limits should be set for.
Definition: setquotajob.cpp:77
Sets resource limits on a quota root.
Definition: setquotajob.h:38
QByteArray number(int n, int base)
QString i18n(const char *text, const TYPE &arg...)
const QList< QKeySequence > & end()
Definition: acl.cpp:12
void setQuota(const QByteArray &resource, qint64 limit)
Set a limit for a quota resource.
Definition: setquotajob.cpp:70
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Oct 24 2020 23:16:51 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.