dovecot-2.2-pigeonhole: lib-sieve: Implemented the Sieve index e...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Wed Nov 12 21:11:21 UTC 2014


details:   http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/1d06b61cbaf3
changeset: 1962:1d06b61cbaf3
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Wed Nov 12 22:10:25 2014 +0100
description:
lib-sieve: Implemented the Sieve index extension (RFC 5260).

diffstat:

 Makefile.am                                    |    2 +
 configure.ac                                   |    1 +
 src/lib-sieve/Makefile.am                      |    1 +
 src/lib-sieve/plugins/Makefile.am              |    1 +
 src/lib-sieve/plugins/index/Makefile.am        |   13 +
 src/lib-sieve/plugins/index/ext-index-common.c |   15 +
 src/lib-sieve/plugins/index/ext-index-common.h |   32 ++
 src/lib-sieve/plugins/index/ext-index.c        |   69 ++++++
 src/lib-sieve/plugins/index/tag-index.c        |  272 +++++++++++++++++++++++++
 src/lib-sieve/sieve-extensions.c               |    4 +-
 tests/extensions/index/basic.svtest            |   93 ++++++++
 tests/extensions/index/errors.svtest           |   20 +
 tests/extensions/index/errors/syntax.sieve     |   20 +
 13 files changed, 542 insertions(+), 1 deletions(-)

diffs (truncated from 632 to 300 lines):

diff -r 578aca9c0ba1 -r 1d06b61cbaf3 Makefile.am
--- a/Makefile.am	Wed Nov 12 22:10:24 2014 +0100
+++ b/Makefile.am	Wed Nov 12 22:10:25 2014 +0100
@@ -140,6 +140,8 @@
 	tests/extensions/date/basic.svtest \
 	tests/extensions/date/date-parts.svtest \
 	tests/extensions/date/zones.svtest \
+	tests/extensions/index/basic.svtest \
+	tests/extensions/index/errors.svtest \
 	tests/extensions/spamvirustest/spamtest.svtest \
 	tests/extensions/spamvirustest/virustest.svtest \
 	tests/extensions/spamvirustest/spamtestplus.svtest \
diff -r 578aca9c0ba1 -r 1d06b61cbaf3 configure.ac
--- a/configure.ac	Wed Nov 12 22:10:24 2014 +0100
+++ b/configure.ac	Wed Nov 12 22:10:25 2014 +0100
@@ -203,6 +203,7 @@
 src/lib-sieve/plugins/editheader/Makefile
 src/lib-sieve/plugins/metadata/Makefile
 src/lib-sieve/plugins/duplicate/Makefile
+src/lib-sieve/plugins/index/Makefile
 src/lib-sieve/plugins/vnd.dovecot/Makefile
 src/lib-sieve/plugins/vnd.dovecot/debug/Makefile
 src/lib-sieve-tool/Makefile
diff -r 578aca9c0ba1 -r 1d06b61cbaf3 src/lib-sieve/Makefile.am
--- a/src/lib-sieve/Makefile.am	Wed Nov 12 22:10:24 2014 +0100
+++ b/src/lib-sieve/Makefile.am	Wed Nov 12 22:10:25 2014 +0100
@@ -76,6 +76,7 @@
 	$(extdir)/ihave/libsieve_ext_ihave.la \
 	$(extdir)/editheader/libsieve_ext_editheader.la \
 	$(extdir)/duplicate/libsieve_ext_duplicate.la \
+	$(extdir)/index/libsieve_ext_index.la \
 	$(extdir)/vnd.dovecot/debug/libsieve_ext_debug.la \
 	$(unfinished_plugins)
 
diff -r 578aca9c0ba1 -r 1d06b61cbaf3 src/lib-sieve/plugins/Makefile.am
--- a/src/lib-sieve/plugins/Makefile.am	Wed Nov 12 22:10:24 2014 +0100
+++ b/src/lib-sieve/plugins/Makefile.am	Wed Nov 12 22:10:25 2014 +0100
@@ -22,6 +22,7 @@
 	ihave \
 	editheader \
 	duplicate \
+	index \
 	vnd.dovecot \
 	$(UNFINISHED)
 
diff -r 578aca9c0ba1 -r 1d06b61cbaf3 src/lib-sieve/plugins/index/Makefile.am
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/index/Makefile.am	Wed Nov 12 22:10:25 2014 +0100
@@ -0,0 +1,13 @@
+noinst_LTLIBRARIES = libsieve_ext_index.la
+
+AM_CPPFLAGS = \
+	-I$(srcdir)/../.. \
+	$(LIBDOVECOT_INCLUDE)
+
+libsieve_ext_index_la_SOURCES = \
+	ext-index-common.c \
+	ext-index.c \
+	tag-index.c
+
+noinst_HEADERS = \
+	ext-index-common.h
diff -r 578aca9c0ba1 -r 1d06b61cbaf3 src/lib-sieve/plugins/index/ext-index-common.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/index/ext-index-common.c	Wed Nov 12 22:10:25 2014 +0100
@@ -0,0 +1,15 @@
+/* Copyright (c) 2002-2014 Pigeonhole authors, see the included COPYING file
+ */
+
+#include "lib.h"
+#include "utc-offset.h"
+#include "str.h"
+
+#include "sieve-common.h"
+#include "sieve-stringlist.h"
+#include "sieve-code.h"
+#include "sieve-interpreter.h"
+#include "sieve-message.h"
+
+#include "ext-index-common.h"
+
diff -r 578aca9c0ba1 -r 1d06b61cbaf3 src/lib-sieve/plugins/index/ext-index-common.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/index/ext-index-common.h	Wed Nov 12 22:10:25 2014 +0100
@@ -0,0 +1,32 @@
+/* Copyright (c) 2002-2014 Pigeonhole authors, see the included COPYING file
+ */
+
+#ifndef __EXT_INDEX_COMMON_H
+#define __EXT_INDEX_COMMON_H
+
+#include "sieve-common.h"
+
+#include <time.h>
+
+#define SIEVE_EXT_INDEX_HDR_OVERRIDE_SEQUENCE 100
+
+/*
+ * Tagged arguments
+ */
+
+extern const struct sieve_argument_def index_tag;
+extern const struct sieve_argument_def last_tag;
+
+/*
+ * Operands
+ */
+
+extern const struct sieve_operand_def index_operand;
+
+/*
+ * Extension
+ */
+
+extern const struct sieve_extension_def index_extension;
+
+#endif /* __EXT_INDEX_COMMON_H */
diff -r 578aca9c0ba1 -r 1d06b61cbaf3 src/lib-sieve/plugins/index/ext-index.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/index/ext-index.c	Wed Nov 12 22:10:25 2014 +0100
@@ -0,0 +1,69 @@
+/* Copyright (c) 2002-2014 Pigeonhole authors, see the included COPYING file
+ */
+
+/* Extension index
+ * ------------------
+ *
+ * Authors: Stephan Bosch
+ * Specification: RFC 5260
+ * Implementation: full
+ * Status: testing
+ *
+ */
+
+#include "lib.h"
+#include "array.h"
+
+#include "sieve-common.h"
+#include "sieve-message.h"
+#include "sieve-extensions.h"
+#include "sieve-commands.h"
+
+#include "sieve-validator.h"
+#include "sieve-generator.h"
+#include "sieve-binary.h"
+#include "sieve-interpreter.h"
+#include "sieve-dump.h"
+
+#include "ext-index-common.h"
+
+/*
+ * Extension
+ */
+
+static bool ext_index_validator_load
+(const struct sieve_extension *ext, struct sieve_validator *validator);
+
+const struct sieve_extension_def index_extension = {
+	.name = "index",
+	.validator_load = ext_index_validator_load,
+	SIEVE_EXT_DEFINE_OPERAND(index_operand)
+};
+
+static bool ext_index_validator_load
+(const struct sieve_extension *ext, struct sieve_validator *valdtr)
+{
+	/* Register :index and :last tags with header, address and date test commands
+	 * and we don't care whether these command are registered or even whether
+	 * these will be registered at all. The validator handles either situation
+	 * gracefully.
+	 */
+	sieve_validator_register_external_tag
+		(valdtr, "header", ext, &index_tag, SIEVE_OPT_MESSAGE_OVERRIDE);
+	sieve_validator_register_external_tag
+		(valdtr, "header", ext, &last_tag, 0);
+
+	sieve_validator_register_external_tag
+		(valdtr, "address", ext, &index_tag, SIEVE_OPT_MESSAGE_OVERRIDE);
+	sieve_validator_register_external_tag
+		(valdtr, "address", ext, &last_tag, 0);
+
+	sieve_validator_register_external_tag
+		(valdtr, "date", ext, &index_tag, SIEVE_OPT_MESSAGE_OVERRIDE);
+	sieve_validator_register_external_tag
+		(valdtr, "date", ext, &last_tag, 0);
+
+	return TRUE;
+}
+
+
diff -r 578aca9c0ba1 -r 1d06b61cbaf3 src/lib-sieve/plugins/index/tag-index.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/index/tag-index.c	Wed Nov 12 22:10:25 2014 +0100
@@ -0,0 +1,272 @@
+/* Copyright (c) 2002-2014 Pigeonhole authors, see the included COPYING file
+ */
+
+#include "lib.h"
+#include "mail-storage.h"
+#include "mail-namespace.h"
+
+#include "sieve-common.h"
+#include "sieve-stringlist.h"
+#include "sieve-extensions.h"
+#include "sieve-commands.h"
+#include "sieve-binary.h"
+#include "sieve-code.h"
+#include "sieve-message.h"
+#include "sieve-result.h"
+#include "sieve-validator.h"
+#include "sieve-generator.h"
+
+#include "ext-index-common.h"
+
+/*
+ * Tagged argument
+ */
+
+static bool tag_index_validate
+	(struct sieve_validator *valdtr, struct sieve_ast_argument **arg,
+		struct sieve_command *cmd);
+static bool tag_index_generate
+	(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg,
+    struct sieve_command *context);
+
+const struct sieve_argument_def index_tag = {
+	"index",
+	NULL,
+	tag_index_validate,
+	NULL, NULL,
+	tag_index_generate
+};
+
+static bool tag_last_validate
+	(struct sieve_validator *valdtr, struct sieve_ast_argument **arg,
+		struct sieve_command *cmd);
+
+const struct sieve_argument_def last_tag = {
+	"last",
+	NULL,
+	tag_last_validate,
+	NULL, NULL, NULL
+};
+
+
+/*
+ * Header override
+ */
+
+static bool svmo_index_dump_context
+	(const struct sieve_message_override *svmo,
+		const struct sieve_dumptime_env *denv, sieve_size_t *address);
+static int svmo_index_read_context
+	(const struct sieve_message_override *svmo,
+		const struct sieve_runtime_env *renv, sieve_size_t *address,
+		void **ho_context);
+static int svmo_index_header_override
+	(const struct sieve_message_override *svmo,
+		const struct sieve_runtime_env *renv,
+		struct sieve_stringlist **headers);
+
+const struct sieve_message_override_def index_header_override = {
+	SIEVE_OBJECT("index", &index_operand, 0),
+	.sequence = SIEVE_EXT_INDEX_HDR_OVERRIDE_SEQUENCE,
+	.dump_context = svmo_index_dump_context,
+	.read_context = svmo_index_read_context,
+	.header_override = svmo_index_header_override
+};
+
+/*
+ * Operand
+ */
+
+static const struct sieve_extension_objects ext_header_overrides =
+	SIEVE_EXT_DEFINE_MESSAGE_OVERRIDE(index_header_override);
+
+const struct sieve_operand_def index_operand = {
+	"index operand",
+	&index_extension,
+	0,
+	&sieve_message_override_operand_class,
+	&ext_header_overrides
+};
+
+/*
+ * Tag data
+ */
+
+struct tag_index_data {
+	sieve_number_t fieldno;
+	unsigned int last:1;
+};
+
+/*
+ * Tag validation
+ */
+
+static bool tag_index_validate
+(struct sieve_validator *valdtr ATTR_UNUSED,
+	struct sieve_ast_argument **arg, struct sieve_command *cmd)


More information about the dovecot-cvs mailing list