dovecot-2.0-pigeonhole: lib-sieve: finished ihave extension.
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Sun Jun 26 22:59:06 EEST 2011
details: http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/bdb94146c89c
changeset: 1508:bdb94146c89c
user: Stephan Bosch <stephan at rename-it.nl>
date: Sun Jun 26 23:07:33 2011 +0200
description:
lib-sieve: finished ihave extension.
diffstat:
Makefile.am | 2 +
src/lib-sieve/plugins/ihave/Makefile.am | 4 +
src/lib-sieve/plugins/ihave/cmd-error.c | 131 ++++++++++++++++++++++++++
src/lib-sieve/plugins/ihave/ext-ihave-common.h | 4 +-
src/lib-sieve/plugins/ihave/ext-ihave.c | 5 +-
src/lib-sieve/plugins/ihave/tst-ihave.c | 12 +-
tests/extensions/ihave/errors.svtest | 19 +++
tests/extensions/ihave/errors/error.sieve | 3 +
tests/extensions/ihave/restrictions.svtest | 14 ++
9 files changed, 183 insertions(+), 11 deletions(-)
diffs (274 lines):
diff -r 2eec49242135 -r bdb94146c89c Makefile.am
--- a/Makefile.am Sun Jun 26 22:35:31 2011 +0200
+++ b/Makefile.am Sun Jun 26 23:07:33 2011 +0200
@@ -124,6 +124,8 @@
tests/extensions/spamvirustest/spamtestplus.svtest \
tests/extensions/spamvirustest/errors.svtest \
tests/extensions/ihave/execute.svtest \
+ tests/extensions/ihave/errors.svtest \
+ tests/extensions/ihave/restrictions.svtest \
tests/extensions/vnd.dovecot/debug/execute.svtest \
tests/deprecated/notify/basic.svtest \
tests/deprecated/notify/mailto.svtest \
diff -r 2eec49242135 -r bdb94146c89c src/lib-sieve/plugins/ihave/Makefile.am
--- a/src/lib-sieve/plugins/ihave/Makefile.am Sun Jun 26 22:35:31 2011 +0200
+++ b/src/lib-sieve/plugins/ihave/Makefile.am Sun Jun 26 23:07:33 2011 +0200
@@ -7,8 +7,12 @@
tests = \
tst-ihave.c
+commands = \
+ cmd-error.c
+
libsieve_ext_ihave_la_SOURCES = \
$(tests) \
+ $(commands) \
ext-ihave-binary.c \
ext-ihave-common.c \
ext-ihave.c
diff -r 2eec49242135 -r bdb94146c89c src/lib-sieve/plugins/ihave/cmd-error.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/ihave/cmd-error.c Sun Jun 26 23:07:33 2011 +0200
@@ -0,0 +1,131 @@
+/* Copyright (c) 2002-2011 Pigeonhole authors, see the included COPYING file
+ */
+
+#include "lib.h"
+#include "str-sanitize.h"
+
+#include "sieve-extensions.h"
+#include "sieve-commands.h"
+#include "sieve-code.h"
+
+#include "sieve-validator.h"
+#include "sieve-generator.h"
+#include "sieve-binary.h"
+#include "sieve-interpreter.h"
+#include "sieve-dump.h"
+
+#include "ext-ihave-common.h"
+
+/*
+ * Error command
+ *
+ * Syntax
+ * error <message: string>
+ */
+
+static bool cmd_error_validate
+ (struct sieve_validator *valdtr, struct sieve_command *tst);
+static bool cmd_error_generate
+ (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx);
+
+const struct sieve_command_def error_command = {
+ "error",
+ SCT_COMMAND,
+ 1, 0, FALSE, FALSE,
+ NULL, NULL,
+ cmd_error_validate,
+ NULL,
+ cmd_error_generate,
+ NULL
+};
+
+/*
+ * Body operation
+ */
+
+static bool cmd_error_operation_dump
+ (const struct sieve_dumptime_env *denv, sieve_size_t *address);
+static int cmd_error_operation_execute
+ (const struct sieve_runtime_env *renv, sieve_size_t *address);
+
+const struct sieve_operation_def error_operation = {
+ "ERROR",
+ &ihave_extension,
+ 0,
+ cmd_error_operation_dump,
+ cmd_error_operation_execute
+};
+
+/*
+ * Validation
+ */
+
+static bool cmd_error_validate
+(struct sieve_validator *valdtr, struct sieve_command *tst)
+{
+ struct sieve_ast_argument *arg = tst->first_positional;
+
+ if ( !sieve_validate_positional_argument
+ (valdtr, tst, arg, "message", 1, SAAT_STRING) ) {
+ return FALSE;
+ }
+
+ return sieve_validator_argument_activate(valdtr, tst, arg, FALSE);
+}
+
+/*
+ * Code generation
+ */
+
+static bool cmd_error_generate
+(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd)
+{
+ (void)sieve_operation_emit(cgenv->sblock, cmd->ext, &error_operation);
+
+ /* Generate arguments */
+ return sieve_generate_arguments(cgenv, cmd, NULL);
+}
+
+/*
+ * Code dump
+ */
+
+static bool cmd_error_operation_dump
+(const struct sieve_dumptime_env *denv, sieve_size_t *address)
+{
+ sieve_code_dumpf(denv, "ERROR");
+ sieve_code_descend(denv);
+
+ return sieve_opr_string_dump(denv, address, "message");
+}
+
+/*
+ * Interpretation
+ */
+
+static int cmd_error_operation_execute
+(const struct sieve_runtime_env *renv, sieve_size_t *address)
+{
+ string_t *message;
+ int ret;
+
+ /*
+ * Read operands
+ */
+
+ /* Read message */
+
+ if ( (ret=sieve_opr_string_read(renv, address, "message", &message)) <= 0 )
+ return ret;
+
+ /*
+ * Perform operation
+ */
+
+ sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "error \"%s\"",
+ str_sanitize(str_c(message), 80));
+
+ sieve_runtime_error(renv, NULL, "%s", str_c(message));
+
+ return SIEVE_EXEC_FAILURE;
+}
diff -r 2eec49242135 -r bdb94146c89c src/lib-sieve/plugins/ihave/ext-ihave-common.h
--- a/src/lib-sieve/plugins/ihave/ext-ihave-common.h Sun Jun 26 22:35:31 2011 +0200
+++ b/src/lib-sieve/plugins/ihave/ext-ihave-common.h Sun Jun 26 23:07:33 2011 +0200
@@ -22,13 +22,13 @@
* Commands
*/
-//extern const struct sieve_command_def error_command;
+extern const struct sieve_command_def error_command;
/*
* Operations
*/
-//extern const struct sieve_operation_def error_operation;
+extern const struct sieve_operation_def error_operation;
/*
* AST context
diff -r 2eec49242135 -r bdb94146c89c src/lib-sieve/plugins/ihave/ext-ihave.c
--- a/src/lib-sieve/plugins/ihave/ext-ihave.c Sun Jun 26 22:35:31 2011 +0200
+++ b/src/lib-sieve/plugins/ihave/ext-ihave.c Sun Jun 26 23:07:33 2011 +0200
@@ -41,16 +41,15 @@
ext_ihave_binary_load,
ext_ihave_binary_dump,
NULL,
-// SIEVE_EXT_DEFINE_OPERATION(error_operation),
- SIEVE_EXT_DEFINE_NO_OPERATIONS,
+ SIEVE_EXT_DEFINE_OPERATION(error_operation),
SIEVE_EXT_DEFINE_NO_OPERANDS
};
static bool ext_ihave_validator_load
(const struct sieve_extension *ext, struct sieve_validator *validator)
{
- /* Register new test */
sieve_validator_register_command(validator, ext, &ihave_test);
+ sieve_validator_register_command(validator, ext, &error_command);
return TRUE;
}
diff -r 2eec49242135 -r bdb94146c89c src/lib-sieve/plugins/ihave/tst-ihave.c
--- a/src/lib-sieve/plugins/ihave/tst-ihave.c Sun Jun 26 22:35:31 2011 +0200
+++ b/src/lib-sieve/plugins/ihave/tst-ihave.c Sun Jun 26 23:07:33 2011 +0200
@@ -113,12 +113,12 @@
/* RFC 5463, Section 4, page 4:
*
* The "ihave" extension is designed to be used with other extensions
- * that add tests, actions, comparators, or arguments. Implementations
- * MUST NOT allow it to be used with extensions that change the
- * underlying Sieve grammar, or extensions like encoded-character
- * [RFC5228], or variables [RFC5229] that change how the content of
- * Sieve scripts are interpreted. The test MUST fail and the extension
- * MUST NOT be enabled if such usage is attempted.
+ * that add tests, actions, comparators, or arguments. Implementations
+ * MUST NOT allow it to be used with extensions that change the
+ * underlying Sieve grammar, or extensions like encoded-character
+ * [RFC5228], or variables [RFC5229] that change how the content of
+ * Sieve scripts are interpreted. The test MUST fail and the extension
+ * MUST NOT be enabled if such usage is attempted.
*
* FIXME: current implementation of this restriction is hardcoded and
* therefore highly inflexible
diff -r 2eec49242135 -r bdb94146c89c tests/extensions/ihave/errors.svtest
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/extensions/ihave/errors.svtest Sun Jun 26 23:07:33 2011 +0200
@@ -0,0 +1,19 @@
+require "vnd.dovecot.testsuite";
+
+require "relational";
+require "comparator-i;ascii-numeric";
+
+test "Error command" {
+ if not test_script_compile "errors/error.sieve" {
+ test_fail "compile failed";
+ }
+
+ if test_script_run {
+ test_fail "execution should have failed";
+ }
+
+ if test_error :count "gt" :comparator "i;ascii-numeric" "1" {
+ test_fail "too many runtime errors reported";
+ }
+}
+
diff -r 2eec49242135 -r bdb94146c89c tests/extensions/ihave/errors/error.sieve
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/extensions/ihave/errors/error.sieve Sun Jun 26 23:07:33 2011 +0200
@@ -0,0 +1,3 @@
+require "ihave";
+
+error "Something failed.";
diff -r 2eec49242135 -r bdb94146c89c tests/extensions/ihave/restrictions.svtest
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/extensions/ihave/restrictions.svtest Sun Jun 26 23:07:33 2011 +0200
@@ -0,0 +1,14 @@
+require "vnd.dovecot.testsuite";
+require "ihave";
+
+test "Restricted: encoded-character" {
+ if ihave "encoded-character" {
+ test_fail "encoded-character extension is incompatible with ihave";
+ }
+}
+
+test "Restricted: variables" {
+ if ihave "variables" {
+ test_fail "variables extension is incompatible with ihave";
+ }
+}
More information about the dovecot-cvs
mailing list