• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.3 API Reference
  • KDE Home
  • Contact Us
 

KIMAP Library

  • kimap
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 <KDE/KLocale>
23 #include <KDE/KDebug>
24 
25 #include "quotajobbase_p.h"
26 #include "message_p.h"
27 #include "session_p.h"
28 #include "rfccodecs.h"
29 
30 namespace KIMAP
31 {
32  class GetQuotaRootJobPrivate : public QuotaJobBasePrivate
33  {
34  public:
35  GetQuotaRootJobPrivate( Session *session, const QString& name ) : QuotaJobBasePrivate(session, name) { }
36  ~GetQuotaRootJobPrivate() { }
37 
38  QString mailBox;
39  QList<QByteArray> rootList;
40  QMap< QByteArray, QMap<QByteArray, QPair<qint64, qint64> > > quotas;
41  };
42 }
43 
44 using namespace KIMAP;
45 
46 GetQuotaRootJob::GetQuotaRootJob( Session *session )
47  : QuotaJobBase( *new GetQuotaRootJobPrivate(session, i18n("GetQuotaRoot")) )
48 {
49 }
50 
51 GetQuotaRootJob::~GetQuotaRootJob()
52 {
53 }
54 
55 void GetQuotaRootJob::doStart()
56 {
57  Q_D(GetQuotaRootJob);
58  d->tags << d->sessionInternal()->sendCommand( "GETQUOTAROOT", '\"' + KIMAP::encodeImapFolderName( d->mailBox.toUtf8() ) + '\"');
59 }
60 
61 void GetQuotaRootJob::handleResponse(const Message &response)
62 {
63  Q_D(GetQuotaRootJob);
64  if (handleErrorReplies(response) == NotHandled) {
65  if ( response.content.size() >= 3 ) {
66  if (response.content[1].toString() == "QUOTAROOT" ) {
67  d->rootList.clear();
68  //some impls don't give the root a name which for us seems as if
69  //there were no message part
70  if ( response.content.size() == 3 ) {
71  d->rootList.append("");
72  } else {
73  int i = 3;
74  while ( i < response.content.size())
75  {
76  d->rootList.append(response.content[i].toString());
77  i++;
78  }
79  }
80  } else
81  if (response.content[1].toString() == "QUOTA" ) {
82  QByteArray rootName;
83  int quotaContentIndex = 3;
84  //some impls don't give the root a name in the response
85  if (response.content.size() == 3 ) {
86  quotaContentIndex = 2;
87  } else {
88  rootName = response.content[2].toString();
89  }
90 
91  const QMap<QByteArray, QPair<qint64, qint64> >& quota = d->readQuota(response.content[quotaContentIndex]);
92  if (d->quotas.contains(rootName)) {
93  d->quotas[ rootName ].unite(quota);
94  } else {
95  d->quotas[ rootName ] = quota;
96  }
97  }
98  }
99  }
100 }
101 
102 
103 void GetQuotaRootJob::setMailBox(const QString& mailBox)
104 {
105  Q_D(GetQuotaRootJob);
106 
107  d->mailBox = mailBox;
108 }
109 
110 QString GetQuotaRootJob::mailBox() const
111 {
112  Q_D(const GetQuotaRootJob);
113 
114  return d->mailBox;
115 }
116 
117 QList<QByteArray> GetQuotaRootJob::roots() const
118 {
119  Q_D(const GetQuotaRootJob);
120 
121  return d->rootList;
122 }
123 
124 qint64 GetQuotaRootJob::usage(const QByteArray &root, const QByteArray &resource) const
125 {
126  Q_D(const GetQuotaRootJob);
127 
128  QByteArray r = resource.toUpper();
129 
130  if (d->quotas.contains(root) && d->quotas[root].contains(r)) {
131  return d->quotas[root][r].first;
132  }
133 
134  return -1;
135 }
136 
137 qint64 GetQuotaRootJob::limit(const QByteArray &root, const QByteArray &resource) const
138 {
139  Q_D(const GetQuotaRootJob);
140 
141  QByteArray r = resource.toUpper();
142 
143  if (d->quotas.contains(root) && d->quotas[root].contains(r)) {
144  return d->quotas[root][r].second;
145  }
146 
147  return -1;
148 }
149 
150 QMap<QByteArray, qint64> GetQuotaRootJob::allUsages(const QByteArray &root) const
151 {
152  Q_D(const GetQuotaRootJob);
153 
154  QMap<QByteArray, qint64> result;
155 
156  if (d->quotas.contains(root)) {
157  const QMap< QByteArray, QPair<qint64, qint64> > quota = d->quotas[root];
158  QMapIterator<QByteArray, QPair<qint64, qint64> > it( quota );
159  while ( it.hasNext() ) {
160  it.next();
161  result[it.key()] = it.value().first;
162  }
163  }
164 
165  return result;
166 }
167 
168 QMap<QByteArray, qint64> GetQuotaRootJob::allLimits(const QByteArray &root) const
169 {
170  Q_D(const GetQuotaRootJob);
171 
172  QMap<QByteArray, qint64> result;
173 
174  if (d->quotas.contains(root)) {
175  const QMap< QByteArray, QPair<qint64, qint64> > quota = d->quotas[root];
176  QMapIterator<QByteArray, QPair<qint64, qint64> > it( quota );
177  while ( it.hasNext() ) {
178  it.next();
179  result[it.key()] = it.value().second;
180  }
181  }
182 
183  return result;
184 }
185 
186 #include "getquotarootjob.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Nov 26 2012 16:46:44 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIMAP Library

Skip menu "KIMAP Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.9.3 API Reference

Skip menu "kdepimlibs-4.9.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal