- if ((idata->status != IMAP_FATAL) &&
- (idata->state == IMAP_SELECTED) && (ctx == idata->ctx)) {
- if (!(idata->noclose) && imap_exec (idata, "CLOSE", 0))
+ if (ctx == idata->ctx) {
+ if (idata->state == IMAP_SELECTED) {
+ /* mx_close_mailbox won't sync if there are no deleted messages
+ * and the mailbox is unchanged, so we may have to close here */
+ if (idata->status != IMAP_FATAL && !ctx->deleted &&
+ imap_exec (idata, "CLOSE", 0))