dovecot-1.2-sieve: Plugin support: added -P parameter to all sie...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Thu Jan 7 03:58:29 EET 2010


details:   http://hg.rename-it.nl/dovecot-1.2-sieve/rev/e3ed9a03a28b
changeset: 1192:e3ed9a03a28b
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Thu Jan 07 02:58:08 2010 +0100
description:
Plugin support: added -P parameter to all sieve tools and enabled dict support.

diffstat:

 src/lib-sieve-tool/Makefile.am  |   1 +
 src/lib-sieve-tool/sieve-tool.c |  34 ++++++++++++++++-
 src/lib-sieve-tool/sieve-tool.h |   5 ++-
 src/sieve-tools/Makefile.am     |   6 +++
 src/sieve-tools/sieve-filter.c  |   4 +-
 src/sieve-tools/sieve-test.c    |  27 ++++++++++++-
 src/sieve-tools/sievec.c        |  30 +++++++++++++-
 src/sieve-tools/sieved.c        |  30 +++++++++++++-
 src/testsuite/Makefile.am       |   6 +++
 src/testsuite/testsuite.c       |  57 ++++++++++++++++------------
 10 files changed, 163 insertions(+), 37 deletions(-)

diffs (truncated from 522 to 300 lines):

diff -r e03187e12739 -r e3ed9a03a28b src/lib-sieve-tool/Makefile.am
--- a/src/lib-sieve-tool/Makefile.am	Thu Jan 07 02:56:58 2010 +0100
+++ b/src/lib-sieve-tool/Makefile.am	Thu Jan 07 02:58:08 2010 +0100
@@ -4,6 +4,7 @@
 	-I$(top_srcdir)/src/lib-sieve \
 	-I$(dovecot_incdir) \
 	-I$(dovecot_incdir)/src/lib \
+	-I$(dovecot_incdir)/src/lib-dict \
 	-I$(dovecot_incdir)/src/lib-mail \
 	-I$(dovecot_incdir)/src/lib-index \
 	-I$(dovecot_incdir)/src/lib-storage \
diff -r e03187e12739 -r e3ed9a03a28b src/lib-sieve-tool/sieve-tool.c
--- a/src/lib-sieve-tool/sieve-tool.c	Thu Jan 07 02:56:58 2010 +0100
+++ b/src/lib-sieve-tool/sieve-tool.c	Thu Jan 07 02:58:08 2010 +0100
@@ -3,12 +3,16 @@
 
 #include "lib.h"
 #include "lib-signals.h"
+#include "array.h"
 #include "ioloop.h"
 #include "ostream.h"
 #include "hostpid.h"
+#include "dict.h"
 #include "mail-storage.h"
 
 #include "sieve.h"
+#include "sieve-plugins.h"
+
 #include "sieve-tool.h"
 
 #include <stdio.h>
@@ -71,7 +75,7 @@
  * Initialization
  */
 
-void sieve_tool_init(const struct sieve_environment *env) 
+void sieve_tool_init(void)
 {
 	lib_init();
 
@@ -83,6 +87,11 @@
 	lib_signals_ignore(SIGPIPE, TRUE);
 	lib_signals_ignore(SIGALRM, FALSE);
 
+	dict_drivers_register_builtin();
+}
+
+void sieve_tool_sieve_init(const struct sieve_environment *env)
+{
 	if ( env == NULL ) env = &sieve_tool_sieve_env;
 
 	if ( (sieve_instance=sieve_init(env, NULL)) == NULL ) 
@@ -93,6 +102,8 @@
 {
 	sieve_deinit(&sieve_instance);
 	
+	dict_drivers_unregister_builtin();
+
 	lib_signals_deinit();
 
 	io_loop_destroy(&ioloop);
@@ -148,6 +159,27 @@
 		*sender = "sender at example.com";
 }
 
+void sieve_tool_load_plugins(ARRAY_TYPE(const_string) *plugins)
+{
+	unsigned int i, count;
+	const char * const*_plugins;
+
+	_plugins = array_get(plugins, &count);
+	for ( i = 0; i < count; i++ ) {
+		const char *path, *file = strrchr(_plugins[i], '/');
+
+		if ( file != NULL ) {
+			path = t_strdup_until(_plugins[i], file);
+			file = file+1;
+		} else {
+			path = NULL;
+			file = _plugins[i];
+		}
+
+		sieve_plugins_load(sieve_instance, path, file);		
+	}
+}
+
 /*
  * Sieve script handling
  */
diff -r e03187e12739 -r e3ed9a03a28b src/lib-sieve-tool/sieve-tool.h
--- a/src/lib-sieve-tool/sieve-tool.h	Thu Jan 07 02:56:58 2010 +0100
+++ b/src/lib-sieve-tool/sieve-tool.h	Thu Jan 07 02:58:08 2010 +0100
@@ -21,7 +21,8 @@
  * Initialization
  */
 
-void sieve_tool_init(const struct sieve_environment *env);
+void sieve_tool_init(void);
+void sieve_tool_sieve_init(const struct sieve_environment *env);
 void sieve_tool_deinit(void);
 
 /*
@@ -33,6 +34,8 @@
 void sieve_tool_get_envelope_data
 	(struct mail *mail, const char **recipient, const char **sender);
 
+void sieve_tool_load_plugins(ARRAY_TYPE(const_string) *plugins);
+
 /*
  * Sieve script handling
  */
diff -r e03187e12739 -r e3ed9a03a28b src/sieve-tools/Makefile.am
--- a/src/sieve-tools/Makefile.am	Thu Jan 07 02:56:58 2010 +0100
+++ b/src/sieve-tools/Makefile.am	Thu Jan 07 02:58:08 2010 +0100
@@ -14,6 +14,7 @@
 	-I./debug \
 	-I$(dovecot_incdir) \
 	-I$(dovecot_incdir)/src/lib \
+	-I$(dovecot_incdir)/src/lib-dict \
 	-I$(dovecot_incdir)/src/lib-mail \
 	-I$(dovecot_incdir)/src/lib-index \
 	-I$(dovecot_incdir)/src/lib-storage \
@@ -23,10 +24,15 @@
 	$(top_srcdir)/src/lib-sieve/libsieve.la \
 	$(top_srcdir)/src/lib-sieve-tool/libsieve-tool.la \
 	./debug/libsieve_ext_debug.la \
+    $(dovecot_incdir)/src/lib-dict/libdict.a \
 	$(STORAGE_LIBS) 
 
+unused_objects = \
+	$(dovecot_incdir)/src/lib-dict/dict.o
+
 ldadd = \
 	$(libs) \
+	$(unused_objects) \
  	$(LIBICONV) \
 	$(RAND_LIBS) \
 	$(MODULE_LIBS)
diff -r e03187e12739 -r e3ed9a03a28b src/sieve-tools/sieve-filter.c
--- a/src/sieve-tools/sieve-filter.c	Thu Jan 07 02:56:58 2010 +0100
+++ b/src/sieve-tools/sieve-filter.c	Thu Jan 07 02:58:08 2010 +0100
@@ -231,7 +231,7 @@
 	const char *user, *home, *folder;
 	int i;
 
-	sieve_tool_init(NULL);
+	sieve_tool_init();
 	
 	/* Parse arguments */
 	scriptfile = recipient = sender = extensions = src_mailstore = dst_mailstore 
@@ -276,6 +276,8 @@
 		i_fatal("Missing <mailstore> argument");
 	}
 
+	sieve_tool_sieve_init(NULL);
+
 	if ( extensions != NULL ) {
 		sieve_set_extensions(sieve_instance, extensions);
 	}
diff -r e03187e12739 -r e3ed9a03a28b src/sieve-tools/sieve-test.c
--- a/src/sieve-tools/sieve-test.c	Thu Jan 07 02:56:58 2010 +0100
+++ b/src/sieve-tools/sieve-test.c	Thu Jan 07 02:58:08 2010 +0100
@@ -40,7 +40,8 @@
 "Usage: sieve-test [-c] [-d <dump-filename>] [-e] [-f <envelope-sender>]\n"
 "                  [-l <mail-location>] [-m <default-mailbox>]\n" 
 "                  [-r <recipient-address>] [-s <script-file>]\n"
-"                  [-t] [-x <extensions>] <script-file> <mail-file>\n"
+"                  [-t] [-P <plugin>] [-x <extensions>]\n"
+"                  <script-file> <mail-file>\n"
 	);
 }
 
@@ -90,7 +91,8 @@
 
 int main(int argc, char **argv) 
 {
-	ARRAY_DEFINE(scriptfiles, const char *);
+	ARRAY_TYPE(const_string) scriptfiles;
+	ARRAY_TYPE(const_string) plugins;
 	const char *scriptfile, *recipient, *sender, *mailbox, *dumpfile, *mailfile, 
 		*mailloc, *extensions; 
 	const char *user, *home;
@@ -108,9 +110,10 @@
 	bool trace = FALSE;
 	int ret;
 
-	sieve_tool_init(NULL);
+	sieve_tool_init();
 	
 	t_array_init(&scriptfiles, 16);
+	t_array_init(&plugins, 4);
 
 	/* Parse arguments (ugly) */
 	scriptfile = recipient = sender = mailbox = dumpfile = mailfile = mailloc = 
@@ -187,6 +190,18 @@
 			/* runtime trace */
 			trace = TRUE;
 #endif
+		} else if (strcmp(argv[i], "-P") == 0) {
+			const char *plugin;
+			
+			/* scriptfile executed before main script */
+			i++;
+			if (i == argc) {
+				print_help();
+				i_fatal("Missing -P argument");
+			}
+				
+			plugin = t_strdup(argv[i]);
+			array_append(&plugins, &plugin, 1);
 		} else if ( scriptfile == NULL ) {
 			scriptfile = argv[i];
 		} else if ( mailfile == NULL ) {
@@ -207,6 +222,12 @@
 		i_fatal("Missing <mail-file> argument");
 	}
 
+	sieve_tool_sieve_init(NULL);
+
+	if ( array_count(&plugins) > 0 ) {
+		sieve_tool_load_plugins(&plugins);
+	}
+
 	if ( extensions != NULL ) {
 		sieve_set_extensions(sieve_instance, extensions);
 	}
diff -r e03187e12739 -r e3ed9a03a28b src/sieve-tools/sievec.c
--- a/src/sieve-tools/sievec.c	Thu Jan 07 02:56:58 2010 +0100
+++ b/src/sieve-tools/sievec.c	Thu Jan 07 02:58:08 2010 +0100
@@ -2,6 +2,7 @@
  */
 
 #include "lib.h"
+#include "array.h"
 
 #include "sieve.h"
 #include "sieve-extensions.h"
@@ -26,7 +27,8 @@
 static void print_help(void)
 {
 	printf(
-"Usage: sievec [-d] [-x <extensions>] <script-file> [<out-file>]\n"
+"Usage: sievec [-d] [-P <plugin>] [-x <extensions>] \n"
+"              <script-file> [<out-file>]\n"
 	);
 }
 
@@ -34,14 +36,18 @@
  * Tool implementation
  */
 
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
+	ARRAY_TYPE(const_string) plugins;
 	int i;
 	struct stat st;
 	struct sieve_binary *sbin;
 	bool dump = FALSE;
 	const char *scriptfile, *outfile, *extensions;
 				
-	sieve_tool_init(NULL);
+	sieve_tool_init();
+
+	t_array_init(&plugins, 4);
 
 	scriptfile = outfile = extensions = NULL;
 	for (i = 1; i < argc; i++) {
@@ -56,6 +62,18 @@
 				i_fatal("Missing -x argument");
 			}
 			extensions = argv[i];
+		} else if (strcmp(argv[i], "-P") == 0) {
+			const char *plugin;
+
+			/* scriptfile executed before main script */
+			i++;
+			if (i == argc) {
+				print_help();
+				i_fatal("Missing -P argument");
+			}
+
+			plugin = t_strdup(argv[i]);
+			array_append(&plugins, &plugin, 1);
 		} else if ( scriptfile == NULL ) {
 			scriptfile = argv[i];
 		} else if ( outfile == NULL ) {
@@ -74,6 +92,12 @@
 	if ( outfile == NULL && dump )
 		outfile = "-";	
 
+	sieve_tool_sieve_init(NULL);
+
+	if ( array_count(&plugins) > 0 ) {
+		sieve_tool_load_plugins(&plugins);
+	}
+
 	if ( extensions != NULL ) {
 		sieve_set_extensions(sieve_instance, extensions);
 	}


More information about the dovecot-cvs mailing list