diff --git a/src/plugins/doveadm-sieve/doveadm-sieve-cmd-put.c b/src/plugins/doveadm-sieve/doveadm-sieve-cmd-put.c index ef9472d6199b650553f2e2557ad6b0fc09e0d12b..d8cdb531fb47a10838665223f2bd9544a02c8c73 100644 --- a/src/plugins/doveadm-sieve/doveadm-sieve-cmd-put.c +++ b/src/plugins/doveadm-sieve/doveadm-sieve-cmd-put.c @@ -15,12 +15,11 @@ struct doveadm_sieve_put_cmd_context { struct doveadm_sieve_cmd_context ctx; const char *scriptname; - + bool activate:1; }; -static int cmd_sieve_put_run -(struct doveadm_sieve_cmd_context *_ctx) +static int cmd_sieve_put_run(struct doveadm_sieve_cmd_context *_ctx) { struct doveadm_sieve_put_cmd_context *ctx = (struct doveadm_sieve_put_cmd_context *)_ctx; @@ -31,17 +30,16 @@ static int cmd_sieve_put_run ssize_t ret; bool save_failed = FALSE; - save_ctx = sieve_storage_save_init - (storage, ctx->scriptname, input); - if ( save_ctx == NULL ) { + save_ctx = sieve_storage_save_init(storage, ctx->scriptname, input); + if (save_ctx == NULL) { i_error("Saving failed: %s", sieve_storage_get_last_error(storage, &error)); doveadm_sieve_cmd_failed_error(_ctx, error); return -1; } - while ( (ret = i_stream_read(input)) > 0 || ret == -2 ) { - if ( sieve_storage_save_continue(save_ctx) < 0 ) { + while ((ret = i_stream_read(input)) > 0 || ret == -2) { + if (sieve_storage_save_continue(save_ctx) < 0) { save_failed = TRUE; ret = -1; break; @@ -49,15 +47,16 @@ static int cmd_sieve_put_run } i_assert(ret == -1); - if ( input->stream_errno != 0 ) { - i_error("read(script input) failed: %s", i_stream_get_error(input)); - doveadm_sieve_cmd_failed_error - (&ctx->ctx, SIEVE_ERROR_TEMP_FAILURE); - } else if ( save_failed ) { + if (input->stream_errno != 0) { + i_error("read(script input) failed: %s", + i_stream_get_error(input)); + doveadm_sieve_cmd_failed_error(&ctx->ctx, + SIEVE_ERROR_TEMP_FAILURE); + } else if (save_failed) { i_error("Saving failed: %s", sieve_storage_get_last_error(storage, NULL)); doveadm_sieve_cmd_failed_storage(&ctx->ctx, storage); - } else if ( sieve_storage_save_finish(save_ctx) < 0 ) { + } else if (sieve_storage_save_finish(save_ctx) < 0) { i_error("Saving failed: %s", sieve_storage_get_last_error(storage, NULL)); doveadm_sieve_cmd_failed_storage(&ctx->ctx, storage); @@ -66,10 +65,11 @@ static int cmd_sieve_put_run } /* Verify that script compiles */ - if ( ret == 0 ) { + if (ret == 0) { struct sieve_error_handler *ehandler; enum sieve_compile_flags cpflags = - SIEVE_COMPILE_FLAG_NOGLOBAL | SIEVE_COMPILE_FLAG_UPLOADED; + SIEVE_COMPILE_FLAG_NOGLOBAL | + SIEVE_COMPILE_FLAG_UPLOADED; struct sieve_script *script; struct sieve_binary *sbin; @@ -77,21 +77,26 @@ static int cmd_sieve_put_run script = sieve_storage_save_get_tempscript(save_ctx); /* Check result */ - if ( script == NULL ) { + if (script == NULL) { i_error("Saving failed: %s", sieve_storage_get_last_error(storage, &error)); doveadm_sieve_cmd_failed_error(_ctx, error); ret = -1; } else { - /* Mark this as an activation when we are replacing the active script */ - if ( ctx->activate || sieve_storage_save_will_activate(save_ctx) ) + /* Mark this as an activation when we are replacing the + active script. + */ + if (ctx->activate || + sieve_storage_save_will_activate(save_ctx)) cpflags |= SIEVE_COMPILE_FLAG_ACTIVATED; /* Compile */ - ehandler = sieve_master_ehandler_create(ctx->ctx.svinst, 0); - if ( (sbin=sieve_compile_script - (script, ehandler, cpflags, &error)) == NULL ) { + ehandler = sieve_master_ehandler_create( + ctx->ctx.svinst, 0); + sbin = sieve_compile_script(script, ehandler, cpflags, + &error); + if (sbin == NULL) { doveadm_sieve_cmd_failed_error(_ctx, error); ret = -1; } else { @@ -101,8 +106,10 @@ static int cmd_sieve_put_run ret = sieve_storage_save_commit(&save_ctx); if (ret < 0) { i_error("Saving failed: %s", - sieve_storage_get_last_error(storage, &error)); - doveadm_sieve_cmd_failed_error(_ctx, error); + sieve_storage_get_last_error( + storage, &error)); + doveadm_sieve_cmd_failed_error( + _ctx, error); ret = -1; } } @@ -110,14 +117,15 @@ static int cmd_sieve_put_run } } - if ( save_ctx != NULL ) + if (save_ctx != NULL) sieve_storage_save_cancel(&save_ctx); - if ( ctx->activate && ret == 0 ) { - struct sieve_script *script = sieve_storage_open_script - (storage, ctx->scriptname, NULL); - if ( script == NULL || - sieve_script_activate(script, (time_t)-1) < 0) { + if (ctx->activate && ret == 0) { + struct sieve_script *script = + sieve_storage_open_script(storage, ctx->scriptname, + NULL); + if (script == NULL || + sieve_script_activate(script, (time_t)-1) < 0) { i_error("Failed to activate Sieve script: %s", sieve_storage_get_last_error(storage, &error)); doveadm_sieve_cmd_failed_error(_ctx, error); @@ -131,14 +139,14 @@ static int cmd_sieve_put_run return ret < 0 ? -1 : 0; } -static void cmd_sieve_put_init -(struct doveadm_mail_cmd_context *_ctx, - const char *const args[]) +static void +cmd_sieve_put_init(struct doveadm_mail_cmd_context *_ctx, + const char *const args[]) { struct doveadm_sieve_put_cmd_context *ctx = (struct doveadm_sieve_put_cmd_context *)_ctx; - if ( str_array_length(args) != 1 ) + if (str_array_length(args) != 1) doveadm_mail_help_name("sieve put"); doveadm_sieve_cmd_scriptnames_check(args); @@ -153,7 +161,7 @@ cmd_sieve_put_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c) struct doveadm_sieve_put_cmd_context *ctx = (struct doveadm_sieve_put_cmd_context *)_ctx; - switch ( c ) { + switch (c) { case 'a': ctx->activate = TRUE; break; @@ -163,8 +171,7 @@ cmd_sieve_put_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c) return TRUE; } -static struct doveadm_mail_cmd_context * -cmd_sieve_put_alloc(void) +static struct doveadm_mail_cmd_context *cmd_sieve_put_alloc(void) { struct doveadm_sieve_put_cmd_context *ctx;