From: Timo Sirainen Date: Fri, 28 May 2010 11:23:10 +0000 (+0100) Subject: doveadm mailbox *: Removed -7 and -8 parameters from most commands, UTF-8 is used... X-Git-Tag: 2.0.beta6~120 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4ca6f6e2ae7be7c5f04ea5ef176a7c4a47ea3d33;p=thirdparty%2Fdovecot%2Fcore.git doveadm mailbox *: Removed -7 and -8 parameters from most commands, UTF-8 is used always. --HG-- branch : HEAD --- diff --git a/src/doveadm/doveadm-mail-mailbox.c b/src/doveadm/doveadm-mail-mailbox.c index 7fb9b8e761..e983a76f75 100644 --- a/src/doveadm/doveadm-mail-mailbox.c +++ b/src/doveadm/doveadm-mail-mailbox.c @@ -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 rename_cmd_context { 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 @@ doveadm_mailbox_args_to_mutf7(const char *const args[]) 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 @@ doveadm_mailbox_cmd_alloc_size(size_t size) 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 @@ cmd_mailbox_list_run(struct doveadm_mail_cmd_context *_ctx, 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 @@ static void cmd_mailbox_list_init(struct doveadm_mail_cmd_context *_ctx, 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 @@ static struct doveadm_mail_cmd_context *cmd_mailbox_list_alloc(void) 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 @@ static void cmd_mailbox_create_init(struct doveadm_mail_cmd_context *_ctx, 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 @@ static void cmd_mailbox_delete_init(struct doveadm_mail_cmd_context *_ctx, 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 @@ static void cmd_mailbox_rename_init(struct doveadm_mail_cmd_context *_ctx, 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 @@ static void cmd_mailbox_subscribe_init(struct doveadm_mail_cmd_context *_ctx, "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_list = { }; struct doveadm_mail_cmd cmd_mailbox_create = { cmd_mailbox_create_alloc, "mailbox create", - "[-7|-8] [-s] [...]" + "[-s] [...]" }; struct doveadm_mail_cmd cmd_mailbox_delete = { cmd_mailbox_delete_alloc, "mailbox delete", - "[-7|-8] [-s] [...]" + "[-s] [...]" }; struct doveadm_mail_cmd cmd_mailbox_rename = { cmd_mailbox_rename_alloc, "mailbox rename", - "[-7|-8] [-s] " + "[-s] " }; struct doveadm_mail_cmd cmd_mailbox_subscribe = { cmd_mailbox_subscribe_alloc, "mailbox subscribe", - "[-7|-8] [...]" + " [...]" }; struct doveadm_mail_cmd cmd_mailbox_unsubscribe = { cmd_mailbox_unsubscribe_alloc, "mailbox unsubscribe", - "[-7|-8] [...]" + " [...]" }; struct doveadm_cmd doveadm_cmd_mailbox_convert = { cmd_mailbox_convert, "mailbox convert",