<commit_before>/* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */

#include "common.h"
#include "commands.h"
#include "imap-expunge.h"

static void cmd_close_finish(struct client *client)
{
	client_search_updates_free(client);
	if (mailbox_close(&client->mailbox) < 0) {
		client_send_untagged_storage_error(client,
			mailbox_get_storage(client->mailbox));
	}
	client_update_mailbox_flags(client, NULL);
}

bool cmd_close(struct client_command_context *cmd)
{
	struct client *client = cmd->client;
	struct mailbox *mailbox = client->mailbox;
	struct mail_storage *storage;
	int ret;

	if (!client_verify_open_mailbox(cmd))
		return TRUE;

	i_assert(client->mailbox_change_lock == NULL);
	client->mailbox_change_lock = cmd;

	storage = mailbox_get_storage(mailbox);
	if ((ret = imap_expunge(mailbox, NULL)) < 0)
		client_send_untagged_storage_error(client, storage);

	if ((client->enabled_features & MAILBOX_FEATURE_QRESYNC) != 0 &&
	    ret > 0) {
		/* we expunged something. since we're sending updated
		   HIGHESTMODSEQ make sure the client sees all changes up to
		   it by syncing the mailbox one last time. We wouldn't need
		   to include our own expunge in there, but it's too much
		   trouble to hide it. */
		return cmd_sync(cmd, MAILBOX_SYNC_FLAG_EXPUNGE,
				IMAP_SYNC_FLAG_SAFE, "OK Close completed.");
	} else {
		if (mailbox_sync(mailbox, 0, 0, NULL) < 0)
			client_send_untagged_storage_error(client, storage);
		cmd_close_finish(client);
		client_send_tagline(cmd, "OK Close completed.");
		return TRUE;
	}
}<commit_msg>CLOSE: Don't send any mailbox changes or HIGHESTMODSEQ to client. Also the previous code wasn't really even closing the mailbox.<commit_after>/* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */

#include "common.h"
#include "commands.h"
#include "imap-expunge.h"

bool cmd_close(struct client_command_context *cmd)
{
	struct client *client = cmd->client;
	struct mailbox *mailbox = client->mailbox;
	struct mail_storage *storage;
	int ret;

	if (!client_verify_open_mailbox(cmd))
		return TRUE;

	i_assert(client->mailbox_change_lock == NULL);
	client->mailbox = NULL;

	storage = mailbox_get_storage(mailbox);
	if ((ret = imap_expunge(mailbox, NULL)) < 0)
		client_send_untagged_storage_error(client, storage);
	if (mailbox_sync(mailbox, 0, 0, NULL) < 0)
		client_send_untagged_storage_error(client, storage);

	if (mailbox_close(&mailbox) < 0)
		client_send_untagged_storage_error(client, storage);
	client_update_mailbox_flags(client, NULL);

	client_send_tagline(cmd, "OK Close completed.");
	return TRUE;
}
{'fraction_non_alphanumeric': 0.10760953112990007, 'fraction_numerical': 0.010760953112990008, 'mean_word_length': 5.443069306930693, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2184840', 'n_tokens_mistral': 961, 'n_tokens_neox': 885, 'n_words': 227}