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

0001 /*
0002     SPDX-FileCopyrightText: 2009 Kevin Ottens <ervin@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "kimap_export.h"
0010 
0011 #include "fetchjob.h"
0012 #include "job.h"
0013 
0014 namespace KIMAP
0015 {
0016 class Session;
0017 struct Response;
0018 class SelectJobPrivate;
0019 class ImapSet;
0020 
0021 class KIMAP_EXPORT SelectJob : public Job
0022 {
0023     Q_OBJECT
0024     Q_DECLARE_PRIVATE(SelectJob)
0025 
0026     friend class SessionPrivate;
0027 
0028 public:
0029     explicit SelectJob(Session *session);
0030     ~SelectJob() override;
0031 
0032     void setMailBox(const QString &mailBox);
0033     [[nodiscard]] QString mailBox() const;
0034 
0035     void setOpenReadOnly(bool readOnly);
0036     /**
0037      * @return Returns whether the mailbox is opened in read-only mode. Note
0038      * that this can return true even if setOpenReadOnly() was set to false,
0039      * as the mailbox may be read-only on the server.
0040      */
0041     [[nodiscard]] bool isOpenReadOnly() const;
0042 
0043     [[nodiscard]] QList<QByteArray> flags() const;
0044     [[nodiscard]] QList<QByteArray> permanentFlags() const;
0045 
0046     [[nodiscard]] int messageCount() const;
0047     [[nodiscard]] int recentCount() const;
0048     [[nodiscard]] int firstUnseenIndex() const;
0049 
0050     [[nodiscard]] qint64 uidValidity() const;
0051     [[nodiscard]] qint64 nextUid() const;
0052 
0053     /**
0054      * @return Highest mod-sequence value of all messages in the mailbox or 0
0055      * if the server does not have CONDSTORE capability (RFC4551) or does not
0056      * support persistent storage of mod-sequences.
0057      *
0058      * @since 4.12
0059      */
0060     [[nodiscard]] quint64 highestModSequence() const;
0061 
0062     /**
0063      * Whether to append CONDSTORE parameter to the SELECT command.
0064      *
0065      * This option is false by default and can be enabled only when server
0066      * has CONDSTORE capability (RFC4551), otherwise the SELECT command will
0067      * fail.
0068      *
0069      * @since 4.12
0070      */
0071     void setCondstoreEnabled(bool enable);
0072 
0073     /**
0074      * Returns whether the CONDSTORE parameter will be appended to SELECT command
0075      *
0076      * @since 4.12
0077      */
0078     [[nodiscard]] bool condstoreEnabled() const;
0079 
0080     /**
0081      * Set Quick Resynchronization parameters.
0082      *
0083      * Requires that the server supports the QRESYNC extension as defined in RFC5162
0084      * and the QRESYNC extension has been enabled via EnableJob.
0085      *
0086      * Using this option implies enabling CONDSTORE.
0087      *
0088      * @param lastUidvalidity Last UIDValidity value known to the client
0089      * @param lastModseq Last modification sequence number known to the client
0090      * @param knownUids List of all UIDs known to the client (optional).
0091      *
0092      * @see KIMAP::EnableJob
0093      */
0094     void setQResync(qint64 lastUidvalidity, quint64 lastModseq, const ImapSet &knownUids = ImapSet{});
0095 
0096 Q_SIGNALS:
0097     /**
0098      * Emitted when the server provides a list of UIDs that have vanished since last sync.
0099      *
0100      * This feature requires that the QRESYNC parameters have been provided
0101      * to the SELECT command. This signal may not be emitted if no messages
0102      * have been expunged since the last check.
0103      *
0104      * @see setQResync()
0105      * @since 5.16
0106      */
0107     void vanished(const KIMAP::ImapSet &set);
0108 
0109     /**
0110      * Emitted when the server provides a list of messages that have changed or appeared
0111      * in the mailbox since the last sync.
0112      *
0113      * This feature requires that the QRESYNC parameters have been provided
0114      * to the SELECT command. The signal may not be emitted if no messages
0115      * have been modified or appended to the mailbox.
0116      *
0117      * @see setQResync()
0118      * @since 5.16
0119      */
0120     void modified(const QMap<qint64, KIMAP::Message> &messages);
0121 
0122 protected:
0123     void doStart() override;
0124     void handleResponse(const Response &response) override;
0125 };
0126 
0127 }