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

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Fri Jan 8 00:58:46 EET 2010


details:   http://hg.rename-it.nl/dovecot-2.0-sieve/rev/e3d3d82febe3
changeset: 1189:e3d3d82febe3
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Thu Jan 07 23:04:23 2010 +0100
description:
Plugin support: added -P parameter to all sieve tools and enabled dict support.

diffstat:

 configure.in                      |   6 +++---
 src/lib-sieve-tool/sieve-tool.c   |  30 +++++++++++++++++++++++++++++-
 src/lib-sieve-tool/sieve-tool.h   |   5 ++++-
 src/plugins/lda-sieve/Makefile.am |   1 +
 src/sieve-tools/sieve-filter.c    |   4 +++-
 src/sieve-tools/sieve-test.c      |  26 ++++++++++++++++++++++----
 src/sieve-tools/sievec.c          |  30 +++++++++++++++++++++++++++---
 src/sieve-tools/sieved.c          |  30 +++++++++++++++++++++++++++---
 src/testsuite/testsuite.c         |  44 +++++++++++++++++++-------------------------
 9 files changed, 135 insertions(+), 41 deletions(-)

diffs (truncated from 468 to 300 lines):

diff -r 7138e5d66a42 -r e3d3d82febe3 configure.in
--- a/configure.in	Thu Jan 07 22:26:29 2010 +0100
+++ b/configure.in	Thu Jan 07 23:04:23 2010 +0100
@@ -105,13 +105,13 @@
   LIBDOVECOT_INCLUDE=' \
     -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-storage \
     -I$(dovecot_incdir)/src/lib-imap \
     -I$(dovecot_incdir)/src/lib-master'
 
   LIBDOVECOT_LDA_INCLUDE=' \
-    -I$(dovecot_incdir)/src/lib-dict \
     -I$(dovecot_incdir)/src/lib-lda \
     -I$(dovecot_incdir)/src/lda'
 
@@ -130,8 +130,8 @@
   LIBDOVECOT_STORAGE='$(dovecot_libdir)/libdovecot-storage.la'
 
   LIBDOVECOT_INCLUDE='-I$(dovecot_incdir)'
-  LIBDOVECOT_LDA_INCLUDE='-I$(dovecot_incdir)'
-  LIBDOVECOT_STORAGE_INCLUDE='-I$(dovecot_incdir)'
+  LIBDOVECOT_LDA_INCLUDE=''
+  LIBDOVECOT_STORAGE_INCLUDE=''
 fi
 
 dovecot_pkglibexecdir='$(libexecdir)/dovecot'
diff -r 7138e5d66a42 -r e3d3d82febe3 src/lib-sieve-tool/sieve-tool.c
--- a/src/lib-sieve-tool/sieve-tool.c	Thu Jan 07 22:26:29 2010 +0100
+++ b/src/lib-sieve-tool/sieve-tool.c	Thu Jan 07 23:04:23 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>
@@ -74,7 +78,7 @@
 /* HACK */
 static bool _init_lib = FALSE;
 
-void sieve_tool_init(const struct sieve_environment *env, bool init_lib) 
+void sieve_tool_init(bool init_lib) 
 {
 	_init_lib = init_lib;
 
@@ -89,7 +93,10 @@
 		lib_signals_ignore(SIGPIPE, TRUE);
 		lib_signals_ignore(SIGALRM, FALSE);
 	}
+}
 
+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 )
@@ -159,6 +166,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 7138e5d66a42 -r e3d3d82febe3 src/lib-sieve-tool/sieve-tool.h
--- a/src/lib-sieve-tool/sieve-tool.h	Thu Jan 07 22:26:29 2010 +0100
+++ b/src/lib-sieve-tool/sieve-tool.h	Thu Jan 07 23:04:23 2010 +0100
@@ -23,7 +23,8 @@
  * Initialization
  */
 
-void sieve_tool_init(const struct sieve_environment *env, bool init_lib);
+void sieve_tool_init(bool init_lib);
+void sieve_tool_sieve_init(const struct sieve_environment *env);
 void sieve_tool_deinit(void);
 
 /*
@@ -35,6 +36,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 7138e5d66a42 -r e3d3d82febe3 src/plugins/lda-sieve/Makefile.am
--- a/src/plugins/lda-sieve/Makefile.am	Thu Jan 07 22:26:29 2010 +0100
+++ b/src/plugins/lda-sieve/Makefile.am	Thu Jan 07 23:04:23 2010 +0100
@@ -1,6 +1,7 @@
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib-sieve \
 	$(LIBDOVECOT_INCLUDE) \
+	$(LIBDOVECOT_DICT_INCLUDE) \
 	$(LIBDOVECOT_LDA_INCLUDE)
 
 lib90_sieve_plugin_la_LDFLAGS = -module -avoid-version
diff -r 7138e5d66a42 -r e3d3d82febe3 src/sieve-tools/sieve-filter.c
--- a/src/sieve-tools/sieve-filter.c	Thu Jan 07 22:26:29 2010 +0100
+++ b/src/sieve-tools/sieve-filter.c	Thu Jan 07 23:04:23 2010 +0100
@@ -231,7 +231,7 @@
 	const char *user, *home, *folder;
 	int i;
 
-	sieve_tool_init(NULL, FALSE);
+	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, FALSE);
+
 	if ( extensions != NULL ) {
 		sieve_set_extensions(sieve_instance, extensions);
 	}
diff -r 7138e5d66a42 -r e3d3d82febe3 src/sieve-tools/sieve-test.c
--- a/src/sieve-tools/sieve-test.c	Thu Jan 07 22:26:29 2010 +0100
+++ b/src/sieve-tools/sieve-test.c	Thu Jan 07 23:04:23 2010 +0100
@@ -48,7 +48,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"
 	);
 }
 
@@ -107,7 +108,8 @@
 	struct mail_storage_service_user *service_user;
 	struct mail_storage_service_input service_input;
 	struct mail_user *mail_user_dovecot = NULL;
-	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, *errstr;
@@ -125,11 +127,12 @@
 	int ret, c;
 
 	master_service = master_service_init("sieve-test", 
-		MASTER_SERVICE_FLAG_STANDALONE, &argc, &argv, "r:f:m:d:l:x:s:ect");
+		MASTER_SERVICE_FLAG_STANDALONE, &argc, &argv, "r:f:m:d:l:x:s:ectP:");
 
-	sieve_tool_init(NULL, FALSE);
+	sieve_tool_init(FALSE);
 
 	t_array_init(&scriptfiles, 16);
+	t_array_init(&plugins, 4);
 
 	user = getenv("USER");
 	
@@ -171,6 +174,15 @@
 				array_append(&scriptfiles, &file, 1);
 			}
 			break;
+		case 'P': 
+			/* Plugin */
+			{
+				const char *plugin;			
+
+				plugin = t_strdup(optarg);
+				array_append(&plugins, &plugin, 1);
+			}
+			break;
 		case 'e':
 			execute = TRUE;
 			break;
@@ -206,6 +218,12 @@
 		i_fatal_status(EX_USAGE, "Unknown argument: %s", argv[optind]);
 	}
 
+	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 7138e5d66a42 -r e3d3d82febe3 src/sieve-tools/sievec.c
--- a/src/sieve-tools/sievec.c	Thu Jan 07 22:26:29 2010 +0100
+++ b/src/sieve-tools/sievec.c	Thu Jan 07 23:04:23 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, TRUE);	
+	sieve_tool_init(TRUE);
+
+	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);
 	}
diff -r 7138e5d66a42 -r e3d3d82febe3 src/sieve-tools/sieved.c
--- a/src/sieve-tools/sieved.c	Thu Jan 07 22:26:29 2010 +0100
+++ b/src/sieve-tools/sieved.c	Thu Jan 07 23:04:23 2010 +0100
@@ -2,6 +2,7 @@
  */
 
 #include "lib.h"
+#include "array.h"


More information about the dovecot-cvs mailing list