dovecot-2.0: doveadm mailbox *: Removed -7 and -8 parameters fro...

dovecot at dovecot.org dovecot at dovecot.org
Fri May 28 14:25:07 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/2127b6e9096d
changeset: 11410:2127b6e9096d
user:      Timo Sirainen <tss at iki.fi>
date:      Fri May 28 12:23:10 2010 +0100
description:
doveadm mailbox *: Removed -7 and -8 parameters from most commands, UTF-8 is used always.

diffstat:

 src/doveadm/doveadm-mail-mailbox.c |  73 +++++++++++++++++-------------------
 1 files changed, 34 insertions(+), 39 deletions(-)

diffs (183 lines):

diff -r 93eaae8617c8 -r 2127b6e9096d src/doveadm/doveadm-mail-mailbox.c
--- a/src/doveadm/doveadm-mail-mailbox.c	Fri May 28 12:22:46 2010 +0100
+++ b/src/doveadm/doveadm-mail-mailbox.c	Fri May 28 12:23:10 2010 +0100
@@ -14,7 +14,7 @@
 
 struct doveadm_mailbox_cmd_context {
 	struct doveadm_mail_cmd_context ctx;
-	bool mutf7, subscriptions;
+	bool subscriptions;
 };
 
 struct mailbox_cmd_context {
@@ -30,6 +30,7 @@
 struct list_cmd_context {
 	struct doveadm_mailbox_cmd_context ctx;
 	struct mail_search_args *search_args;
+	bool mutf7;
 };
 
 static const char *const *
@@ -53,31 +54,12 @@
 	return array_idx(&dest, 0);
 }
 
-static void
-doveadm_mailbox_args_validate_mutf7(const char *const *args)
-{
-	string_t *str = t_str_new(128);
-	unsigned int i;
-
-	for (i = 0; args[i] != NULL; i++) {
-		if (imap_utf7_to_utf8(args[i], str) < 0)
-			i_fatal("Mailbox name not valid mUTF-7: %s", args[i]);
-		str_truncate(str, 0);
-	}
-}
-
 static bool cmd_mailbox_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
 {
 	struct doveadm_mailbox_cmd_context *ctx =
 		(struct doveadm_mailbox_cmd_context *)_ctx;
 
 	switch (c) {
-	case '7':
-		ctx->mutf7 = TRUE;
-		break;
-	case '8':
-		ctx->mutf7 = FALSE;
-		break;
 	case 's':
 		ctx->subscriptions = TRUE;
 		break;
@@ -95,19 +77,30 @@
 	struct doveadm_mail_cmd_context *ctx;
 
 	ctx = doveadm_mail_cmd_alloc_size(size);
-	ctx->getopt_args = "78s";
+	ctx->getopt_args = "s";
 	ctx->v.parse_arg = cmd_mailbox_parse_arg;
 	return ctx;
 }
 
-static void
-doveadm_mailbox_translate_args(struct doveadm_mailbox_cmd_context *ctx,
-			       const char *const *args[])
+static bool
+cmd_mailbox_list_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
 {
-	if (!ctx->mutf7)
-		*args = doveadm_mailbox_args_to_mutf7(*args);
-	else
-		doveadm_mailbox_args_validate_mutf7(*args);
+	struct list_cmd_context *ctx = (struct list_cmd_context *)_ctx;
+
+	switch (c) {
+	case '7':
+		ctx->mutf7 = TRUE;
+		break;
+	case '8':
+		ctx->mutf7 = FALSE;
+		break;
+	case 's':
+		ctx->ctx.subscriptions = TRUE;
+		break;
+	default:
+		return FALSE;
+	}
+	return TRUE;
 }
 
 static void
@@ -130,7 +123,7 @@
 	iter = doveadm_mail_list_iter_init(user, ctx->search_args, iter_flags);
 	while ((info = doveadm_mail_list_iter_next(iter)) != NULL) {
 		str_truncate(str, 0);
-		if (ctx->ctx.mutf7 || imap_utf7_to_utf8(info->name, str) < 0)
+		if (ctx->mutf7 || imap_utf7_to_utf8(info->name, str) < 0)
 			printf("%s\n", info->name);
 		else
 			printf("%s\n", str_c(str));
@@ -145,7 +138,7 @@
 	struct mail_search_arg *arg;
 	unsigned int i;
 
-	doveadm_mailbox_translate_args(&ctx->ctx, &args);
+	args = doveadm_mailbox_args_to_mutf7(args);
 	ctx->search_args = mail_search_build_init();
 	for (i = 0; args[i] != NULL; i++) {
 		arg = mail_search_build_add(ctx->search_args,
@@ -168,6 +161,8 @@
 	ctx = doveadm_mailbox_cmd_alloc(struct list_cmd_context);
 	ctx->ctx.ctx.v.init = cmd_mailbox_list_init;
 	ctx->ctx.ctx.v.run = cmd_mailbox_list_run;
+	ctx->ctx.ctx.v.parse_arg = cmd_mailbox_list_parse_arg;
+	ctx->ctx.ctx.getopt_args = "78s";
 	return &ctx->ctx.ctx;
 }
 
@@ -222,7 +217,7 @@
 
 	if (args[0] == NULL)
 		doveadm_mail_help_name("mailbox create");
-	doveadm_mailbox_translate_args(&ctx->ctx, &args);
+	args = doveadm_mailbox_args_to_mutf7(args);
 
 	for (i = 0; args[i] != NULL; i++) {
 		name = p_strdup(ctx->ctx.ctx.pool, args[i]);
@@ -284,7 +279,7 @@
 
 	if (args[0] == NULL)
 		doveadm_mail_help_name("mailbox delete");
-	doveadm_mailbox_translate_args(&ctx->ctx, &args);
+	args = doveadm_mailbox_args_to_mutf7(args);
 
 	for (i = 0; args[i] != NULL; i++) {
 		name = p_strdup(ctx->ctx.ctx.pool, args[i]);
@@ -350,7 +345,7 @@
 
 	if (str_array_length(args) != 2)
 		doveadm_mail_help_name("mailbox rename");
-	doveadm_mailbox_translate_args(&ctx->ctx, &args);
+	args = doveadm_mailbox_args_to_mutf7(args);
 
 	ctx->oldname = p_strdup(ctx->ctx.ctx.pool, args[0]);
 	ctx->newname = p_strdup(ctx->ctx.ctx.pool, args[1]);
@@ -406,7 +401,7 @@
 				       "mailbox subscribe" :
 				       "mailbox unsubscribe");
 	}
-	doveadm_mailbox_translate_args(&ctx->ctx, &args);
+	args = doveadm_mailbox_args_to_mutf7(args);
 
 	for (i = 0; args[i] != NULL; i++) {
 		name = p_strdup(ctx->ctx.ctx.pool, args[i]);
@@ -489,23 +484,23 @@
 };
 struct doveadm_mail_cmd cmd_mailbox_create = {
 	cmd_mailbox_create_alloc, "mailbox create",
-	"[-7|-8] [-s] <mailbox> [...]"
+	"[-s] <mailbox> [...]"
 };
 struct doveadm_mail_cmd cmd_mailbox_delete = {
 	cmd_mailbox_delete_alloc, "mailbox delete",
-	"[-7|-8] [-s] <mailbox> [...]"
+	"[-s] <mailbox> [...]"
 };
 struct doveadm_mail_cmd cmd_mailbox_rename = {
 	cmd_mailbox_rename_alloc, "mailbox rename",
-	"[-7|-8] [-s] <old name> <new name>"
+	"[-s] <old name> <new name>"
 };
 struct doveadm_mail_cmd cmd_mailbox_subscribe = {
 	cmd_mailbox_subscribe_alloc, "mailbox subscribe",
-	"[-7|-8] <mailbox> [...]"
+	"<mailbox> [...]"
 };
 struct doveadm_mail_cmd cmd_mailbox_unsubscribe = {
 	cmd_mailbox_unsubscribe_alloc, "mailbox unsubscribe",
-	"[-7|-8] <mailbox> [...]"
+	"<mailbox> [...]"
 };
 struct doveadm_cmd doveadm_cmd_mailbox_convert = {
 	cmd_mailbox_convert, "mailbox convert",


More information about the dovecot-cvs mailing list