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

0001 /*
0002     Copyright (c) 2009 Kevin Ottens <ervin@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_LISTJOB_H
0021 #define KIMAP2_LISTJOB_H
0022 
0023 #include "kimap2_export.h"
0024 
0025 #include "job.h"
0026 
0027 namespace KIMAP2
0028 {
0029 
0030 class Session;
0031 struct Message;
0032 class ListJobPrivate;
0033 
0034 struct KIMAP2_EXPORT MailBoxDescriptor {
0035     QString name;
0036     QChar separator;
0037 
0038     inline bool operator==(const MailBoxDescriptor &other) const
0039     {
0040         return other.name == name && other.separator == separator;
0041     }
0042 
0043     inline bool operator<(const MailBoxDescriptor &other) const
0044     {
0045         return other.name < name || (other.name == name && other.separator < separator);
0046     }
0047 };
0048 
0049 class KIMAP2_EXPORT ListJob : public Job
0050 {
0051     Q_OBJECT
0052     Q_DECLARE_PRIVATE(ListJob)
0053 
0054     friend class SessionPrivate;
0055 
0056 public:
0057     enum Option {
0058         NoOption = 0x0,         /**< List only subscribed mailboxes. (Uses the LSUB IMAP command.) */
0059         IncludeUnsubscribed,    /**< List subscribed and unsubscribed mailboxes. (Uses the LIST IMAP command.) */
0060         IncludeFolderRoleFlags  /**< List subscribed and unsubscribed mailboxes with flags to identify standard mailboxes whose name may be localized.
0061                                    The server must support the XLIST extension. */
0062     };
0063 
0064     explicit ListJob(Session *session);
0065     virtual ~ListJob();
0066 
0067     void setOption(Option option);
0068     Option option() const;
0069 
0070     void setQueriedNamespaces(const QList<MailBoxDescriptor> &namespaces);
0071     QList<MailBoxDescriptor> queriedNamespaces() const;
0072 
0073 Q_SIGNALS:
0074     void resultReceived(const KIMAP2::MailBoxDescriptor &descriptors, const QList<QByteArray> &flags);
0075 
0076 protected:
0077     void doStart() Q_DECL_OVERRIDE;
0078     void handleResponse(const Message &response) Q_DECL_OVERRIDE;
0079 
0080 private:
0081 
0082     /**
0083     * @brief Converts a mailbox descriptor's name to uppercase if it is the Inbox or an Inbox subfolder.
0084     *  This is according to the RFC3501, 5.1. Mailbox Naming section.
0085     *
0086     * @param descriptor the descriptor to convert, conversion happens in place
0087     **/
0088     void convertInboxName(KIMAP2::MailBoxDescriptor &descriptor);
0089 };
0090 
0091 }
0092 
0093 Q_DECLARE_METATYPE(KIMAP2::MailBoxDescriptor)
0094 
0095 #endif