Skip to content
Snippets Groups Projects
Commit 2ce32c4c authored by Stephan Bosch's avatar Stephan Bosch
Browse files

managesieve: The PUTSCRIPT command now allows uploading empty Sieve scripts.

There is no reason to forbid an empty Sieve script.
parent a4348748
No related branches found
No related tags found
No related merge requests found
...@@ -36,6 +36,8 @@ struct cmd_putscript_context { ...@@ -36,6 +36,8 @@ struct cmd_putscript_context {
struct managesieve_parser *save_parser; struct managesieve_parser *save_parser;
struct sieve_storage_save_context *save_ctx; struct sieve_storage_save_context *save_ctx;
bool script_size_valid:1;
}; };
static void cmd_putscript_finish(struct cmd_putscript_context *ctx); static void cmd_putscript_finish(struct cmd_putscript_context *ctx);
...@@ -182,12 +184,14 @@ static bool cmd_putscript_finish_parsing(struct client_command_context *cmd) ...@@ -182,12 +184,14 @@ static bool cmd_putscript_finish_parsing(struct client_command_context *cmd)
} }
/* If quoted string, the size was not known until now */ /* If quoted string, the size was not known until now */
if ( ctx->script_size == 0 ) { if ( !ctx->script_size_valid ) {
if (sieve_script_get_size(script, &ctx->script_size) < 0) { if (sieve_script_get_size(script, &ctx->script_size) < 0) {
client_send_storage_error(client, ctx->storage); client_send_storage_error(client, ctx->storage);
cmd_putscript_finish(ctx); cmd_putscript_finish(ctx);
return TRUE; return TRUE;
} }
ctx->script_size_valid = TRUE;
/* Check quota; max size is already checked */ /* Check quota; max size is already checked */
if ( ctx->scriptname != NULL && !managesieve_quota_check_all if ( ctx->scriptname != NULL && !managesieve_quota_check_all
(client, ctx->scriptname, ctx->script_size) ) { (client, ctx->scriptname, ctx->script_size) ) {
...@@ -310,18 +314,10 @@ static bool cmd_putscript_continue_parsing(struct client_command_context *cmd) ...@@ -310,18 +314,10 @@ static bool cmd_putscript_continue_parsing(struct client_command_context *cmd)
} }
if ( i_stream_get_size(ctx->input, FALSE, &ctx->script_size) > 0 ) { if ( i_stream_get_size(ctx->input, FALSE, &ctx->script_size) > 0 ) {
if ( ctx->script_size == 0 ) { ctx->script_size_valid = TRUE;
/* no script content, abort */
if ( ctx->scriptname != NULL )
client_send_no(client, "PUTSCRIPT aborted (empty script).");
else
client_send_no(client, "CHECKSCRIPT aborted (empty script).");
cmd_putscript_finish(ctx);
return TRUE;
/* Check quota */ /* Check quota */
} else if ( ctx->scriptname == NULL ) { if ( ctx->scriptname == NULL ) {
if ( !managesieve_quota_check_validsize(client, ctx->script_size) ) if ( !managesieve_quota_check_validsize(client, ctx->script_size) )
return cmd_putscript_cancel(ctx, TRUE); return cmd_putscript_cancel(ctx, TRUE);
} else { } else {
...@@ -360,7 +356,9 @@ static bool cmd_putscript_continue_script(struct client_command_context *cmd) ...@@ -360,7 +356,9 @@ static bool cmd_putscript_continue_script(struct client_command_context *cmd)
int ret; int ret;
if (ctx->save_ctx != NULL) { if (ctx->save_ctx != NULL) {
while (ctx->script_size == 0 || ctx->input->v_offset != ctx->script_size) { for (;;) {
i_assert(!ctx->script_size_valid ||
ctx->input->v_offset <= ctx->script_size);
if ( ctx->max_script_size > 0 && if ( ctx->max_script_size > 0 &&
ctx->input->v_offset > ctx->max_script_size ) { ctx->input->v_offset > ctx->max_script_size ) {
(void)managesieve_quota_check_validsize(client, ctx->input->v_offset); (void)managesieve_quota_check_validsize(client, ctx->input->v_offset);
...@@ -392,7 +390,7 @@ static bool cmd_putscript_continue_script(struct client_command_context *cmd) ...@@ -392,7 +390,7 @@ static bool cmd_putscript_continue_script(struct client_command_context *cmd)
bool failed = FALSE; bool failed = FALSE;
bool all_written = FALSE; bool all_written = FALSE;
if ( ctx->script_size == 0 ) { if ( !ctx->script_size_valid ) {
if ( !client->input->eof && if ( !client->input->eof &&
ctx->input->stream_errno == EINVAL ) { ctx->input->stream_errno == EINVAL ) {
client_send_command_error(cmd, t_strdup_printf( client_send_command_error(cmd, t_strdup_printf(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.