dovecot-2.2-pigeonhole: lib-sieve: Added final result execution ...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Wed May 7 18:03:29 UTC 2014


details:   http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/3476d8bc0dc3
changeset: 1852:3476d8bc0dc3
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Wed May 07 20:03:10 2014 +0200
description:
lib-sieve: Added final result execution stage for the duplicate extension.
This way, a duplicate is only marked when the script execution succeeds, as required in the specification.

diffstat:

 src/lib-sieve/cmd-discard.c                            |  10 +-
 src/lib-sieve/cmd-redirect.c                           |  15 +-
 src/lib-sieve/ext-reject.c                             |  15 +-
 src/lib-sieve/plugins/duplicate/ext-duplicate-common.c |  44 ++++----
 src/lib-sieve/plugins/enotify/cmd-notify.c             |  13 +-
 src/lib-sieve/plugins/notify/cmd-notify.c              |  13 +-
 src/lib-sieve/plugins/vacation/cmd-vacation.c          |  15 +-
 src/lib-sieve/sieve-actions.c                          |  19 +--
 src/lib-sieve/sieve-actions.h                          |  10 +-
 src/lib-sieve/sieve-result.c                           |  82 +++++++++++------
 src/plugins/sieve-extprograms/cmd-pipe.c               |  14 +-
 11 files changed, 124 insertions(+), 126 deletions(-)

diffs (truncated from 424 to 300 lines):

diff -r d1d4454866ad -r 3476d8bc0dc3 src/lib-sieve/cmd-discard.c
--- a/src/lib-sieve/cmd-discard.c	Mon May 05 17:09:10 2014 +0200
+++ b/src/lib-sieve/cmd-discard.c	Wed May 07 20:03:10 2014 +0200
@@ -63,13 +63,9 @@
 		const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep);
 
 const struct sieve_action_def act_discard = {
-	"discard",
-	0,
-	NULL, NULL, NULL,
-	act_discard_print,
-	NULL, NULL,
-	act_discard_commit,
-	NULL
+	.name = "discard",
+	.print = act_discard_print,
+	.commit = act_discard_commit,
 };
 
 /*
diff -r d1d4454866ad -r 3476d8bc0dc3 src/lib-sieve/cmd-redirect.c
--- a/src/lib-sieve/cmd-redirect.c	Mon May 05 17:09:10 2014 +0200
+++ b/src/lib-sieve/cmd-redirect.c	Wed May 07 20:03:10 2014 +0200
@@ -92,15 +92,12 @@
 		void *tr_context, bool *keep);
 
 const struct sieve_action_def act_redirect = {
-	"redirect",
-	SIEVE_ACTFLAG_TRIES_DELIVER,
-	act_redirect_equals,
-	act_redirect_check_duplicate,
-	NULL,
-	act_redirect_print,
-	NULL, NULL,
-	act_redirect_commit,
-	NULL
+	.name = "redirect",
+	.flags = SIEVE_ACTFLAG_TRIES_DELIVER,
+	.equals = act_redirect_equals,
+	.check_duplicate = act_redirect_check_duplicate,
+	.print = act_redirect_print,
+	.commit = act_redirect_commit
 };
 
 struct act_redirect_context {
diff -r d1d4454866ad -r 3476d8bc0dc3 src/lib-sieve/ext-reject.c
--- a/src/lib-sieve/ext-reject.c	Mon May 05 17:09:10 2014 +0200
+++ b/src/lib-sieve/ext-reject.c	Wed May 07 20:03:10 2014 +0200
@@ -186,15 +186,12 @@
 		const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep);
 
 const struct sieve_action_def act_reject = {
-	"reject",
-	SIEVE_ACTFLAG_SENDS_RESPONSE,
-	NULL,
-	act_reject_check_duplicate,
-	act_reject_check_conflict,
-	act_reject_print,
-	NULL, NULL,
-	act_reject_commit,
-	NULL
+	.name = "reject",
+	.flags = SIEVE_ACTFLAG_SENDS_RESPONSE,
+	.check_duplicate = act_reject_check_duplicate,
+	.check_conflict = act_reject_check_conflict,
+	.print = act_reject_print,
+	.commit = act_reject_commit,
 };
 
 struct act_reject_context {
diff -r d1d4454866ad -r 3476d8bc0dc3 src/lib-sieve/plugins/duplicate/ext-duplicate-common.c
--- a/src/lib-sieve/plugins/duplicate/ext-duplicate-common.c	Mon May 05 17:09:10 2014 +0200
+++ b/src/lib-sieve/plugins/duplicate/ext-duplicate-common.c	Wed May 07 20:03:10 2014 +0200
@@ -15,6 +15,7 @@
 #include "sieve-message.h"
 #include "sieve-code.h"
 #include "sieve-runtime.h"
+#include "sieve-interpreter.h"
 #include "sieve-actions.h"
 #include "sieve-result.h"
 
@@ -78,18 +79,14 @@
 static void act_duplicate_mark_print
 	(const struct sieve_action *action,
 		const struct sieve_result_print_env *rpenv, bool *keep);
-static int act_duplicate_mark_commit
+static void act_duplicate_mark_finish
 	(const struct sieve_action *action,
-		const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep);
+		const struct sieve_action_exec_env *aenv, void *tr_context, int status);
 
 static const struct sieve_action_def act_duplicate_mark = {
-	"duplicate_mark",
-	0,
-	NULL, NULL, NULL,
-	act_duplicate_mark_print,
-	NULL, NULL,
-	act_duplicate_mark_commit,
-	NULL
+	.name = "duplicate_mark",
+	.print = act_duplicate_mark_print,
+	.finish = act_duplicate_mark_finish
 };
 
 static void act_duplicate_mark_print
@@ -108,27 +105,24 @@
 	}
 }
 
-// FIXME: at commit phase the sieve script is still not guaranteed to finish
-//         successfully. We need a new final stage in Sieve result execution.
-static int act_duplicate_mark_commit
+static void act_duplicate_mark_finish
 (const struct sieve_action *action,
 	const struct sieve_action_exec_env *aenv,
-	void *tr_context ATTR_UNUSED, bool *keep ATTR_UNUSED)
+	void *tr_context ATTR_UNUSED, int status)
 {
 	const struct sieve_script_env *senv = aenv->scriptenv;
 	struct act_duplicate_mark_data *data =
 		(struct act_duplicate_mark_data *) action->context;
 
-	/* Message was handled successfully until now, so track duplicate for this
-	 * message.
-	 */
-	sieve_action_duplicate_mark
-		(senv, data->hash, sizeof(data->hash), ioloop_time + data->period);
-	
-	return SIEVE_EXEC_OK;
+	if ( status == SIEVE_EXEC_OK ) {
+		/* Message was handled successfully, so track duplicate for this
+		 * message.
+		 */
+		sieve_action_duplicate_mark
+			(senv, data->hash, sizeof(data->hash), ioloop_time + data->period);
+	}
 }
 
-
 /*
  * Duplicate checking
  */
@@ -181,7 +175,13 @@
 	pool_t msg_pool = NULL, result_pool = NULL;
 	struct act_duplicate_mark_data *act;
 
-	if ( !sieve_action_duplicate_check_available(senv) || value == NULL )
+	if ( !sieve_action_duplicate_check_available(senv) ) {
+		sieve_runtime_warning(renv, NULL, "duplicate test: "
+			"duplicate checking not available in this context");
+		return 0;
+	}
+		
+	if ( value == NULL )
 		return 0;
 
 	/* Get context; find out whether duplicate was checked earlier */
diff -r d1d4454866ad -r 3476d8bc0dc3 src/lib-sieve/plugins/enotify/cmd-notify.c
--- a/src/lib-sieve/plugins/enotify/cmd-notify.c	Mon May 05 17:09:10 2014 +0200
+++ b/src/lib-sieve/plugins/enotify/cmd-notify.c	Wed May 07 20:03:10 2014 +0200
@@ -143,15 +143,10 @@
 /* Action object */
 
 const struct sieve_action_def act_notify = {
-	"notify",
-	0,
-	NULL,
-	act_notify_check_duplicate,
-	NULL,
-	act_notify_print,
-	NULL, NULL,
-	act_notify_commit,
-	NULL
+	.name = "notify",
+	.check_duplicate =act_notify_check_duplicate,
+	.print = act_notify_print,
+	.commit = act_notify_commit,
 };
 
 /*
diff -r d1d4454866ad -r 3476d8bc0dc3 src/lib-sieve/plugins/notify/cmd-notify.c
--- a/src/lib-sieve/plugins/notify/cmd-notify.c	Mon May 05 17:09:10 2014 +0200
+++ b/src/lib-sieve/plugins/notify/cmd-notify.c	Wed May 07 20:03:10 2014 +0200
@@ -153,15 +153,10 @@
 /* Action object */
 
 const struct sieve_action_def act_notify_old = {
-	"notify",
-	0,
-	NULL,
-	act_notify_check_duplicate,
-	NULL,
-	act_notify_print,
-	NULL, NULL,
-	act_notify_commit,
-	NULL
+	.name = "notify",
+	.check_duplicate = act_notify_check_duplicate,
+	.print = act_notify_print,
+	.commit = act_notify_commit
 };
 
 /*
diff -r d1d4454866ad -r 3476d8bc0dc3 src/lib-sieve/plugins/vacation/cmd-vacation.c
--- a/src/lib-sieve/plugins/vacation/cmd-vacation.c	Mon May 05 17:09:10 2014 +0200
+++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c	Wed May 07 20:03:10 2014 +0200
@@ -197,15 +197,12 @@
 /* Action object */
 
 const struct sieve_action_def act_vacation = {
-	"vacation",
-	SIEVE_ACTFLAG_SENDS_RESPONSE,
-	NULL,
-	act_vacation_check_duplicate,
-	act_vacation_check_conflict,
-	act_vacation_print,
-	NULL, NULL,
-	act_vacation_commit,
-	NULL
+	.name = "vacation",
+	.flags = SIEVE_ACTFLAG_SENDS_RESPONSE,
+	.check_duplicate = act_vacation_check_duplicate,
+	.check_conflict = act_vacation_check_conflict,
+	.print = act_vacation_print,
+	.commit = act_vacation_commit
 };
 
 /* Action context information */
diff -r d1d4454866ad -r 3476d8bc0dc3 src/lib-sieve/sieve-actions.c
--- a/src/lib-sieve/sieve-actions.c	Mon May 05 17:09:10 2014 +0200
+++ b/src/lib-sieve/sieve-actions.c	Wed May 07 20:03:10 2014 +0200
@@ -206,16 +206,15 @@
 /* Action object */
 
 const struct sieve_action_def act_store = {
-	"store",
-	SIEVE_ACTFLAG_TRIES_DELIVER,
-	act_store_equals,
-	act_store_check_duplicate,
-	NULL,
-	act_store_print,
-	act_store_start,
-	act_store_execute,
-	act_store_commit,
-	act_store_rollback,
+	.name = "store",
+	.flags = SIEVE_ACTFLAG_TRIES_DELIVER,
+	.equals = act_store_equals,
+	.check_duplicate = act_store_check_duplicate,
+	.print = act_store_print,
+	.start = act_store_start,
+	.execute = act_store_execute,
+	.commit = act_store_commit,
+	.rollback = act_store_rollback,
 };
 
 /* API */
diff -r d1d4454866ad -r 3476d8bc0dc3 src/lib-sieve/sieve-actions.h
--- a/src/lib-sieve/sieve-actions.h	Mon May 05 17:09:10 2014 +0200
+++ b/src/lib-sieve/sieve-actions.h	Wed May 07 20:03:10 2014 +0200
@@ -77,10 +77,16 @@
 			const struct sieve_action_exec_env *aenv, void *tr_context);
 	int (*commit)
 		(const struct sieve_action *action,
-			const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep);
+			const struct sieve_action_exec_env *aenv, void *tr_context,
+			bool *keep);
 	void (*rollback)
 		(const struct sieve_action *action,
-			const struct sieve_action_exec_env *aenv, void *tr_context, bool success);
+			const struct sieve_action_exec_env *aenv, void *tr_context,
+			bool success);
+	void (*finish)
+		(const struct sieve_action *action,
+			const struct sieve_action_exec_env *aenv, void *tr_context,
+			int status);
 };
 
 /*
diff -r d1d4454866ad -r 3476d8bc0dc3 src/lib-sieve/sieve-result.c
--- a/src/lib-sieve/sieve-result.c	Mon May 05 17:09:10 2014 +0200
+++ b/src/lib-sieve/sieve-result.c	Wed May 07 20:03:10 2014 +0200
@@ -1002,7 +1002,7 @@
 		}
 	}
 
-	/* Finish keep action */
+	/* Commit keep action */
 	if ( status == SIEVE_EXEC_OK ) {
 		bool dummy = TRUE;
 
@@ -1020,14 +1020,18 @@
 					(sef, &act_keep, &result->action_env, tr_context, &keep);
 			rsef = rsef->next;
 		}
-
-		return status;
+	} else {
+		/* Failed, rollback */
+		if ( act_keep.def->rollback != NULL )


More information about the dovecot-cvs mailing list