From 3817e2b0740b2dff8bade9a7ed6bfc3ff2905c83 Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan@rename-it.nl> Date: Tue, 25 Jan 2011 01:27:01 +0100 Subject: [PATCH] Vacation extension: added default period configuration setting and fixed a limit bug. --- doc/vacation.txt | 12 ++++++++++-- src/lib-sieve/plugins/vacation/cmd-vacation.c | 10 +++++++--- .../plugins/vacation/ext-vacation-common.c | 18 ++++++++++++++---- .../plugins/vacation/ext-vacation-common.h | 5 ++++- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/doc/vacation.txt b/doc/vacation.txt index e14357114..50ba37bc4 100644 --- a/doc/vacation.txt +++ b/doc/vacation.txt @@ -8,15 +8,20 @@ The following settings can be configured for using the vacation extension: sieve_vacation_min_period = 1d This specifies the minimum period that can be specified for the :days tag of the vacation command. Values are specified in s(econds), unless followed - by a d(ay), h(our), m(inute) specifier character. + by a d(ay), h(our) or m(inute) specifier character. sieve_vacation_max_period = 0 This specifies the minimum period that can be specified for the :days tag of the vacation command. Values are specified in s(econds), unless followed - by a d(ay), h(our), m(inute) specifier character. The configured value + by a d(ay), h(our) or m(inute) specifier character. The configured value must be larger than the sieve_vacation_min_period setting. A value of 0 has a special meaning: it indicates that there is no upper limit. +sieve_vacation_default_period = 7d + This specifies the default period that can be specified for the :days tag + of the vacation command. Values are specified in s(econds), unless followed + by a d(ay), h(our) or m(inute) specifier character. + Example ======= @@ -26,6 +31,9 @@ plugin { # One minute at minimum sieve_vacation_min_period = 1m + # Ten days default + sieve_vacation_min_period = 10d + # Thirty days at maximum sieve_vacation_max_period = 30d } diff --git a/src/lib-sieve/plugins/vacation/cmd-vacation.c b/src/lib-sieve/plugins/vacation/cmd-vacation.c index 195ebf6e2..00beee4b0 100644 --- a/src/lib-sieve/plugins/vacation/cmd-vacation.c +++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c @@ -554,11 +554,13 @@ static int ext_vacation_operation_execute (const struct sieve_runtime_env *renv, sieve_size_t *address) { const struct sieve_extension *this_ext = renv->oprtn->ext; + const struct ext_vacation_config *config = + (const struct ext_vacation_config *) this_ext->context; struct sieve_side_effects_list *slist = NULL; struct act_vacation_context *act; pool_t pool; int opt_code = 0; - sieve_number_t seconds = EXT_VACATION_DEFAULT_PERIOD; + sieve_number_t seconds = config->default_period; bool mime = FALSE; struct sieve_stringlist *addresses = NULL; string_t *reason, *subject = NULL, *from = NULL, *handle = NULL; @@ -1132,8 +1134,10 @@ static bool act_vacation_commit /* Check period limits once more */ seconds = ctx->seconds; - if ( seconds < config->min_period ) seconds = config->min_period; - if ( seconds > config->max_period ) seconds = config->max_period; + if ( seconds < config->min_period ) + seconds = config->min_period; + else if ( config->max_period > 0 && seconds > config->max_period ) + seconds = config->max_period; /* Mark as replied */ sieve_action_duplicate_mark diff --git a/src/lib-sieve/plugins/vacation/ext-vacation-common.c b/src/lib-sieve/plugins/vacation/ext-vacation-common.c index ab2ae71f3..52e837726 100644 --- a/src/lib-sieve/plugins/vacation/ext-vacation-common.c +++ b/src/lib-sieve/plugins/vacation/ext-vacation-common.c @@ -10,7 +10,7 @@ bool ext_vacation_load { struct sieve_instance *svinst = ext->svinst; struct ext_vacation_config *config; - sieve_number_t min_period, max_period; + sieve_number_t min_period, max_period, default_period; if ( *context != NULL ) { ext_vacation_unload(ext); @@ -26,18 +26,28 @@ bool ext_vacation_load max_period = EXT_VACATION_DEFAULT_MAX_PERIOD; } - if ( max_period > 0 && max_period < min_period ) { + if ( !sieve_setting_get_duration_value + (svinst, "sieve_vacation_default_period", &default_period) ) { + default_period = EXT_VACATION_DEFAULT_PERIOD; + } + + if ( max_period > 0 + && (min_period > max_period || default_period < min_period + || default_period > max_period) ) { min_period = EXT_VACATION_DEFAULT_MIN_PERIOD; max_period = EXT_VACATION_DEFAULT_MAX_PERIOD; + default_period = EXT_VACATION_DEFAULT_PERIOD; sieve_sys_warning(svinst, - "vacation extension: invalid settings: " - "sieve_vacation_min_period > sieve_vacation_max_period"); + "vacation extension: invalid settings: violated " + "sieve_vacation_min_period < sieve_vacation_default_period < " + "sieve_vacation_max_period"); } config = i_new(struct ext_vacation_config, 1); config->min_period = min_period; config->max_period = max_period; + config->default_period = default_period; *context = (void *) config; diff --git a/src/lib-sieve/plugins/vacation/ext-vacation-common.h b/src/lib-sieve/plugins/vacation/ext-vacation-common.h index ad232a215..512858d31 100644 --- a/src/lib-sieve/plugins/vacation/ext-vacation-common.h +++ b/src/lib-sieve/plugins/vacation/ext-vacation-common.h @@ -17,6 +17,7 @@ struct ext_vacation_config { unsigned int min_period; unsigned int max_period; + unsigned int default_period; }; /* @@ -31,7 +32,9 @@ extern const struct sieve_command_def vacation_command; extern const struct sieve_operation_def vacation_operation; -/* Extension */ +/* + * Extension + */ extern const struct sieve_extension_def vacation_extension; -- GitLab