# HG changeset patch # User Timo Sirainen # Date 1486304648 -7200 # Node ID 5f2cc5e42122f4a71216e5cd1dd23caeddbbf13b # Parent 6291f52aea855f42a518a027178c23325f03326f imap: Share mailbox closing code in SELECT/UNSELECT/CLOSE/LOGOUT/deinit diff -r 6291f52aea85 -r 5f2cc5e42122 src/imap/cmd-close.c --- a/src/imap/cmd-close.c Sun Feb 05 16:23:35 2017 +0200 +++ b/src/imap/cmd-close.c Sun Feb 05 16:24:08 2017 +0200 @@ -16,7 +16,6 @@ return TRUE; i_assert(client->mailbox_change_lock == NULL); - client->mailbox = NULL; storage = mailbox_get_storage(mailbox); if (imap_expunge(mailbox, NULL, &client->expunged_count) < 0) { @@ -31,11 +30,7 @@ if (mailbox_sync(mailbox, 0) < 0) client_send_untagged_storage_error(client, storage); - client_search_updates_free(client); - - mailbox_free(&mailbox); - client_update_mailbox_flags(client, NULL); - + imap_client_close_mailbox(client); client_send_tagline(cmd, tagged_reply); return TRUE; } diff -r 6291f52aea85 -r 5f2cc5e42122 src/imap/cmd-logout.c --- a/src/imap/cmd-logout.c Sun Feb 05 16:23:35 2017 +0200 +++ b/src/imap/cmd-logout.c Sun Feb 05 16:24:08 2017 +0200 @@ -11,11 +11,10 @@ client_send_line(client, "* BYE Logging out"); if (client->mailbox != NULL) { - client_search_updates_free(client); /* this could be done at client_disconnect() as well, but eg. mbox rewrite takes a while so the waiting is better to happen before "OK" message. */ - mailbox_free(&client->mailbox); + imap_client_close_mailbox(client); } client_send_tagline(cmd, "OK Logout completed."); diff -r 6291f52aea85 -r 5f2cc5e42122 src/imap/cmd-select.c --- a/src/imap/cmd-select.c Sun Feb 05 16:23:35 2017 +0200 +++ b/src/imap/cmd-select.c Sun Feb 05 16:24:08 2017 +0200 @@ -363,16 +363,10 @@ static void close_selected_mailbox(struct client *client) { - struct mailbox *box; - if (client->mailbox == NULL) return; - client_search_updates_free(client); - box = client->mailbox; - client->mailbox = NULL; - - mailbox_free(&box); + imap_client_close_mailbox(client); /* CLOSED response is required by QRESYNC */ client_send_line(client, "* OK [CLOSED] Previous mailbox closed."); } diff -r 6291f52aea85 -r 5f2cc5e42122 src/imap/cmd-unselect.c --- a/src/imap/cmd-unselect.c Sun Feb 05 16:23:35 2017 +0200 +++ b/src/imap/cmd-unselect.c Sun Feb 05 16:24:08 2017 +0200 @@ -6,19 +6,13 @@ bool cmd_unselect(struct client_command_context *cmd) { struct client *client = cmd->client; - struct mailbox *mailbox = client->mailbox; if (!client_verify_open_mailbox(cmd)) return TRUE; - client_search_updates_free(client); + i_assert(client->mailbox_change_lock == NULL); - i_assert(client->mailbox_change_lock == NULL); - client->mailbox = NULL; - - mailbox_free(&mailbox); - client_update_mailbox_flags(client, NULL); - + imap_client_close_mailbox(client); client_send_tagline(cmd, "OK Unselect completed."); return TRUE; } diff -r 6291f52aea85 -r 5f2cc5e42122 src/imap/imap-client.c --- a/src/imap/imap-client.c Sun Feb 05 16:23:35 2017 +0200 +++ b/src/imap/imap-client.c Sun Feb 05 16:24:08 2017 +0200 @@ -374,10 +374,8 @@ if (client->input_lock != NULL) client_command_cancel(&client->input_lock); - if (client->mailbox != NULL) { - client_search_updates_free(client); - mailbox_free(&client->mailbox); - } + if (client->mailbox != NULL) + imap_client_close_mailbox(client); if (client->notify_ctx != NULL) imap_notify_deinit(&client->notify_ctx); if (client->urlauth_ctx != NULL) diff -r 6291f52aea85 -r 5f2cc5e42122 src/imap/imap-commands-util.c --- a/src/imap/imap-commands-util.c Sun Feb 05 16:23:35 2017 +0200 +++ b/src/imap/imap-commands-util.c Sun Feb 05 16:24:08 2017 +0200 @@ -74,6 +74,21 @@ } } +void imap_client_close_mailbox(struct client *client) +{ + struct mailbox *box; + + i_assert(client->mailbox != NULL); + + client_search_updates_free(client); + + box = client->mailbox; + client->mailbox = NULL; + + mailbox_free(&box); + client_update_mailbox_flags(client, NULL); +} + int client_open_save_dest_box(struct client_command_context *cmd, const char *name, struct mailbox **destbox_r) { diff -r 6291f52aea85 -r 5f2cc5e42122 src/imap/imap-commands-util.h --- a/src/imap/imap-commands-util.h Sun Feb 05 16:23:35 2017 +0200 +++ b/src/imap/imap-commands-util.h Sun Feb 05 16:24:08 2017 +0200 @@ -20,6 +20,8 @@ /* Returns TRUE if mailbox is selected. If not, sends "No mailbox selected" error message to client. */ bool client_verify_open_mailbox(struct client_command_context *cmd); +/* Close the selected mailbox. */ +void imap_client_close_mailbox(struct client *client); /* Open APPEND/COPY destination mailbox. */ int client_open_save_dest_box(struct client_command_context *cmd,