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

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

bool cmd_delete(struct client_command_context *cmd)
{
	struct client *client = cmd->client;
	struct mail_namespace *ns;
	struct mail_storage *storage;
	struct mailbox *mailbox;
	const char *name;

	/* <mailbox> */
	if (!client_read_string_args(cmd, 1, &name))
		return FALSE;

	if (strcasecmp(name, "INBOX") == 0) {
		/* INBOX can't be deleted */
		client_send_tagline(cmd, "NO INBOX can't be deleted.");
		return TRUE;
	}

	ns = client_find_namespace(cmd, &name);
	if (ns == NULL)
		return TRUE;

	mailbox = client->mailbox;
	if (mailbox != NULL && mailbox_get_namespace(mailbox) == ns &&
	    strcmp(mailbox_get_name(mailbox), name) == 0) {
		/* deleting selected mailbox. close it first */
		client_search_updates_free(client);
		storage = mailbox_get_storage(mailbox);
		client->mailbox = NULL;

		mailbox_close(&mailbox);
	}

	if ((client->workarounds & WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
	    *name != '\0' &&
	    name[strlen(name)-1] == mailbox_list_get_hierarchy_sep(ns->list)) {
		/* drop the extra trailing hierarchy separator */
		name = t_strndup(name, strlen(name)-1);
	}

	if (mailbox_list_delete_mailbox(ns->list, name) < 0)
		client_send_list_error(cmd, ns->list);
	else {<commit_msg>imap delete: Use mailbox_backends_equal() for finding if we're deleting selected mailbox.<commit_after>/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */

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

bool cmd_delete(struct client_command_context *cmd)
{
	struct client *client = cmd->client;
	struct mail_namespace *ns;
	struct mailbox *mailbox;
	const char *name;

	/* <mailbox> */
	if (!client_read_string_args(cmd, 1, &name))
		return FALSE;

	if (strcasecmp(name, "INBOX") == 0) {
		/* INBOX can't be deleted */
		client_send_tagline(cmd, "NO INBOX can't be deleted.");
		return TRUE;
	}

	ns = client_find_namespace(cmd, &name);
	if (ns == NULL)
		return TRUE;

	mailbox = mailbox_alloc(ns->list, name, NULL, 0);
	if (client->mailbox != NULL &&
	    mailbox_backends_equal(mailbox, client->mailbox)) {
		/* deleting selected mailbox. close it first */
		client_search_updates_free(client);
		mailbox_close(&client->mailbox);
	}
	mailbox_close(&mailbox);

	if ((client->workarounds & WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
	    *name != '\0' &&
	    name[strlen(name)-1] == mailbox_list_get_hierarchy_sep(ns->list)) {
		/* drop the extra trailing hierarchy separator */
		name = t_strndup(name, strlen(name)-1);
	}

	if (mailbox_list_delete_mailbox(ns->list, name) < 0)
		client_send_list_error(cmd, ns->list);
	else {
{'fraction_non_alphanumeric': 0.14238288454444853, 'fraction_numerical': 0.011803762449280709, 'mean_word_length': 4.603305785123967, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '3789007', 'n_tokens_mistral': 1052, 'n_tokens_neox': 970, 'n_words': 228}