diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
commit | f7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch) | |
tree | a3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /pigeonhole/src/lib-sieve/plugins/vacation/ext-vacation.c | |
parent | Initial commit. (diff) | |
download | dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip |
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pigeonhole/src/lib-sieve/plugins/vacation/ext-vacation.c')
-rw-r--r-- | pigeonhole/src/lib-sieve/plugins/vacation/ext-vacation.c | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/pigeonhole/src/lib-sieve/plugins/vacation/ext-vacation.c b/pigeonhole/src/lib-sieve/plugins/vacation/ext-vacation.c new file mode 100644 index 0000000..8d3d9a7 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/vacation/ext-vacation.c @@ -0,0 +1,131 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +/* Extension vacation + * ------------------ + * + * Authors: Stephan Bosch <stephan@rename-it.nl> + * Specification: RFC 5230 + * Implementation: full + * Status: testing + * + */ + +#include "lib.h" + +#include "sieve-common.h" + +#include "sieve-extensions.h" +#include "sieve-commands.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" +#include "sieve-dump.h" + +#include "ext-vacation-common.h" + +/* + * Extension + */ + +static bool +ext_vacation_validator_load(const struct sieve_extension *ext, + struct sieve_validator *valdtr); +static bool +ext_vacation_interpreter_load(const struct sieve_extension *ext, + const struct sieve_runtime_env *renv, + sieve_size_t *address); + +static bool +ext_vacation_validator_validate(const struct sieve_extension *ext, + struct sieve_validator *valdtr, void *context, + struct sieve_ast_argument *require_arg, + bool required); +static int +ext_vacation_interpreter_run(const struct sieve_extension *this_ext, + const struct sieve_runtime_env *renv, + void *context, bool deferred); + +const struct sieve_extension_def vacation_extension = { + .name = "vacation", + .load = ext_vacation_load, + .unload = ext_vacation_unload, + .validator_load = ext_vacation_validator_load, + .interpreter_load = ext_vacation_interpreter_load, + SIEVE_EXT_DEFINE_OPERATION(vacation_operation) +}; +const struct sieve_validator_extension +vacation_validator_extension = { + .ext = &vacation_extension, + .validate = ext_vacation_validator_validate +}; +const struct sieve_interpreter_extension +vacation_interpreter_extension = { + .ext_def = &vacation_extension, + .run = ext_vacation_interpreter_run +}; + +static bool +ext_vacation_validator_load(const struct sieve_extension *ext, + struct sieve_validator *valdtr) +{ + /* Register new command */ + sieve_validator_register_command(valdtr, ext, &vacation_command); + + sieve_validator_extension_register(valdtr, ext, + &vacation_validator_extension, NULL); + return TRUE; +} + +static bool +ext_vacation_interpreter_load(const struct sieve_extension *ext, + const struct sieve_runtime_env *renv, + sieve_size_t *address ATTR_UNUSED) +{ + sieve_interpreter_extension_register( + renv->interp, ext, &vacation_interpreter_extension, NULL); + return TRUE; +} + +static bool +ext_vacation_validator_validate(const struct sieve_extension *ext, + struct sieve_validator *valdtr, + void *context ATTR_UNUSED, + struct sieve_ast_argument *require_arg, + bool required) +{ + if (required) { + enum sieve_compile_flags flags = + sieve_validator_compile_flags(valdtr); + + if ((flags & SIEVE_COMPILE_FLAG_NO_ENVELOPE) != 0) { + sieve_argument_validate_error( + valdtr, require_arg, + "the %s extension cannot be used in this context " + "(needs access to message envelope)", + sieve_extension_name(ext)); + return FALSE; + } + } + return TRUE; +} + +static int +ext_vacation_interpreter_run(const struct sieve_extension *ext, + const struct sieve_runtime_env *renv, + void *context ATTR_UNUSED, bool deferred) +{ + const struct sieve_execute_env *eenv = renv->exec_env; + + if ((eenv->flags & SIEVE_EXECUTE_FLAG_NO_ENVELOPE) != 0) { + if (!deferred) { + sieve_runtime_error( + renv, NULL, + "the %s extension cannot be used in this context " + "(needs access to message envelope)", + sieve_extension_name(ext)); + } + return SIEVE_EXEC_FAILURE; + } + return SIEVE_EXEC_OK; +} |