]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imapc: Fix handling EXISTS reply to previous mailbox while selecting new mailbox
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 9 Feb 2023 14:21:24 +0000 (16:21 +0200)
committerMarkus Valentin <markus.valentin@open-xchange.com>
Mon, 13 Feb 2023 11:39:34 +0000 (12:39 +0100)
For example if the communication was:

C: a SELECT box1
...
C: b SELECT box2
S: * 10 EXISTS
S: * 1 EXISTS
S: * OK [UIDVALIDITY 1675948459] UIDs valid
S: ...
S: b OK

The first EXISTS is meant for box1, not box2. Fixed by not starting a FETCH
(FLAGS) for the mailbox being selected until the tagged reply is received.

src/lib-storage/index/imapc/imapc-mailbox.c

index 5e3e55a3a8f821bcfd18fbad995b9aa5165eaa21..73a38e27f1bfe26f8181f15873cb134bb5d8287a 100644 (file)
@@ -242,6 +242,9 @@ void imap_mailbox_select_finish(struct imapc_mailbox *mbox)
                mbox->sync_next_lseq = 1;
                imapc_mailbox_init_delayed_trans(mbox);
                imapc_mailbox_fetch_state_finish(mbox);
+       } else {
+               /* We don't know the latest flags, refresh them. */
+               (void)imapc_mailbox_fetch_state(mbox, 1);
        }
        mbox->selected = TRUE;
 }
@@ -310,7 +313,7 @@ imapc_untagged_exists(const struct imapc_untagged_reply *reply,
 
        if (mbox == NULL)
                return;
-       if (mbox->exists_received &&
+       if (IMAPC_MAILBOX_IS_FULLY_SELECTED(mbox) &&
            IMAPC_BOX_HAS_FEATURE(mbox, IMAPC_FEATURE_NO_MSN_UPDATES)) {
                /* ignore all except the first EXISTS reply (returned by
                   SELECT) */
@@ -324,10 +327,7 @@ imapc_untagged_exists(const struct imapc_untagged_reply *reply,
        if (view == NULL)
                view = imapc_mailbox_get_sync_view(mbox);
 
-       if (mbox->selecting) {
-               /* We don't know the latest flags, refresh them. */
-               (void)imapc_mailbox_fetch_state(mbox, 1);
-       } else if (mbox->sync_fetch_first_uid != 1) {
+       if (!mbox->selecting && 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;