From: Markus Valentin Date: Thu, 24 Feb 2022 14:31:39 +0000 (+0100) Subject: imapc: Delay fetching state after untagged exists reply X-Git-Tag: 2.3.19~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f5fc15b1b1e69fc59e107e4e4754a3701973c098;p=thirdparty%2Fdovecot%2Fcore.git imapc: Delay fetching state after untagged exists reply --- diff --git a/src/lib-storage/index/imapc/imapc-mailbox.c b/src/lib-storage/index/imapc/imapc-mailbox.c index 3f8c504e9c..f6b318b0bb 100644 --- a/src/lib-storage/index/imapc/imapc-mailbox.c +++ b/src/lib-storage/index/imapc/imapc-mailbox.c @@ -214,6 +214,7 @@ imapc_mailbox_fetch_state_callback(const struct imapc_command_reply *reply, struct imapc_mailbox *mbox = context; mbox->state_fetching_uid1 = FALSE; + mbox->delayed_untagged_exists = FALSE; imapc_client_stop(mbox->storage->client->client); switch (reply->state) { @@ -245,7 +246,7 @@ void imap_mailbox_select_finish(struct imapc_mailbox *mbox) mbox->selected = TRUE; } -static void +bool imapc_mailbox_fetch_state(struct imapc_mailbox *mbox, uint32_t first_uid) { struct imapc_command *cmd; @@ -255,11 +256,11 @@ imapc_mailbox_fetch_state(struct imapc_mailbox *mbox, uint32_t first_uid) just make sure everything is expunged in local index. Delay calling imapc_mailbox_fetch_state_finish() until SELECT finishes, so we see the updated UIDNEXT. */ - return; + return FALSE; } if (mbox->state_fetching_uid1) { /* retrying after reconnection - don't send duplicate */ - return; + return FALSE; } string_t *str = t_str_new(64); @@ -297,6 +298,7 @@ imapc_mailbox_fetch_state(struct imapc_mailbox *mbox, uint32_t first_uid) } mbox->state_fetching_uid1 = first_uid == 1; imapc_command_send(cmd, str_c(str)); + return TRUE; } static void @@ -305,7 +307,6 @@ imapc_untagged_exists(const struct imapc_untagged_reply *reply, { struct mail_index_view *view; uint32_t exists_count = reply->num; - const struct mail_index_header *hdr; if (mbox == NULL) return; @@ -325,11 +326,12 @@ imapc_untagged_exists(const struct imapc_untagged_reply *reply, if (mbox->selecting) { /* We don't know the latest flags, refresh them. */ - imapc_mailbox_fetch_state(mbox, 1); + (void)imapc_mailbox_fetch_state(mbox, 1); } else if (mbox->sync_fetch_first_uid != 1) { + const struct mail_index_header *hdr; hdr = mail_index_get_header(view); mbox->sync_fetch_first_uid = hdr->next_uid; - imapc_mailbox_fetch_state(mbox, hdr->next_uid); + mbox->delayed_untagged_exists = TRUE; } imapc_mailbox_idle_notify(mbox); } diff --git a/src/lib-storage/index/imapc/imapc-storage.h b/src/lib-storage/index/imapc/imapc-storage.h index d5e51bcb1b..e02c5687e4 100644 --- a/src/lib-storage/index/imapc/imapc-storage.h +++ b/src/lib-storage/index/imapc/imapc-storage.h @@ -181,6 +181,7 @@ struct imapc_mailbox { bool state_fetching_uid1:1; bool state_fetched_success:1; bool rollback_pending:1; + bool delayed_untagged_exists:1; }; struct imapc_simple_context { @@ -262,5 +263,6 @@ void imapc_untagged_fetch_update_flags(struct imapc_mailbox *mbox, struct imapc_untagged_fetch_ctx *ctx, struct mail_index_view *view, uint32_t lseq); +bool imapc_mailbox_fetch_state(struct imapc_mailbox *mbox, uint32_t first_uid); #endif diff --git a/src/lib-storage/index/imapc/imapc-sync.c b/src/lib-storage/index/imapc/imapc-sync.c index f9ac885daf..3130121787 100644 --- a/src/lib-storage/index/imapc/imapc-sync.c +++ b/src/lib-storage/index/imapc/imapc-sync.c @@ -477,6 +477,14 @@ imapc_sync_begin(struct imapc_mailbox *mbox, mbox->syncing = TRUE; mbox->sync_ctx = ctx; + + if (mbox->delayed_untagged_exists) { + bool fetch_send = imapc_mailbox_fetch_state(mbox, + mbox->min_append_uid); + while (fetch_send && mbox->delayed_untagged_exists) + imapc_mailbox_run(mbox); + } + if (!mbox->box.deleting) imapc_sync_index(ctx);