dovecot-2.0-pigeonhole: Vacation extension: implemented the (dra...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Tue Jan 25 03:44:37 EET 2011
details: http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/5d69bb1453ec
changeset: 1467:5d69bb1453ec
user: Stephan Bosch <stephan at rename-it.nl>
date: Tue Jan 25 02:43:25 2011 +0100
description:
Vacation extension: implemented the (draft) vacation-seconds extension.
diffstat:
INSTALL | 5 +-
doc/vacation.txt | 43 +++++++++----
src/lib-sieve/plugins/vacation/Makefile.am | 3 +-
src/lib-sieve/plugins/vacation/cmd-vacation.c | 60 +++++++++++++++-----
src/lib-sieve/plugins/vacation/ext-vacation-common.h | 10 +++-
src/lib-sieve/plugins/vacation/ext-vacation-seconds.c | 70 +++++++++++++++++++++++
src/lib-sieve/sieve-commands.h | 2 +
src/lib-sieve/sieve-extensions.c | 2 +
src/lib-sieve/sieve-validator.c | 30 ++++++++++
src/lib-sieve/sieve-validator.h | 4 +-
tests/extensions/vacation/execute.svtest | 30 ++++++++++
tests/extensions/vacation/execute/seconds.sieve | 4 +
12 files changed, 229 insertions(+), 34 deletions(-)
diffs (truncated from 434 to 300 lines):
diff -r b6aa4ac74175 -r 5d69bb1453ec INSTALL
--- a/INSTALL Tue Jan 25 01:27:01 2011 +0100
+++ b/INSTALL Tue Jan 25 02:43:25 2011 +0100
@@ -259,9 +259,10 @@
Sieve Interpreter - Extension Configuration
-------------------------------------------
-- Vacation extension:
+- Vacation and Vacation-Seconds extensions:
- Refer to doc/vacation.txt for settings specific to the vacation extension.
+ Refer to doc/vacation.txt for settings specific to the vacation and
+ vacation-seconds extensions.
- Spamtest and Virustest extensions:
diff -r b6aa4ac74175 -r 5d69bb1453ec doc/vacation.txt
--- a/doc/vacation.txt Tue Jan 25 01:27:01 2011 +0100
+++ b/doc/vacation.txt Tue Jan 25 02:43:25 2011 +0100
@@ -1,35 +1,50 @@
Vacation Extension
==================
-The vacation extension is available by default.
+The vacation extension is available by default. In contrast, the (draft)
+vacation-seconds extension - which implies the vacation extension when
+used - is not available by default and needs to be enabled explicitly by
+adding it to the sieve_extensions setting. The configuration also needs
+to be adjusted accordingly to allow a non-reply period of less than a
+day.
+
+The vacation and vacation-seconds extensions have their own specific
+settings. The settings that specify a period (currently all of them)
+are specified in s(econds), unless followed by a d(ay), h(our) or m(inute)
+specifier character.
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) or m(inute) specifier character.
+ This specifies the minimum period that can be specified for the :days
+ and :seconds tags of the vacation command. A minimum of 0 indicates that
+ users are allowed to make the Sieve interpreter send a vacation response
+ message for every incoming message that meets the other criteria (not
+ recommended).
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) 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.
+ of the vacation command. 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.
+ This specifies the default period that is used when no :days or :seconds
+ tag is specified. The configured value must lie between the
+ sieve_vacation_min_period and sieve_vacation_max_period.
+
+Invalid values for the settings above will make the Sieve interpreter log
+a warning and revert to the default values.
Example
=======
plugin {
- # ... other plugin settings
+ # Use vacation-seconds
+ sieve_extensions = +vacation-seconds
- # One minute at minimum
- sieve_vacation_min_period = 1m
+ # One hour at minimum
+ sieve_vacation_min_period = 1h
# Ten days default
sieve_vacation_min_period = 10d
diff -r b6aa4ac74175 -r 5d69bb1453ec src/lib-sieve/plugins/vacation/Makefile.am
--- a/src/lib-sieve/plugins/vacation/Makefile.am Tue Jan 25 01:27:01 2011 +0100
+++ b/src/lib-sieve/plugins/vacation/Makefile.am Tue Jan 25 02:43:25 2011 +0100
@@ -10,7 +10,8 @@
libsieve_ext_vacation_la_SOURCES = \
$(cmds) \
ext-vacation-common.c \
- ext-vacation.c
+ ext-vacation.c \
+ ext-vacation-seconds.c
noinst_HEADERS = \
ext-vacation-common.h
diff -r b6aa4ac74175 -r 5d69bb1453ec src/lib-sieve/plugins/vacation/cmd-vacation.c
--- a/src/lib-sieve/plugins/vacation/cmd-vacation.c Tue Jan 25 01:27:01 2011 +0100
+++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c Tue Jan 25 02:43:25 2011 +0100
@@ -101,6 +101,13 @@
NULL, NULL, NULL,
};
+static const struct sieve_argument_def vacation_seconds_tag = {
+ "seconds",
+ NULL,
+ cmd_vacation_validate_number_tag,
+ NULL, NULL, NULL,
+};
+
static const struct sieve_argument_def vacation_subject_tag = {
"subject",
NULL,
@@ -238,6 +245,7 @@
const struct ext_vacation_config *config =
(const struct ext_vacation_config *) ext->context;
struct sieve_ast_argument *tag = *arg;
+ sieve_number_t period, seconds;
/* Detach the tag itself */
*arg = sieve_ast_arguments_detach(*arg,1);
@@ -250,26 +258,36 @@
return FALSE;
}
+ period = sieve_ast_argument_number(*arg);
if ( sieve_argument_is(tag, vacation_days_tag) ) {
- sieve_number_t days = sieve_ast_argument_number(*arg);
+ seconds = period * (24*60*60);
- /* Enforce :days >= min_period */
- if ( days * (24*60*60) < config->min_period ) {
- sieve_ast_argument_number_set(*arg, config->min_period);
+ } else if ( sieve_argument_is(tag, vacation_seconds_tag) ) {
+ seconds = period;
- sieve_argument_validate_warning(valdtr, *arg,
- "specified :days period '%d' is under the minimum", days);
+ } else {
+ i_unreached();
+ }
- /* 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);
+ /* Enforce :seconds >= min_period */
+ if ( seconds < config->min_period ) {
+ seconds = config->min_period;
- sieve_argument_validate_warning(valdtr, *arg,
- "specified :days period '%d' is over the maximum", days);
- }
+ sieve_argument_validate_warning(valdtr, *arg,
+ "specified :%s value '%lu' is under the minimum",
+ sieve_argument_identifier(tag), (unsigned long) period);
+
+ /* Enforce :days <= max_period */
+ } else if ( config->max_period > 0 && seconds > config->max_period ) {
+ seconds = config->max_period;
+
+ sieve_argument_validate_warning(valdtr, *arg,
+ "specified :%s value '%lu' is over the maximum",
+ sieve_argument_identifier(tag), (unsigned long) period);
}
+ sieve_ast_argument_number_set(*arg, seconds);
+
/* Skip parameter */
*arg = sieve_ast_argument_next(*arg);
@@ -400,6 +418,16 @@
return TRUE;
}
+bool ext_vacation_register_seconds_tag
+(struct sieve_validator *valdtr, const struct sieve_extension *vacation_ext)
+{
+ sieve_validator_register_external_tag
+ (valdtr, vacation_command.identifier, vacation_ext, &vacation_seconds_tag,
+ OPT_SECONDS);
+
+ return TRUE;
+}
+
/*
* Command validation
*/
@@ -1140,8 +1168,10 @@
seconds = config->max_period;
/* Mark as replied */
- sieve_action_duplicate_mark
- (senv, dupl_hash, sizeof(dupl_hash), ioloop_time + seconds);
+ if ( seconds > 0 ) {
+ sieve_action_duplicate_mark
+ (senv, dupl_hash, sizeof(dupl_hash), ioloop_time + seconds);
+ }
return TRUE;
}
diff -r b6aa4ac74175 -r 5d69bb1453ec src/lib-sieve/plugins/vacation/ext-vacation-common.h
--- a/src/lib-sieve/plugins/vacation/ext-vacation-common.h Tue Jan 25 01:27:01 2011 +0100
+++ b/src/lib-sieve/plugins/vacation/ext-vacation-common.h Tue Jan 25 02:43:25 2011 +0100
@@ -33,9 +33,11 @@
extern const struct sieve_operation_def vacation_operation;
/*
- * Extension
+ * Extensions
*/
+/* Vacation */
+
extern const struct sieve_extension_def vacation_extension;
bool ext_vacation_load
@@ -43,5 +45,11 @@
void ext_vacation_unload
(const struct sieve_extension *ext);
+/* Vacation-seconds */
+
+extern const struct sieve_extension_def vacation_seconds_extension;
+
+bool ext_vacation_register_seconds_tag
+ (struct sieve_validator *valdtr, const struct sieve_extension *vacation_ext);
#endif /* __EXT_VACATION_COMMON_H */
diff -r b6aa4ac74175 -r 5d69bb1453ec src/lib-sieve/plugins/vacation/ext-vacation-seconds.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/vacation/ext-vacation-seconds.c Tue Jan 25 02:43:25 2011 +0100
@@ -0,0 +1,70 @@
+/* Copyright (c) 2002-2010 Pigeonhole authors, see the included COPYING file
+ */
+
+/* Extension vacation-seconds
+ * --------------------------
+ *
+ * Authors: Stephan Bosch <stephan at rename-it.nl>
+ * Specification: draft-ietf-sieve-vacation-seconds-03
+ * Implementation: full
+ * Status: testing
+ *
+ */
+
+#include "lib.h"
+
+#include "sieve-common.h"
+
+#include "sieve-extensions.h"
+#include "sieve-validator.h"
+
+#include "ext-vacation-common.h"
+
+/*
+ * Extension
+ */
+
+bool ext_vacation_seconds_load
+ (const struct sieve_extension *ext, void **context);
+static bool ext_vacation_seconds_validator_load
+ (const struct sieve_extension *ext, struct sieve_validator *valdtr);
+
+const struct sieve_extension_def vacation_seconds_extension = {
+ "vacation-seconds",
+ ext_vacation_seconds_load,
+ NULL,
+ ext_vacation_seconds_validator_load,
+ NULL, NULL, NULL, NULL, NULL,
+ SIEVE_EXT_DEFINE_NO_OPERATIONS,
+ SIEVE_EXT_DEFINE_NO_OPERANDS
+};
+
+bool ext_vacation_seconds_load
+(const struct sieve_extension *ext, void **context)
+{
+ if ( *context == NULL ) {
+ /* Make sure vacation extension is registered */
+ *context = (void *)
+ sieve_extension_require(ext->svinst, &vacation_extension);
+ }
+
+ return TRUE;
+}
+
+static bool ext_vacation_seconds_validator_load
+(const struct sieve_extension *ext ATTR_UNUSED, struct sieve_validator *valdtr)
+{
+ const struct sieve_extension *vacation_ext;
+
+ /* Load vacation extension implicitly */
+
+ vacation_ext = sieve_validator_extension_load_implicit
+ (valdtr, vacation_extension.name);
+
+ if ( vacation_ext == NULL )
+ return FALSE;
+
More information about the dovecot-cvs
mailing list