]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imapc: Delay fetching state after untagged exists reply
authorMarkus Valentin <markus.valentin@open-xchange.com>
Thu, 24 Feb 2022 14:31:39 +0000 (15:31 +0100)
committerMarkus Valentin <markus.valentin@open-xchange.com>
Mon, 14 Mar 2022 13:06:49 +0000 (14:06 +0100)
src/lib-storage/index/imapc/imapc-mailbox.c
src/lib-storage/index/imapc/imapc-storage.h
src/lib-storage/index/imapc/imapc-sync.c

index 3f8c504e9cf7b9ee3f289c66d8ad321c9c90154f..f6b318b0bb25de7c56a528c467f02cbca09e0b07 100644 (file)
@@ -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);
 }
index d5e51bcb1b29c53b0f08abe28d0848da27779648..e02c5687e46a5c51f9c61db4a125a85d7feb8371 100644 (file)
@@ -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
index f9ac885daf5cc271a81c607d745d1db36e745a28..31301217876ca5fe649a9f993d460da8eb5b69dd 100644 (file)
@@ -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);