#include "imapc-client.h"
+#define IMAPC_CLIENT_IDLE_SEND_DELAY_MSECS 100
+
struct imapc_client_connection {
struct imapc_connection *conn;
struct imapc_client_mailbox *box;
struct imapc_client *client;
struct imapc_connection *conn;
struct imapc_msgmap *msgmap;
+ struct timeout *to_send_idle;
void (*reopen_callback)(void *context);
void *reopen_context;
}
imapc_msgmap_deinit(&box->msgmap);
+ if (box->to_send_idle != NULL)
+ timeout_remove(&box->to_send_idle);
i_free(box);
}
return box->msgmap;
}
-void imapc_client_mailbox_idle(struct imapc_client_mailbox *box)
+static void imapc_client_mailbox_idle_send(struct imapc_client_mailbox *box)
{
+ timeout_remove(&box->to_send_idle);
if (imapc_client_mailbox_is_opened(box))
imapc_connection_idle(box->conn);
+}
+
+void imapc_client_mailbox_idle(struct imapc_client_mailbox *box)
+{
+ /* send the IDLE with a delay to avoid unnecessary IDLEs that are
+ immediately aborted */
+ if (box->to_send_idle == NULL && imapc_client_mailbox_is_opened(box)) {
+ box->to_send_idle =
+ timeout_add_short(IMAPC_CLIENT_IDLE_SEND_DELAY_MSECS,
+ imapc_client_mailbox_idle_send, box);
+ }
box->reconnect_ok = TRUE;
}
}
capabilities = imapc_client_get_capabilities(mbox->storage->client->client);
- if ((capabilities & IMAPC_CAPABILITY_IDLE) == 0) {
- /* IDLE not supported. do NOOP to get latest changes
- before starting sync. */
+ if ((capabilities & IMAPC_CAPABILITY_IDLE) == 0 ||
+ (flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0) {
+ /* do NOOP to make sure we have the latest changes before
+ starting sync. this is necessary either because se don't
+ support IDLE at all, or because we want to be sure that we
+ have the latest changes (IDLE is started with a small delay,
+ so we might not actually even be in IDLE right not) */
imapc_mailbox_noop(mbox);
}