From: Aki Tuomi Date: Thu, 18 Feb 2016 07:27:10 +0000 (+0200) Subject: doveadm: Code cleanup - move code to doveadm_mail_cmd_exec() X-Git-Tag: 2.2.22.rc1~158 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1d689069fcd18f777b5f52736b150a79232eb48a;p=thirdparty%2Fdovecot%2Fcore.git doveadm: Code cleanup - move code to doveadm_mail_cmd_exec() No functional changes. --- diff --git a/src/doveadm/doveadm-mail.c b/src/doveadm/doveadm-mail.c index d481c22682..0770b6be38 100644 --- a/src/doveadm/doveadm-mail.c +++ b/src/doveadm/doveadm-mail.c @@ -534,12 +534,66 @@ doveadm_mail_cmd_init(const struct doveadm_mail_cmd *cmd, return ctx; } +static void +doveadm_mail_cmd_exec(struct doveadm_mail_cmd_context *ctx, char *argv[], + const char *wildcard_user) +{ + int ret; + const char *error; + + if (ctx->v.preinit != NULL) + ctx->v.preinit(ctx); + + ctx->iterate_single_user = + !ctx->iterate_all_users && wildcard_user == NULL; + if (doveadm_print_is_initialized() && !ctx->iterate_single_user) { + doveadm_print_header("username", "Username", + DOVEADM_PRINT_HEADER_FLAG_STICKY | + DOVEADM_PRINT_HEADER_FLAG_HIDE_TITLE); + } + + if (ctx->iterate_single_user) { + struct mail_storage_service_input input; + + if (ctx->cur_username == NULL) + i_fatal_status(EX_USAGE, "USER environment is missing and -u option not used"); + + memset(&input, 0, sizeof(input)); + input.service = "doveadm"; + input.username = ctx->cur_username; + ret = doveadm_mail_single_user(ctx, &input, &error); + if (ret < 0) + i_fatal("%s", error); + else if (ret == 0) + i_fatal_status(EX_NOUSER, "User doesn't exist"); + } else { + ctx->service_flags |= MAIL_STORAGE_SERVICE_FLAG_TEMP_PRIV_DROP; + doveadm_mail_all_users(ctx, argv, wildcard_user); + } + if (ctx->search_args != NULL) + mail_search_args_unref(&ctx->search_args); + doveadm_mail_server_flush(); + ctx->v.deinit(ctx); + doveadm_print_flush(); + + /* service deinit unloads mail plugins, so do it late */ + mail_storage_service_deinit(&ctx->storage_service); + + if (ctx->users_list_input != NULL) + i_stream_unref(&ctx->users_list_input); + if (ctx->cmd_input != NULL) + i_stream_unref(&ctx->cmd_input); + if (ctx->exit_code != 0) + doveadm_exit_code = ctx->exit_code; + pool_unref(&ctx->pool); +} + static void doveadm_mail_cmd(const struct doveadm_mail_cmd *cmd, int argc, char *argv[]) { struct doveadm_mail_cmd_context *ctx; - const char *getopt_args, *wildcard_user, *error; - int ret, c; + const char *getopt_args, *wildcard_user; + int c; ctx = doveadm_mail_cmd_init(cmd, doveadm_settings); ctx->full_args = (const void *)(argv + 1); @@ -595,51 +649,7 @@ doveadm_mail_cmd(const struct doveadm_mail_cmd *cmd, int argc, char *argv[]) cmd->name, argv[0]); } ctx->args = (const void *)argv; - if (ctx->v.preinit != NULL) - ctx->v.preinit(ctx); - - ctx->iterate_single_user = - !ctx->iterate_all_users && wildcard_user == NULL; - if (doveadm_print_is_initialized() && !ctx->iterate_single_user) { - doveadm_print_header("username", "Username", - DOVEADM_PRINT_HEADER_FLAG_STICKY | - DOVEADM_PRINT_HEADER_FLAG_HIDE_TITLE); - } - - if (ctx->iterate_single_user) { - struct mail_storage_service_input input; - - if (ctx->cur_username == NULL) - i_fatal_status(EX_USAGE, "USER environment is missing and -u option not used"); - - memset(&input, 0, sizeof(input)); - input.service = "doveadm"; - input.username = ctx->cur_username; - ret = doveadm_mail_single_user(ctx, &input, &error); - if (ret < 0) - i_fatal("%s", error); - else if (ret == 0) - i_fatal_status(EX_NOUSER, "User doesn't exist"); - } else { - ctx->service_flags |= MAIL_STORAGE_SERVICE_FLAG_TEMP_PRIV_DROP; - doveadm_mail_all_users(ctx, argv, wildcard_user); - } - if (ctx->search_args != NULL) - mail_search_args_unref(&ctx->search_args); - doveadm_mail_server_flush(); - ctx->v.deinit(ctx); - doveadm_print_flush(); - - /* service deinit unloads mail plugins, so do it late */ - mail_storage_service_deinit(&ctx->storage_service); - - if (ctx->users_list_input != NULL) - i_stream_unref(&ctx->users_list_input); - if (ctx->cmd_input != NULL) - i_stream_unref(&ctx->cmd_input); - if (ctx->exit_code != 0) - doveadm_exit_code = ctx->exit_code; - pool_unref(&ctx->pool); + doveadm_mail_cmd_exec(ctx, argv, wildcard_user); } static bool