dovecot-2.0-pigeonhole: Vacation extension: added min/max period...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Tue Jan 25 02:07:48 EET 2011
details: http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/129adff0c81b
changeset: 1465:129adff0c81b
user: Stephan Bosch <stephan at rename-it.nl>
date: Tue Jan 25 01:05:28 2011 +0100
description:
Vacation extension: added min/max period configuration settings and changed the internal unit from days to seconds.
diffstat:
INSTALL | 31 ++++++----
doc/Makefile.am | 4 +-
doc/vacation.txt | 32 ++++++++++
src/lib-sieve/plugins/vacation/Makefile.am | 1 +
src/lib-sieve/plugins/vacation/cmd-vacation.c | 64 ++++++++++++++-------
src/lib-sieve/plugins/vacation/ext-vacation-common.c | 54 ++++++++++++++++++
src/lib-sieve/plugins/vacation/ext-vacation-common.h | 19 ++++++
src/lib-sieve/plugins/vacation/ext-vacation.c | 3 +-
src/lib-sieve/sieve-binary.h | 2 +-
src/lib-sieve/sieve-settings.c | 4 +-
src/lib-sieve/sieve-settings.h | 2 +-
11 files changed, 177 insertions(+), 39 deletions(-)
diffs (truncated from 421 to 300 lines):
diff -r c21d4452b5eb -r 129adff0c81b INSTALL
--- a/INSTALL Mon Jan 24 23:39:32 2011 +0100
+++ b/INSTALL Tue Jan 25 01:05:28 2011 +0100
@@ -256,21 +256,27 @@
IMPORTANT: Be sure to manually pre-compile the scripts specified by sieve_before
and sieve_after using the sievec tool, as explained in the README file.
-Sieve Interpreter - Spamtest and Virustest Extensions
------------------------------------------------------
+Sieve Interpreter - Extension Configuration
+-------------------------------------------
-Using the spamtest and virustest extensions (RFC 5235), the Sieve language
-provides a uniform and standardized command interface for evaluating spam and
-virus tests performed on the message. Users no longer need to know what headers
-need to be checked and how the scanner's verdict is represented in the header
-field value. They only need to know how to use the spamtest (spamtestplus) and
-virustest extensions. This also gives GUI-based Sieve editors the means to
-provide a portable and easy to install interface for spam and virus filter
-configuration.
+- Vacation extension:
-The spamtest, spamtestplus and virustest extensions require explicit
-configuration and are not enabled for use by default. Refer to
-doc/spamtest-virustest.txt for configuration information.
+ Refer to doc/vacation.txt for settings specific to the vacation extension.
+
+- Spamtest and Virustest extensions:
+
+ Using the spamtest and virustest extensions (RFC 5235), the Sieve language
+ provides a uniform and standardized command interface for evaluating spam and
+ virus tests performed on the message. Users no longer need to know what headers
+ need to be checked and how the scanner's verdict is represented in the header
+ field value. They only need to know how to use the spamtest (spamtestplus) and
+ virustest extensions. This also gives GUI-based Sieve editors the means to
+ provide a portable and easy to install interface for spam and virus filter
+ configuration.
+
+ The spamtest, spamtestplus and virustest extensions require explicit
+ configuration and are not enabled for use by default. Refer to
+ doc/spamtest-virustest.txt for configuration information.
Sieve Interpreter - Migration from CMUSieve (Dovecot v1.0/v1.1)
---------------------------------------------------------------
diff -r c21d4452b5eb -r 129adff0c81b doc/Makefile.am
--- a/doc/Makefile.am Mon Jan 24 23:39:32 2011 +0100
+++ b/doc/Makefile.am Tue Jan 25 01:05:28 2011 +0100
@@ -1,6 +1,8 @@
SUBDIRS = man example-config
-docfiles = spamtest-virustest.txt
+docfiles = \
+ vacation.txt \
+ spamtest-virustest.txt
if BUILD_DOCS
sieve_doc_DATA = $(docfiles)
diff -r c21d4452b5eb -r 129adff0c81b doc/vacation.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/vacation.txt Tue Jan 25 01:05:28 2011 +0100
@@ -0,0 +1,32 @@
+Vacation Extension
+==================
+
+The vacation extension is available by default.
+
+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.
+
+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
+ 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.
+
+Example
+=======
+
+plugin {
+ # ... other plugin settings
+
+ # One minute at minimum
+ sieve_vacation_min_period = 1m
+
+ # Thirty days at maximum
+ sieve_vacation_max_period = 30d
+}
+
diff -r c21d4452b5eb -r 129adff0c81b src/lib-sieve/plugins/vacation/Makefile.am
--- a/src/lib-sieve/plugins/vacation/Makefile.am Mon Jan 24 23:39:32 2011 +0100
+++ b/src/lib-sieve/plugins/vacation/Makefile.am Tue Jan 25 01:05:28 2011 +0100
@@ -9,6 +9,7 @@
libsieve_ext_vacation_la_SOURCES = \
$(cmds) \
+ ext-vacation-common.c \
ext-vacation.c
noinst_HEADERS = \
diff -r c21d4452b5eb -r 129adff0c81b src/lib-sieve/plugins/vacation/cmd-vacation.c
--- a/src/lib-sieve/plugins/vacation/cmd-vacation.c Mon Jan 24 23:39:32 2011 +0100
+++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c Tue Jan 25 01:05:28 2011 +0100
@@ -140,7 +140,7 @@
enum cmd_vacation_optional {
OPT_END,
- OPT_DAYS,
+ OPT_SECONDS,
OPT_SUBJECT,
OPT_FROM,
OPT_ADDRESSES,
@@ -204,7 +204,7 @@
struct act_vacation_context {
const char *reason;
- sieve_number_t days;
+ sieve_number_t seconds;
const char *subject;
const char *handle;
bool mime;
@@ -234,6 +234,9 @@
(struct sieve_validator *valdtr, struct sieve_ast_argument **arg,
struct sieve_command *cmd)
{
+ const struct sieve_extension *ext = sieve_argument_ext(*arg);
+ const struct ext_vacation_config *config =
+ (const struct ext_vacation_config *) ext->context;
struct sieve_ast_argument *tag = *arg;
/* Detach the tag itself */
@@ -247,9 +250,24 @@
return FALSE;
}
- /* Enforce :days > 0 */
- if ( sieve_ast_argument_number(*arg) == 0 ) {
- sieve_ast_argument_number_set(*arg, 1);
+ if ( sieve_argument_is(tag, vacation_days_tag) ) {
+ sieve_number_t days = sieve_ast_argument_number(*arg);
+
+ /* Enforce :days >= min_period */
+ if ( days * (24*60*60) < config->min_period ) {
+ sieve_ast_argument_number_set(*arg, config->min_period);
+
+ sieve_argument_validate_warning(valdtr, *arg,
+ "specified :days period '%d' is under the minimum", days);
+
+ /* Enforce :days <= max_period */
+ } else if ( config->max_period > 0
+ && days * (24*60*60) > config->max_period ) {
+ sieve_ast_argument_number_set(*arg, config->max_period);
+
+ sieve_argument_validate_warning(valdtr, *arg,
+ "specified :days period '%d' is over the maximum", days);
+ }
}
/* Skip parameter */
@@ -367,7 +385,7 @@
struct sieve_command_registration *cmd_reg)
{
sieve_validator_register_tag
- (valdtr, cmd_reg, ext, &vacation_days_tag, OPT_DAYS);
+ (valdtr, cmd_reg, ext, &vacation_days_tag, OPT_SECONDS);
sieve_validator_register_tag
(valdtr, cmd_reg, ext, &vacation_subject_tag, OPT_SUBJECT);
sieve_validator_register_tag
@@ -500,8 +518,8 @@
if ( opt == 0 ) break;
switch ( opt_code ) {
- case OPT_DAYS:
- opok = sieve_opr_number_dump(denv, address, "days");
+ case OPT_SECONDS:
+ opok = sieve_opr_number_dump(denv, address, "seconds");
break;
case OPT_SUBJECT:
opok = sieve_opr_string_dump(denv, address, "subject");
@@ -540,7 +558,7 @@
struct act_vacation_context *act;
pool_t pool;
int opt_code = 0;
- sieve_number_t days = 7;
+ sieve_number_t seconds = EXT_VACATION_DEFAULT_PERIOD;
bool mime = FALSE;
struct sieve_stringlist *addresses = NULL;
string_t *reason, *subject = NULL, *from = NULL, *handle = NULL;
@@ -562,8 +580,8 @@
if ( opt == 0 ) break;
switch ( opt_code ) {
- case OPT_DAYS:
- ret = sieve_opr_number_read(renv, address, "days", &days);
+ case OPT_SECONDS:
+ ret = sieve_opr_number_read(renv, address, "seconds", &seconds);
break;
case OPT_SUBJECT:
ret = sieve_opr_string_read(renv, address, "subject", &subject);
@@ -597,11 +615,6 @@
* Perform operation
*/
- /* Enforce days > 0 (just to be sure) */
-
- if ( days == 0 )
- days = 1;
-
/* Trace */
if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_ACTIONS) ) {
@@ -630,7 +643,7 @@
act = p_new(pool, struct act_vacation_context, 1);
act->reason = p_strdup(pool, str_c(reason));
act->handle = p_strdup(pool, str_c(handle));
- act->days = days;
+ act->seconds = seconds;
act->mime = mime;
if ( subject != NULL )
act->subject = p_strdup(pool, str_c(subject));
@@ -735,7 +748,7 @@
(struct act_vacation_context *) action->context;
sieve_result_action_printf( rpenv, "send vacation message:");
- sieve_result_printf(rpenv, " => days : %d\n", ctx->days);
+ sieve_result_printf(rpenv, " => seconds : %d\n", ctx->seconds);
if ( ctx->subject != NULL )
sieve_result_printf(rpenv, " => subject: %s\n", ctx->subject);
if ( ctx->from != NULL )
@@ -966,11 +979,14 @@
(const struct sieve_action *action, const struct sieve_action_exec_env *aenv,
void *tr_context ATTR_UNUSED, bool *keep ATTR_UNUSED)
{
- const char *const *hdsp;
+ const struct sieve_extension *ext = action->ext;
+ const struct ext_vacation_config *config =
+ (const struct ext_vacation_config *) ext->context;
const struct sieve_message_data *msgdata = aenv->msgdata;
const struct sieve_script_env *senv = aenv->scriptenv;
struct act_vacation_context *ctx =
(struct act_vacation_context *) action->context;
+ const char *const *hdsp;
unsigned char dupl_hash[MD5_RESULTLEN];
const char *const *headers;
const char *sender = sieve_message_get_sender(aenv->msgctx);
@@ -1109,13 +1125,19 @@
/* Send the message */
if ( act_vacation_send(aenv, ctx, sender, reply_from) ) {
+ sieve_number_t seconds;
+
sieve_result_global_log(aenv, "sent vacation response to <%s>",
str_sanitize(sender, 128));
+ /* 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;
+
/* Mark as replied */
sieve_action_duplicate_mark
- (senv, dupl_hash, sizeof(dupl_hash),
- ioloop_time + ctx->days * (24 * 60 * 60));
+ (senv, dupl_hash, sizeof(dupl_hash), ioloop_time + seconds);
return TRUE;
}
diff -r c21d4452b5eb -r 129adff0c81b src/lib-sieve/plugins/vacation/ext-vacation-common.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/vacation/ext-vacation-common.c Tue Jan 25 01:05:28 2011 +0100
@@ -0,0 +1,54 @@
+#include "sieve-common.h"
+#include "sieve-error.h"
+#include "sieve-settings.h"
+#include "sieve-extensions.h"
+
+#include "ext-vacation-common.h"
+
+bool ext_vacation_load
+(const struct sieve_extension *ext, void **context)
+{
+ struct sieve_instance *svinst = ext->svinst;
+ struct ext_vacation_config *config;
+ sieve_number_t min_period, max_period;
+
+ if ( *context != NULL ) {
+ ext_vacation_unload(ext);
+ }
+
+ if ( !sieve_setting_get_duration_value
+ (svinst, "sieve_vacation_min_period", &min_period) ) {
+ min_period = EXT_VACATION_DEFAULT_MIN_PERIOD;
+ }
+
+ if ( !sieve_setting_get_duration_value
+ (svinst, "sieve_vacation_max_period", &max_period) ) {
More information about the dovecot-cvs
mailing list