From 8fe131f82ce9f648c4b0417414c664535927e50c Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 9 Feb 2023 16:21:24 +0200 Subject: [PATCH] imapc: Fix handling EXISTS reply to previous mailbox while selecting new mailbox 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib-storage/index/imapc/imapc-mailbox.c b/src/lib-storage/index/imapc/imapc-mailbox.c index a7377e2e3d..3e03ad93de 100644 --- a/src/lib-storage/index/imapc/imapc-mailbox.c +++ b/src/lib-storage/index/imapc/imapc-mailbox.c @@ -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; -- 2.47.3