File indexing completed on 2024-05-12 05:17:22

0001 /*
0002     Copyright (c) 2009 Andras Mantia <amantia@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or modify it
0005     under the terms of the GNU Library General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or (at your
0007     option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful, but WITHOUT
0010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0012     License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to the
0016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0017     02110-1301, USA.
0018 */
0019 
0020 #ifndef KIMAP2_GETQUOTAROOTJOB_H
0021 #define KIMAP2_GETQUOTAROOTJOB_H
0022 
0023 #include "quotajobbase.h"
0024 
0025 namespace KIMAP2
0026 {
0027 
0028 class Session;
0029 struct Message;
0030 class GetQuotaRootJobPrivate;
0031 
0032 /**
0033  * Gets the quota root and resource limits for a mailbox.
0034  *
0035  * Quotas are defined with respect to "resources" and "quota roots".
0036  * A resource is a numerical property that can be limited, such
0037  * as the octet size of all the messages in a mailbox, or the
0038  * number of messages in a mailbox.  Each mailbox has one or more
0039  * quota roots, which are where the resource limits are defined.
0040  * A quota root may or may not be a mailbox name, and an empty
0041  * string is a valid quota root.  All mailboxes with the same quota
0042  * root share the resource limits of the quota root.
0043  *
0044  * This job can only be run when the session is in the
0045  * authenticated (or selected) state.
0046  *
0047  * This job requires that the server supports the QUOTA
0048  * capability, defined in
0049  * <a href="http://www.apps.ietf.org/rfc/rfc2087.html">RFC 2087</a>.
0050  */
0051 class KIMAP2_EXPORT GetQuotaRootJob : public QuotaJobBase
0052 {
0053     Q_OBJECT
0054     Q_DECLARE_PRIVATE(GetQuotaRootJob)
0055 
0056     friend class SessionPrivate;
0057 
0058 public:
0059     explicit GetQuotaRootJob(Session *session);
0060     virtual ~GetQuotaRootJob();
0061 
0062     /**
0063      * Set the mailbox to get the quota roots for.
0064      *
0065      * @param mailBox  the name of an existing mailbox
0066      */
0067     void setMailBox(const QString &mailBox);
0068     /**
0069      * The mailbox that the quota roots will be fetched for.
0070      */
0071     QString mailBox() const;
0072 
0073     /**
0074      * The quota roots for the mailbox.
0075      */
0076     QList<QByteArray> roots() const;
0077     /**
0078      * Get the current usage for a resource.
0079      *
0080      * Note that if there is no limit for a resource, the
0081      * server will not provide information about resource
0082      * usage.
0083      *
0084      * @param root      the quota root to get the resource usage for
0085      * @param resource  the resource to get the usage for
0086      * @return  the resource usage in appropriate units, or -1
0087      *          if the usage is unknown or there is no
0088      *          limit on the resource
0089      */
0090     qint64 usage(const QByteArray &root, const QByteArray &resource) const;
0091     /**
0092      * Get the current limit for a resource.
0093      *
0094      * @param root      the quota root to get the resource limit for
0095      * @param resource  the resource to get the limit for
0096      * @return  the resource limit in appropriate units, or -1
0097      *          if the limit is unknown or there is no
0098      *          limit on the resource
0099      */
0100     qint64 limit(const QByteArray &root, const QByteArray &resource) const;
0101 
0102     /**
0103      * Get a map containing all resource usage figures for a quota root.
0104      *
0105      * @param root  the quota root to get resource usage figures for
0106      * @return  a map from resource names to usage figures
0107      */
0108     QMap<QByteArray, qint64> allUsages(const QByteArray &root) const;
0109     /**
0110      * Get a map containing all resource limits for a quota root.
0111      *
0112      * @param root  the quota root to get resource limits for
0113      * @return  a map from resource names to limits
0114      */
0115     QMap<QByteArray, qint64> allLimits(const QByteArray &root) const;
0116 
0117 protected:
0118     void doStart() Q_DECL_OVERRIDE;
0119     void handleResponse(const Message &response) Q_DECL_OVERRIDE;
0120 
0121 };
0122 
0123 }
0124 
0125 #endif