changeset 20218:bb25b02501b8

doveadm mailbox delete: Added --unsafe option.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 27 May 2016 22:18:17 +0300
parents f8e7e20407d4
children d0a8832389fe
files src/doveadm/doveadm-mail-mailbox.c
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/doveadm-mail-mailbox.c	Fri May 27 22:15:07 2016 +0300
+++ b/src/doveadm/doveadm-mail-mailbox.c	Fri May 27 22:18:17 2016 +0300
@@ -35,6 +35,7 @@
 	ARRAY_TYPE(const_string) mailboxes;
 	bool recursive;
 	bool require_empty;
+	bool unsafe;
 };
 
 struct rename_cmd_context {
@@ -335,8 +336,11 @@
 	const char *const *namep;
 	ARRAY_TYPE(const_string) recursive_mailboxes;
 	const ARRAY_TYPE(const_string) *mailboxes = &ctx->mailboxes;
+	enum mailbox_flags mailbox_flags = 0;
 	int ret = 0, ret2;
 
+	if (ctx->unsafe)
+		mailbox_flags |= MAILBOX_FLAG_DELETE_UNSAFE;
 	if (ctx->recursive) {
 		t_array_init(&recursive_mailboxes, 32);
 		array_foreach(&ctx->mailboxes, namep) {
@@ -356,7 +360,7 @@
 		const char *name = *namep;
 
 		ns = mail_namespace_find(user->namespaces, name);
-		box = mailbox_alloc(ns->list, name, 0);
+		box = mailbox_alloc(ns->list, name, mailbox_flags);
 		storage = mailbox_get_storage(box);
 		ret2 = ctx->require_empty ? mailbox_delete_empty(box) :
 			mailbox_delete(box);
@@ -412,6 +416,9 @@
 	case 'e':
 		ctx->require_empty = TRUE;
 		break;
+	case 'Z':
+		ctx->unsafe = TRUE;
+		break;
 	default:
 		return FALSE;
 	}
@@ -426,7 +433,7 @@
 	ctx->ctx.ctx.v.init = cmd_mailbox_delete_init;
 	ctx->ctx.ctx.v.run = cmd_mailbox_delete_run;
 	ctx->ctx.ctx.v.parse_arg = cmd_mailbox_delete_parse_arg;
-	ctx->ctx.ctx.getopt_args = "ers";
+	ctx->ctx.ctx.getopt_args = "ersZ";
 	p_array_init(&ctx->mailboxes, ctx->ctx.ctx.pool, 16);
 	return &ctx->ctx.ctx;
 }
@@ -687,12 +694,13 @@
 struct doveadm_cmd_ver2 doveadm_cmd_mailbox_delete_ver2 = {
 	.name = "mailbox delete",
 	.mail_cmd = cmd_mailbox_delete_alloc,
-	.usage = DOVEADM_CMD_MAIL_USAGE_PREFIX"[-e] [-r] [-s] <mailbox> [...]",
+	.usage = DOVEADM_CMD_MAIL_USAGE_PREFIX"[-e] [-r] [-s] [-Z] <mailbox> [...]",
 DOVEADM_CMD_PARAMS_START
 DOVEADM_CMD_MAIL_COMMON
 DOVEADM_CMD_PARAM('e', "require-empty", CMD_PARAM_BOOL, 0)
 DOVEADM_CMD_PARAM('s', "subscriptions", CMD_PARAM_BOOL, 0)
 DOVEADM_CMD_PARAM('r', "recursive", CMD_PARAM_BOOL, 0)
+DOVEADM_CMD_PARAM('Z', "unsafe", CMD_PARAM_BOOL, 0)
 DOVEADM_CMD_PARAM('\0', "mailbox", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
 DOVEADM_CMD_PARAMS_END
 };