From: Marco Bettini Date: Tue, 18 Nov 2025 10:30:14 +0000 (+0000) Subject: imapc: Handle the response to UNSELECT on the remote side X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=81ba8dda26fdac6160ae040b9843e9f3947bee4f;p=thirdparty%2Fdovecot%2Fcore.git imapc: Handle the response to UNSELECT on the remote side --- diff --git a/src/lib-imap-client/imapc-client.h b/src/lib-imap-client/imapc-client.h index 34ab1a2d75..27409f1e2f 100644 --- a/src/lib-imap-client/imapc-client.h +++ b/src/lib-imap-client/imapc-client.h @@ -57,7 +57,9 @@ enum imapc_command_flags { /* This is the LOGOUT command. Use a small timeout for it. */ IMAPC_COMMAND_FLAG_LOGOUT = 0x08, /* Command is being resent after a reconnection. */ - IMAPC_COMMAND_FLAG_RECONNECTED = 0x10 + IMAPC_COMMAND_FLAG_RECONNECTED = 0x10, + /* The command unselects the mailbox (UNSELECT) */ + IMAPC_COMMAND_FLAG_UNSELECT = 0x20, }; struct imapc_command_reply { diff --git a/src/lib-imap-client/imapc-connection.c b/src/lib-imap-client/imapc-connection.c index fc6dbd357a..f6517a427e 100644 --- a/src/lib-imap-client/imapc-connection.c +++ b/src/lib-imap-client/imapc-connection.c @@ -1585,7 +1585,10 @@ static int imapc_connection_input_tagged(struct imapc_connection *conn) conn->selected_box != NULL) { /* EXAMINE/SELECT failed: mailbox is no longer selected */ imapc_connection_mailbox_closed(conn->selected_box, TRUE); - } + } else if (reply.state == IMAPC_COMMAND_STATE_OK && + (cmd->flags & IMAPC_COMMAND_FLAG_UNSELECT) != 0) { + i_free_and_null(conn->selected_on_server); + } if (conn->reconnect_command_count > 0 && (cmd->flags & IMAPC_COMMAND_FLAG_RECONNECTED) != 0) { diff --git a/src/lib-storage/index/imapc/imapc-storage.c b/src/lib-storage/index/imapc/imapc-storage.c index cc139aa49d..9edfc302d2 100644 --- a/src/lib-storage/index/imapc/imapc-storage.c +++ b/src/lib-storage/index/imapc/imapc-storage.c @@ -1165,11 +1165,13 @@ int imapc_server_unselect(struct imapc_storage_client *client) struct imapc_command *cmd = imapc_client_cmd(client->client, imapc_simple_callback, &sctx); - imapc_command_set_flags(cmd, IMAPC_COMMAND_FLAG_SELECT); - if ((caps & IMAPC_CAPABILITY_UNSELECT) != 0) + if ((caps & IMAPC_CAPABILITY_UNSELECT) != 0) { + imapc_command_set_flags(cmd, IMAPC_COMMAND_FLAG_UNSELECT); imapc_command_sendf(cmd, "UNSELECT"); - else + } else { + imapc_command_set_flags(cmd, IMAPC_COMMAND_FLAG_SELECT); imapc_command_sendf(cmd, "SELECT \"~~~\""); + } imapc_simple_run(&sctx, &cmd); return 0;