dovecot-2.2-pigeonhole: lib-sieve: Implemented the foreverypart ...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Sun Nov 29 10:53:29 UTC 2015


details:   http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/feca1b976393
changeset: 2140:feca1b976393
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Sun Nov 29 11:50:59 2015 +0100
description:
lib-sieve: Implemented the foreverypart and mime extensions (RFC 5703).

diffstat:

 Makefile.am                                         |    2 +
 README                                              |    4 +-
 TODO                                                |    2 +-
 configure.ac                                        |    1 +
 src/lib-sieve/Makefile.am                           |    1 +
 src/lib-sieve/plugins/Makefile.am                   |    1 +
 src/lib-sieve/plugins/mime/Makefile.am              |   24 +
 src/lib-sieve/plugins/mime/cmd-break.c              |  273 +++++++
 src/lib-sieve/plugins/mime/cmd-foreverypart.c       |  339 +++++++++
 src/lib-sieve/plugins/mime/ext-foreverypart.c       |   62 +
 src/lib-sieve/plugins/mime/ext-mime-common.c        |   27 +
 src/lib-sieve/plugins/mime/ext-mime-common.h        |   80 ++
 src/lib-sieve/plugins/mime/ext-mime.c               |   77 ++
 src/lib-sieve/plugins/mime/tag-mime.c               |  704 ++++++++++++++++++++
 src/lib-sieve/sieve-extensions.c                    |    4 +-
 tests/extensions/mime/content-header.svtest         |  161 ++++
 tests/extensions/mime/errors.svtest                 |   54 +
 tests/extensions/mime/errors/address-mime-tag.sieve |   38 +
 tests/extensions/mime/errors/break.sieve            |  157 ++++
 tests/extensions/mime/errors/exists-mime-tag.sieve  |   43 +
 tests/extensions/mime/errors/foreverypart.sieve     |   45 +
 tests/extensions/mime/errors/header-mime-tag.sieve  |  100 ++
 tests/extensions/mime/execute.svtest                |   23 +
 tests/extensions/mime/execute/foreverypart.sieve    |    7 +
 24 files changed, 2226 insertions(+), 3 deletions(-)

diffs (truncated from 2381 to 300 lines):

diff -r 7c516d25ad50 -r feca1b976393 Makefile.am
--- a/Makefile.am	Sun Nov 29 11:50:44 2015 +0100
+++ b/Makefile.am	Sun Nov 29 11:50:59 2015 +0100
@@ -166,6 +166,8 @@
 	tests/extensions/duplicate/execute-vnd.svtest \
 	tests/extensions/metadata/execute.svtest \
 	tests/extensions/metadata/errors.svtest \
+	tests/extensions/mime/errors.svtest \
+	tests/extensions/mime/content-header.svtest \
 	tests/extensions/vnd.dovecot/debug/execute.svtest \
 	tests/extensions/vnd.dovecot/environment/basic.svtest \
 	tests/extensions/vnd.dovecot/environment/variables.svtest \
diff -r 7c516d25ad50 -r feca1b976393 README
--- a/README	Sun Nov 29 11:50:44 2015 +0100
+++ b/README	Sun Nov 29 11:50:59 2015 +0100
@@ -120,6 +120,8 @@
     mailbox (RFC 5490; Section 3): fully supported (v0.1.10+), but ACL
         permissions are not verified for mailboxexists.
     mboxmetadata and servermetadata (RFC 5490): fully supported (v0.4.7+)
+		foreverypart (RFC 5703; Section 3): fully supported (v0.4.10+).
+		mime (RFC 5703; Section 4): fully supported (v0.4.10+). 
     include (RFC 6609): fully supported (v0.4.0+)
     duplicate (RFC 7352): fully supported (v0.4.3+).
     regex (draft v08; not latest version): almost fully supported, but
@@ -154,7 +156,7 @@
   useful for Dovecot in particular, but many of them are. Currently, the
   author has taken notice of the following extensions:
 
-    foreverypart, mime, replace, enclose, and extracttext (RFC 5703): planned.
+    replace, enclose, and extracttext (RFC 5703): planned.
     imapsieve (RFC 6785): planned.
     envelope-dsn, envelope-deliverby, redirect-dsn and
       redirect-deliverby (RFC 6009): planned; depends on lib-smtp changes in
diff -r 7c516d25ad50 -r feca1b976393 TODO
--- a/TODO	Sun Nov 29 11:50:44 2015 +0100
+++ b/TODO	Sun Nov 29 11:50:59 2015 +0100
@@ -33,7 +33,7 @@
 	- Adjust Sieve script API to support asynchronous script retrieval to
 	  retrieve scripts in parallel when possible.
 * Implement message modification and extraction API in order to:
-	- Implement replace, enclose, foreverypart, mime and extracttext extensions
+	- Implement replace, enclose, and extracttext extensions
 * Improve error handling.
 	- Implement dropping errors in the user's mailbox as a mail message.
 * Finish body extension:
diff -r 7c516d25ad50 -r feca1b976393 configure.ac
--- a/configure.ac	Sun Nov 29 11:50:44 2015 +0100
+++ b/configure.ac	Sun Nov 29 11:50:59 2015 +0100
@@ -209,6 +209,7 @@
 src/lib-sieve/plugins/metadata/Makefile
 src/lib-sieve/plugins/duplicate/Makefile
 src/lib-sieve/plugins/index/Makefile
+src/lib-sieve/plugins/mime/Makefile
 src/lib-sieve/plugins/vnd.dovecot/Makefile
 src/lib-sieve/plugins/vnd.dovecot/debug/Makefile
 src/lib-sieve/plugins/vnd.dovecot/environment/Makefile
diff -r 7c516d25ad50 -r feca1b976393 src/lib-sieve/Makefile.am
--- a/src/lib-sieve/Makefile.am	Sun Nov 29 11:50:44 2015 +0100
+++ b/src/lib-sieve/Makefile.am	Sun Nov 29 11:50:59 2015 +0100
@@ -77,6 +77,7 @@
 	$(extdir)/duplicate/libsieve_ext_duplicate.la \
 	$(extdir)/index/libsieve_ext_index.la \
 	$(extdir)/metadata/libsieve_ext_metadata.la \
+	$(extdir)/mime/libsieve_ext_mime.la \
 	$(extdir)/vnd.dovecot/debug/libsieve_ext_debug.la \
 	$(extdir)/vnd.dovecot/environment/libsieve_ext_vnd_environment.la \
 	$(unfinished_plugins)
diff -r 7c516d25ad50 -r feca1b976393 src/lib-sieve/plugins/Makefile.am
--- a/src/lib-sieve/plugins/Makefile.am	Sun Nov 29 11:50:44 2015 +0100
+++ b/src/lib-sieve/plugins/Makefile.am	Sun Nov 29 11:50:59 2015 +0100
@@ -24,6 +24,7 @@
 	duplicate \
 	index \
 	metadata \
+	mime \
 	vnd.dovecot \
 	$(UNFINISHED)
 
diff -r 7c516d25ad50 -r feca1b976393 src/lib-sieve/plugins/mime/Makefile.am
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/mime/Makefile.am	Sun Nov 29 11:50:59 2015 +0100
@@ -0,0 +1,24 @@
+noinst_LTLIBRARIES = libsieve_ext_mime.la
+
+AM_CPPFLAGS = \
+	-I$(srcdir)/../.. \
+	-I$(srcdir)/../../util \
+	$(LIBDOVECOT_INCLUDE)
+
+commands = \
+	cmd-foreverypart.c \
+	cmd-break.c
+
+tags = \
+	tag-mime.c
+
+libsieve_ext_mime_la_SOURCES = \
+	ext-mime.c \
+	ext-foreverypart.c \
+	ext-mime-common.c \
+	$(commands) \
+	$(tags)
+
+noinst_HEADERS = \
+	ext-mime-common.h
+
diff -r 7c516d25ad50 -r feca1b976393 src/lib-sieve/plugins/mime/cmd-break.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sieve/plugins/mime/cmd-break.c	Sun Nov 29 11:50:59 2015 +0100
@@ -0,0 +1,273 @@
+/* Copyright (c) 2002-2015 Pigeonhole authors, see the included COPYING file
+ */
+
+#include "sieve-common.h"
+#include "sieve-code.h"
+#include "sieve-extensions.h"
+#include "sieve-commands.h"
+#include "sieve-validator.h"
+#include "sieve-generator.h"
+#include "sieve-interpreter.h"
+#include "sieve-binary.h"
+#include "sieve-dump.h"
+
+#include "ext-mime-common.h"
+
+#include <ctype.h>
+
+/* break
+ *
+ * Syntax:
+ *   break [":name" <name: string>]
+ *
+ */
+
+static bool cmd_break_registered
+	(struct sieve_validator *valdtr, const struct sieve_extension *ext,
+		struct sieve_command_registration *cmd_reg);
+static bool cmd_break_pre_validate
+	(struct sieve_validator *valdtr, struct sieve_command *cmd);
+static bool cmd_break_validate
+	(struct sieve_validator *valdtr, struct sieve_command *cmd);
+static bool cmd_break_generate
+	(const struct sieve_codegen_env *cgenv,
+		struct sieve_command *ctx);
+
+const struct sieve_command_def cmd_break = {
+	"break",
+	SCT_COMMAND,
+	0, 0, FALSE, FALSE,
+	cmd_break_registered,
+	cmd_break_pre_validate,
+	cmd_break_validate,
+	NULL,
+	cmd_break_generate,
+	NULL,
+};
+
+/*
+ * Tagged arguments
+ */
+
+/* Forward declarations */
+
+static bool cmd_break_validate_name_tag
+	(struct sieve_validator *valdtr, struct sieve_ast_argument **arg,
+		struct sieve_command *cmd);
+
+/* Argument objects */
+
+static const struct sieve_argument_def break_name_tag = {
+	"name",
+	NULL,
+	cmd_break_validate_name_tag,
+	NULL, NULL, NULL
+};
+
+/*
+ * Break operation
+ */
+
+static bool cmd_break_operation_dump
+	(const struct sieve_dumptime_env *denv, sieve_size_t *address);
+static int cmd_break_operation_execute
+	(const struct sieve_runtime_env *renv, sieve_size_t *address);
+
+const struct sieve_operation_def break_operation = {
+	"break",
+	&foreverypart_extension,
+	EXT_FOREVERYPART_OPERATION_BREAK,
+	cmd_break_operation_dump,
+	cmd_break_operation_execute
+};
+
+/*
+ * Validation data
+ */
+
+struct cmd_break_data {
+	struct sieve_ast_argument *name;
+	struct sieve_command *loop_cmd;
+};
+
+/*
+ * Tag validation
+ */
+
+static bool cmd_break_validate_name_tag
+(struct sieve_validator *valdtr, struct sieve_ast_argument **arg,
+    struct sieve_command *cmd)
+{
+	struct cmd_break_data *data =
+		(struct cmd_break_data *)cmd->data;
+	struct sieve_ast_argument *tag = *arg;
+
+	/* Detach the tag itself */
+	*arg = sieve_ast_arguments_detach(*arg, 1);
+
+	/* Check syntax:
+	 *   :name <string>
+	 */
+	if ( !sieve_validate_tag_parameter
+		(valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING, TRUE) )
+		return FALSE;
+	data->name = *arg;
+
+	/* Skip parameter */
+	*arg = sieve_ast_argument_next(*arg);
+	return TRUE;
+}
+
+/*
+ * Command registration
+ */
+
+static bool cmd_break_registered
+(struct sieve_validator *valdtr, const struct sieve_extension *ext,
+	struct sieve_command_registration *cmd_reg)
+{
+	sieve_validator_register_tag
+		(valdtr, cmd_reg, ext, &break_name_tag, 0);
+	
+	return TRUE;
+}
+
+/*
+ * Command validation
+ */
+
+static bool cmd_break_pre_validate
+(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd)
+{
+	struct cmd_break_data *data;
+	pool_t pool = sieve_command_pool(cmd);
+	
+	data = p_new(pool, struct cmd_break_data, 1);
+	cmd->data = data;
+	return TRUE;
+}
+
+static bool cmd_break_validate
+(struct sieve_validator *valdtr, struct sieve_command *cmd)
+{
+	struct cmd_break_data *data =
+		(struct cmd_break_data *)cmd->data;
+	struct sieve_ast_node *node = cmd->ast_node;
+	const char *name =	( data->name == NULL ?
+		NULL : sieve_ast_argument_strc(data->name) );
+
+	i_assert(node != NULL);
+	while ( node != NULL && node->command != NULL ) {
+		if ( sieve_command_is(node->command, cmd_foreverypart) ) {
+			struct ext_foreverypart_loop *loop =
+				(struct ext_foreverypart_loop *)node->command->data;
+			if ( name == NULL ||
+				(name != NULL && loop->name != NULL &&
+					strcmp(name, loop->name) == 0) ) {
+				data->loop_cmd = node->command;
+				break;
+			}
+		}
+		node = sieve_ast_node_parent(node);
+	}
+
+	if ( data->loop_cmd == NULL ) {
+		if ( name == NULL ) {
+			sieve_command_validate_error(valdtr, cmd,
+				"the break command is not placed inside "
+				"a foreverypart loop");
+		} else {
+			sieve_command_validate_error(valdtr, cmd,
+				"the break command is not placed inside "
+				"a foreverypart loop named `%s'",
+				name);
+		}
+		return FALSE;
+	}
+
+	return TRUE;
+}
+


More information about the dovecot-cvs mailing list