dovecot-2.0-pigeonhole: Implemented generic string list interfac...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Fri Jul 30 15:57:40 EEST 2010


details:   http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/daef8bfcb457
changeset: 1344:daef8bfcb457
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Fri Jul 30 14:53:14 2010 +0200
description:
Implemented generic string list interface and simplified matching API.

diffstat:

 TODO                                                         |   17 +-
 src/lib-sieve/Makefile.am                                    |    2 +
 src/lib-sieve/ext-envelope.c                                 |  436 ++++++++++------
 src/lib-sieve/mcht-contains.c                                |   15 +-
 src/lib-sieve/mcht-is.c                                      |   15 +-
 src/lib-sieve/mcht-matches.c                                 |   19 +-
 src/lib-sieve/plugins/body/ext-body-common.c                 |   96 +++-
 src/lib-sieve/plugins/body/ext-body-common.h                 |   24 +-
 src/lib-sieve/plugins/body/tst-body.c                        |   88 +--
 src/lib-sieve/plugins/date/ext-date-common.c                 |  147 +++++
 src/lib-sieve/plugins/date/ext-date-common.h                 |   15 +
 src/lib-sieve/plugins/date/tst-date.c                        |  123 +---
 src/lib-sieve/plugins/enotify/cmd-notify.c                   |    2 +-
 src/lib-sieve/plugins/enotify/ext-enotify-common.c           |   19 +-
 src/lib-sieve/plugins/enotify/ext-enotify-common.h           |    2 +-
 src/lib-sieve/plugins/enotify/tst-notify-method-capability.c |   25 +-
 src/lib-sieve/plugins/enotify/tst-valid-notify-method.c      |   12 +-
 src/lib-sieve/plugins/environment/tst-environment.c          |   30 +-
 src/lib-sieve/plugins/imap4flags/cmd-flag.c                  |   10 +-
 src/lib-sieve/plugins/imap4flags/ext-imap4flags-common.c     |  176 +++++-
 src/lib-sieve/plugins/imap4flags/ext-imap4flags-common.h     |   14 +-
 src/lib-sieve/plugins/imap4flags/tag-flags.c                 |   10 +-
 src/lib-sieve/plugins/imap4flags/tst-hasflag.c               |   95 +---
 src/lib-sieve/plugins/mailbox/tst-mailboxexists.c            |   20 +-
 src/lib-sieve/plugins/notify/cmd-denotify.c                  |   18 +-
 src/lib-sieve/plugins/notify/cmd-notify.c                    |   12 +-
 src/lib-sieve/plugins/regex/mcht-regex.c                     |  215 +++++---
 src/lib-sieve/plugins/relational/ext-relational-common.h     |    6 +-
 src/lib-sieve/plugins/relational/mcht-count.c                |  128 +--
 src/lib-sieve/plugins/relational/mcht-value.c                |   27 +-
 src/lib-sieve/plugins/spamvirustest/tst-spamvirustest.c      |   37 +-
 src/lib-sieve/plugins/vacation/cmd-vacation.c                |   14 +-
 src/lib-sieve/plugins/variables/tst-string.c                 |  112 ++-
 src/lib-sieve/sieve-address-parts.c                          |  132 +++--
 src/lib-sieve/sieve-address-parts.h                          |   12 +-
 src/lib-sieve/sieve-address.c                                |  138 +++++
 src/lib-sieve/sieve-address.h                                |   51 +-
 src/lib-sieve/sieve-code.c                                   |  142 ++--
 src/lib-sieve/sieve-code.h                                   |   27 +-
 src/lib-sieve/sieve-common.h                                 |    4 +
 src/lib-sieve/sieve-match-types.h                            |   36 +-
 src/lib-sieve/sieve-match.c                                  |  177 +++---
 src/lib-sieve/sieve-match.h                                  |   31 +-
 src/lib-sieve/sieve-message.c                                |  106 ++++
 src/lib-sieve/sieve-message.h                                |    7 +
 src/lib-sieve/sieve-stringlist.c                             |  139 +++++
 src/lib-sieve/sieve-stringlist.h                             |   51 +
 src/lib-sieve/tst-address.c                                  |   59 +-
 src/lib-sieve/tst-exists.c                                   |   10 +-
 src/lib-sieve/tst-header.c                                   |   67 +--
 src/testsuite/testsuite-log.c                                |   77 ++
 src/testsuite/testsuite-log.h                                |    3 +
 src/testsuite/testsuite-result.c                             |   80 +++
 src/testsuite/testsuite-result.h                             |    3 +
 src/testsuite/tst-test-error.c                               |   48 +-
 src/testsuite/tst-test-multiscript.c                         |   19 +-
 src/testsuite/tst-test-result.c                              |   61 +-
 tests/extensions/envelope.svtest                             |    4 +
 58 files changed, 2140 insertions(+), 1325 deletions(-)

diffs (truncated from 5301 to 300 lines):

diff -r 2b626836f00e -r daef8bfcb457 TODO
--- a/TODO	Fri Jul 30 09:16:13 2010 +0200
+++ b/TODO	Fri Jul 30 14:53:14 2010 +0200
@@ -35,14 +35,15 @@
 	- Implement proper :content "multipart" behavior
 	- Implement proper :content "message/rfc822" behavior
 	- Build test cases for decoding MIME encodings to UTF-8
+* Implement index extension
 * Build a sieve tool to filter an entire existing mailbox through a Sieve 
   script:
 	- Add commandline options to fully customize execution
 	- Write manual page
 * Vacation extension improvements:
-    - Implement configurable sender exclusion list.
-    - Implement mechanism for implicitly including an account's aliases in the
-      vacation command's :addresses list.
+	- Implement configurable sender exclusion list.
+	- Implement mechanism for implicitly including an account's aliases in the
+	  vacation command's :addresses list.
 * Improve error handling. 
 	- Implement dropping errors in the user's mailbox as a mail message.
 * Fix remaining RFC deviations:
@@ -69,8 +70,8 @@
   them to the user if appropriate/safe.
 * Implement proper support for ManageSieve SASL ANONYMOUS login.
 * Test ManageSieve behavior thoroughly:
-  - Test pipelined behavior
-  - Test proxy authentication
+	- Test pipelined behavior
+	- Test proxy authentication
 * Code cleanup:
 	- Make address handling more uniform. 
 	- Review all FIXMEs 
@@ -80,11 +81,7 @@
 
 * ## MAKE A THIRD RELEASE (0.3.x) ##
 
-* Implement abstract string list and make matching interface more generic. Use
-  this to:
-	- Simplify matching API
-	- Implement index extension
-	- Implement extlists extension
+* Implement extlists extension as a plugin
 * Enotify extension: detect use of variable values extracted from the message 
   that are used in the method argument. RFC reports this as a security issue.
 * Make the sieve storage a base class with (possibly) various implementations, 
diff -r 2b626836f00e -r daef8bfcb457 src/lib-sieve/Makefile.am
--- a/src/lib-sieve/Makefile.am	Fri Jul 30 09:16:13 2010 +0200
+++ b/src/lib-sieve/Makefile.am	Fri Jul 30 14:53:14 2010 +0200
@@ -91,6 +91,7 @@
 	sieve-result.c \
 	sieve-error.c \
 	sieve-objects.c \
+	sieve-stringlist.c \
 	sieve-comparators.c \
 	sieve-match-types.c \
 	sieve-address-parts.c \
@@ -136,6 +137,7 @@
 	sieve-error.h \
 	sieve-error-private.h \
 	sieve-objects.h \
+	sieve-stringlist.h \
 	sieve-match.h \
 	sieve-comparators.h \
 	sieve-match-types.h \
diff -r 2b626836f00e -r daef8bfcb457 src/lib-sieve/ext-envelope.c
--- a/src/lib-sieve/ext-envelope.c	Fri Jul 30 09:16:13 2010 +0200
+++ b/src/lib-sieve/ext-envelope.c	Fri Jul 30 14:53:14 2010 +0200
@@ -18,6 +18,7 @@
 #include "sieve-common.h"
 #include "sieve-extensions.h"
 #include "sieve-commands.h"
+#include "sieve-stringlist.h"
 #include "sieve-code.h"
 #include "sieve-address.h"
 #include "sieve-comparators.h"
@@ -176,6 +177,250 @@
 	return NULL;
 }
 
+/* Envelope parts implementation */
+
+static const struct sieve_address *const *_from_part_get_addresses
+(const struct sieve_runtime_env *renv)
+{
+	ARRAY_DEFINE(envelope_values, const struct sieve_address *);
+	const struct sieve_address *address =
+		sieve_message_get_sender_address(renv->msgctx);
+	
+	if ( address != NULL ) {
+		t_array_init(&envelope_values, 2);
+
+        array_append(&envelope_values, &address, 1);
+
+	    (void)array_append_space(&envelope_values);
+    	return array_idx(&envelope_values, 0);
+	} 
+
+	return NULL;
+}
+
+static const char *const *_from_part_get_values
+(const struct sieve_runtime_env *renv)
+{
+	ARRAY_DEFINE(envelope_values, const char *);
+
+	t_array_init(&envelope_values, 2);
+
+	if ( renv->msgdata->return_path != NULL ) {
+        array_append(&envelope_values, &renv->msgdata->return_path, 1);
+	}
+
+	(void)array_append_space(&envelope_values);
+
+	return array_idx(&envelope_values, 0);
+}
+
+static const struct sieve_address *const *_to_part_get_addresses
+(const struct sieve_runtime_env *renv)
+{
+	ARRAY_DEFINE(envelope_values, const struct sieve_address *);
+	const struct sieve_address *address = 
+		sieve_message_get_recipient_address(renv->msgctx);	
+
+	if ( address != NULL && address->local_part != NULL ) {
+		t_array_init(&envelope_values, 2);
+
+		array_append(&envelope_values, &address, 1);
+
+		(void)array_append_space(&envelope_values);
+		return array_idx(&envelope_values, 0);
+	}
+
+	return NULL;
+}
+
+static const char *const *_to_part_get_values
+(const struct sieve_runtime_env *renv)
+{
+	ARRAY_DEFINE(envelope_values, const char *);
+
+	t_array_init(&envelope_values, 2);
+
+	if ( renv->msgdata->to_address != NULL ) {
+        array_append(&envelope_values, &renv->msgdata->to_address, 1);
+	}
+
+	(void)array_append_space(&envelope_values);
+
+	return array_idx(&envelope_values, 0);
+}
+
+
+static const char *const *_auth_part_get_values
+(const struct sieve_runtime_env *renv)
+{
+	ARRAY_DEFINE(envelope_values, const char *);
+
+	t_array_init(&envelope_values, 2);
+
+	if ( renv->msgdata->auth_user != NULL )
+        array_append(&envelope_values, &renv->msgdata->auth_user, 1);
+
+	(void)array_append_space(&envelope_values);
+
+	return array_idx(&envelope_values, 0);
+}
+
+/*
+ * Envelope address list
+ */
+
+/* Forward declarations */
+
+static int sieve_envelope_address_list_next_string_item
+	(struct sieve_stringlist *_strlist, string_t **str_r);
+static int sieve_envelope_address_list_next_item
+	(struct sieve_address_list *_addrlist, struct sieve_address *addr_r, 
+		string_t **unparsed_r);
+static void sieve_envelope_address_list_reset
+	(struct sieve_stringlist *_strlist);
+
+/* Stringlist object */
+
+struct sieve_envelope_address_list {
+	struct sieve_address_list addrlist;
+
+	struct sieve_stringlist *env_parts;
+
+	const struct sieve_address *const *cur_addresses;
+	const char * const *cur_values;
+
+	int value_index; 
+};
+
+static struct sieve_address_list *sieve_envelope_address_list_create
+(const struct sieve_runtime_env *renv, struct sieve_stringlist *env_parts)
+{
+	struct sieve_envelope_address_list *addrlist;
+	    
+	addrlist = t_new(struct sieve_envelope_address_list, 1);
+	addrlist->addrlist.strlist.runenv = renv;
+	addrlist->addrlist.strlist.next_item = 
+		sieve_envelope_address_list_next_string_item;
+	addrlist->addrlist.strlist.reset = sieve_envelope_address_list_reset;
+	addrlist->addrlist.next_item = sieve_envelope_address_list_next_item;
+	addrlist->env_parts = env_parts;
+  
+	return &addrlist->addrlist;
+}
+
+static int sieve_envelope_address_list_next_item
+(struct sieve_address_list *_addrlist, struct sieve_address *addr_r, 
+	string_t **unparsed_r)
+{
+	struct sieve_envelope_address_list *addrlist = 
+		(struct sieve_envelope_address_list *) _addrlist;	
+	const struct sieve_runtime_env *renv = _addrlist->strlist.runenv;
+
+	if ( addr_r != NULL ) addr_r->local_part = NULL;
+	if ( unparsed_r != NULL ) *unparsed_r = NULL;
+
+	while ( addrlist->cur_addresses == NULL && addrlist->cur_values == NULL ) {
+		const struct sieve_envelope_part *epart;
+		string_t *envp_item = NULL;
+		int ret;
+
+		/* Read next header value from source list */
+		if ( (ret=sieve_stringlist_next_item(addrlist->env_parts, &envp_item)) 
+			<= 0 )
+			return ret;
+			
+		if ( (epart=_envelope_part_find(str_c(envp_item))) != NULL ) {
+			addrlist->value_index = 0;
+
+			if ( epart->get_addresses != NULL ) {
+				/* Field contains addresses */
+				addrlist->cur_addresses = epart->get_addresses(renv);
+
+				/* Drop empty list */
+				if ( addrlist->cur_addresses != NULL &&
+					addrlist->cur_addresses[0] == NULL )
+					addrlist->cur_addresses = NULL;
+			}  
+
+			if ( addrlist->cur_addresses == NULL && epart->get_values != NULL ) {
+				/* Field contains something else */
+				addrlist->cur_values = epart->get_values(renv);
+
+				/* Drop empty list */
+				if ( addrlist->cur_values != NULL && addrlist->cur_values[0] == NULL )
+					addrlist->cur_values = NULL;
+			}
+		}
+	}
+	
+	/* Return next item */
+	if ( addrlist->cur_addresses != NULL ) {
+		const struct sieve_address *addr = 
+			addrlist->cur_addresses[addrlist->value_index];
+
+		if ( addr->local_part == NULL ) {
+			/* Null path <> */
+			if ( unparsed_r != NULL ) 
+				*unparsed_r = t_str_new_const("", 0);
+		} else {
+			if ( addr_r != NULL )
+				*addr_r = *addr;
+		}
+
+		/* Advance to next value */
+		addrlist->value_index++;
+		if ( addrlist->cur_addresses[addrlist->value_index] == NULL ) {
+			addrlist->cur_addresses = NULL;
+			addrlist->value_index = 0;
+		}
+	} else {
+		if ( unparsed_r != NULL ) {
+			const char *value = addrlist->cur_values[addrlist->value_index];
+
+			*unparsed_r = t_str_new_const(value, strlen(value));
+		}
+
+		/* Advance to next value */
+		addrlist->value_index++;
+		if ( addrlist->cur_values[addrlist->value_index] == NULL ) {
+			addrlist->cur_values = NULL;
+			addrlist->value_index = 0;
+		}
+	}
+
+	return 1;
+}
+
+static int sieve_envelope_address_list_next_string_item
+(struct sieve_stringlist *_strlist, string_t **str_r)
+{
+	struct sieve_address_list *addrlist = (struct sieve_address_list *)_strlist;
+	struct sieve_address addr;
+	int ret;


More information about the dovecot-cvs mailing list