File indexing completed on 2024-05-12 05:17:14
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 "imapset.h" 0012 #include "job.h" 0013 0014 #include <KMime/Content> 0015 #include <KMime/KMimeMessage> 0016 0017 namespace KIMAP 0018 { 0019 class Session; 0020 struct Response; 0021 class IdleJobPrivate; 0022 0023 /** 0024 * Idles the connection to the IMAP server. 0025 * 0026 * This job can be run while the client has no other use 0027 * for the connection, and the server will send updates 0028 * about the selected mailbox. 0029 * 0030 * Note that although the server may send a variety of 0031 * responses while the job is running (including EXPUNGE, 0032 * for example), only RECENT and EXISTS responses are 0033 * actually reported by this job. 0034 * 0035 * The job also processes updates in pairs - if the server 0036 * sends an EXISTS update but not a RECENT one (because 0037 * another client is changing the mailbox contents), this 0038 * job will not report the update. 0039 * 0040 * It only makes sense to run this job when the session is 0041 * in the selected state. 0042 * 0043 * This job requires that the server supports the IDLE 0044 * capability, defined in 0045 * <a href="https://tools.ietf.org/html/rfc2177">RFC 2177</a>. 0046 */ 0047 class KIMAP_EXPORT IdleJob : public Job 0048 { 0049 Q_OBJECT 0050 Q_DECLARE_PRIVATE(IdleJob) 0051 0052 public: 0053 explicit IdleJob(Session *session); 0054 ~IdleJob() override; 0055 0056 /** 0057 * The last mailbox status that was reported. 0058 * 0059 * This is just the session's selected mailbox. 0060 */ 0061 [[nodiscard]] QString lastMailBox() const; 0062 /** 0063 * The last message count that was reported. 0064 * 0065 * The server will send updates about the number of 0066 * messages in the mailbox when that number changes. 0067 * This is the last number it reported. 0068 * 0069 * @return the last message count the server reported, 0070 * or -1 if it has not reported a message count 0071 * since the job started. 0072 */ 0073 [[nodiscard]] int lastMessageCount() const; 0074 /** 0075 * The last recent message count that was reported. 0076 * 0077 * The server will send updates about the number of 0078 * messages in the mailbox that are tagged with \Recent 0079 * when that number changes. This is the last number it 0080 * reported. 0081 * 0082 * @return the last recent message count the server reported, 0083 * or -1 if it has not reported a recent message count 0084 * since the job started. 0085 */ 0086 [[nodiscard]] int lastRecentCount() const; 0087 0088 public Q_SLOTS: 0089 /** 0090 * Stops the idle job. 0091 */ 0092 void stop(); 0093 0094 Q_SIGNALS: 0095 /** 0096 * Signals that the server has notified that the total and 0097 * recent message counts have changed. 0098 * 0099 * @param job this object 0100 * @param mailBox the selected mailbox 0101 * @param messageCount the new total message count reported by the server 0102 * @param recentCount the new "recent message" count reported by the server 0103 */ 0104 void mailBoxStats(KIMAP::IdleJob *job, const QString &mailBox, int messageCount, int recentCount); 0105 0106 /** 0107 * Signals that the server has notified that the some messages flags 0108 * have changed 0109 * 0110 * @param job this object 0111 * @param uid UID of message that has changed 0112 * @since 4.12 0113 */ 0114 void mailBoxMessageFlagsChanged(KIMAP::IdleJob *job, qint64 uid); 0115 0116 protected: 0117 void doStart() override; 0118 void handleResponse(const Response &response) override; 0119 0120 private: 0121 Q_PRIVATE_SLOT(d_func(), void emitStats()) 0122 Q_PRIVATE_SLOT(d_func(), void resetTimeout()) 0123 }; 0124 0125 }