Mercurial > dovecot > core-2.2
changeset 21495:5f2cc5e42122
imap: Share mailbox closing code in SELECT/UNSELECT/CLOSE/LOGOUT/deinit
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Sun, 05 Feb 2017 16:24:08 +0200 |
parents | 6291f52aea85 |
children | 8cbee0fe11fd |
files | src/imap/cmd-close.c src/imap/cmd-logout.c src/imap/cmd-select.c src/imap/cmd-unselect.c src/imap/imap-client.c src/imap/imap-commands-util.c src/imap/imap-commands-util.h |
diffstat | 7 files changed, 24 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- 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; }
--- 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.");
--- 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."); }
--- 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; }
--- 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)
--- 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) {
--- 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,