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

0001 /*
0002     SPDX-FileCopyrightText: 2009 Andras Mantia <amantia@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "quotajobbase.h"
0010 
0011 namespace KIMAP
0012 {
0013 class Session;
0014 struct Message;
0015 class GetQuotaRootJobPrivate;
0016 
0017 /**
0018  * Gets the quota root and resource limits for a mailbox.
0019  *
0020  * Quotas are defined with respect to "resources" and "quota roots".
0021  * A resource is a numerical property that can be limited, such
0022  * as the octet size of all the messages in a mailbox, or the
0023  * number of messages in a mailbox.  Each mailbox has one or more
0024  * quota roots, which are where the resource limits are defined.
0025  * A quota root may or may not be a mailbox name, and an empty
0026  * string is a valid quota root.  All mailboxes with the same quota
0027  * root share the resource limits of the quota root.
0028  *
0029  * This job can only be run when the session is in the
0030  * authenticated (or selected) state.
0031  *
0032  * This job requires that the server supports the QUOTA
0033  * capability, defined in
0034  * <a href="https://tools.ietf.org/html/rfc2087">RFC 2087</a>.
0035  */
0036 class KIMAP_EXPORT GetQuotaRootJob : public QuotaJobBase
0037 {
0038     Q_OBJECT
0039     Q_DECLARE_PRIVATE(GetQuotaRootJob)
0040 
0041     friend class SessionPrivate;
0042 
0043 public:
0044     explicit GetQuotaRootJob(Session *session);
0045     ~GetQuotaRootJob() override;
0046 
0047     /**
0048      * Set the mailbox to get the quota roots for.
0049      *
0050      * @param mailBox  the name of an existing mailbox
0051      */
0052     void setMailBox(const QString &mailBox);
0053     /**
0054      * The mailbox that the quota roots will be fetched for.
0055      */
0056     [[nodiscard]] QString mailBox() const;
0057 
0058     /**
0059      * The quota roots for the mailbox.
0060      */
0061     [[nodiscard]] QList<QByteArray> roots() const;
0062     /**
0063      * Get the current usage for a resource.
0064      *
0065      * Note that if there is no limit for a resource, the
0066      * server will not provide information about resource
0067      * usage.
0068      *
0069      * @param root      the quota root to get the resource usage for
0070      * @param resource  the resource to get the usage for
0071      * @return  the resource usage in appropriate units, or -1
0072      *          if the usage is unknown or there is no
0073      *          limit on the resource
0074      */
0075     [[nodiscard]] qint64 usage(const QByteArray &root, const QByteArray &resource) const;
0076     /**
0077      * Get the current limit for a resource.
0078      *
0079      * @param root      the quota root to get the resource limit for
0080      * @param resource  the resource to get the limit for
0081      * @return  the resource limit in appropriate units, or -1
0082      *          if the limit is unknown or there is no
0083      *          limit on the resource
0084      */
0085     [[nodiscard]] qint64 limit(const QByteArray &root, const QByteArray &resource) const;
0086 
0087     /**
0088      * Get a map containing all resource usage figures for a quota root.
0089      *
0090      * @param root  the quota root to get resource usage figures for
0091      * @return  a map from resource names to usage figures
0092      */
0093     [[nodiscard]] QMap<QByteArray, qint64> allUsages(const QByteArray &root) const;
0094     /**
0095      * Get a map containing all resource limits for a quota root.
0096      *
0097      * @param root  the quota root to get resource limits for
0098      * @return  a map from resource names to limits
0099      */
0100     [[nodiscard]] QMap<QByteArray, qint64> allLimits(const QByteArray &root) const;
0101 
0102 protected:
0103     void doStart() override;
0104     void handleResponse(const Response &response) override;
0105 };
0106 
0107 }