dovecot-2.2-pigeonhole: lib-sieve: editheader extension: Made pr...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Fri Mar 6 19:02:57 UTC 2015


details:   http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/c13471f102be
changeset: 1995:c13471f102be
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Fri Mar 06 20:02:15 2015 +0100
description:
lib-sieve: editheader extension: Made protection against addition and deletion of headers configurable separately.
Also, the received and auto-submitted headers are now only protected against deletion as required in the RFC.
Updated the documentation accordingly.

diffstat:

 doc/extensions/editheader.txt                            |   25 ++-
 src/lib-sieve/plugins/editheader/cmd-addheader.c         |   18 +-
 src/lib-sieve/plugins/editheader/cmd-deleteheader.c      |   17 +-
 src/lib-sieve/plugins/editheader/ext-editheader-common.c |  112 +++++++++-----
 src/lib-sieve/plugins/editheader/ext-editheader-common.h |    6 +-
 tests/extensions/editheader/protected.svtest             |   76 ++++++++++
 6 files changed, 194 insertions(+), 60 deletions(-)

diffs (truncated from 390 to 300 lines):

diff -r 3f1d2b649e19 -r c13471f102be doc/extensions/editheader.txt
--- a/doc/extensions/editheader.txt	Fri Mar 06 19:02:53 2015 +0100
+++ b/doc/extensions/editheader.txt	Fri Mar 06 20:02:15 2015 +0100
@@ -26,11 +26,23 @@
   command. The minimum value for this setting is 1024 bytes. The value is in
   bytes, unless followed by a k(ilo).
 
+sieve_editheader_forbid_add =
+  A space-separated list of headers that cannot be added to the message header.
+  Addition of the `Subject:' header cannot be prohibited, as required by the RFC
+  specification. Therefore, adding this header to this setting has no effect.
+
+sieve_editheader_forbid_delete =
+  A space-separated list of headers that cannot be deleted from the message
+  header. Deleting the `Received:' and `Auto-Submitted:' fields is always 
+  forbidden, while removing the `Subject:' header cannot be prohibited,
+  as required by the RFC specification. Therefore, adding one of these headers
+  to this setting has no effect.
+
 sieve_editheader_protected =
-  A space-separated list of headers that cannot be added to nor removed from the
-  message header. The `Received:' and `Auto-Submitted:' fields are always
-  protected and the `Subject:' header cannot be protected, as required by the
-  RFC specification; adding one of these headers to this setting has no effect.
+  A space-separated list of headers that cannot be added to or deleted from
+  the message header. This setting is provided for backwards compatibility. It
+  is a combination of the sieve_editheader_forbid_add and
+  sieve_editheader_forbid_delete settings. The same limitations apply. 
 
 Invalid values for the settings above will make the Sieve interpreter log
 a warning and revert to the default values.
@@ -45,7 +57,8 @@
   # Header fiels must not exceed one 1k
   sieve_editheader_max_header_size = 1k
 
-  # Protect special header
-  sieve_editheader_protected = X-Verified
+  # Protected special headers
+  sieve_editheader_forbid_add = X-Verified
+  sieve_editheader_forbid_delete = X-Verified X-Seen
 }
 
diff -r 3f1d2b649e19 -r c13471f102be src/lib-sieve/plugins/editheader/cmd-addheader.c
--- a/src/lib-sieve/plugins/editheader/cmd-addheader.c	Fri Mar 06 19:02:53 2015 +0100
+++ b/src/lib-sieve/plugins/editheader/cmd-addheader.c	Fri Mar 06 20:02:15 2015 +0100
@@ -130,10 +130,13 @@
 			return FALSE;
 		}
 
-		if ( ext_editheader_header_is_protected(cmd->ext, str_c(fname)) ) {
-			sieve_argument_validate_warning(valdtr, arg, "addheader command: "
-				"specified header field `%s' is protected; "
-				"modification will be denied", str_sanitize(str_c(fname), 80));
+		if ( !ext_editheader_header_allow_add
+			(cmd->ext, str_c(fname)) ) {
+			sieve_argument_validate_warning
+				(valdtr, arg, "addheader command: "
+					"adding specified header field `%s' is forbidden; "
+					"modification will be denied",
+					str_sanitize(str_c(fname), 80));
 		}
 	}
 
@@ -298,10 +301,11 @@
 		return SIEVE_EXEC_FAILURE;
 	}
 
-	if ( ext_editheader_header_is_protected(this_ext, str_c(field_name)) ) {
+	if ( !ext_editheader_header_allow_add
+		(this_ext, str_c(field_name)) ) {
 		sieve_runtime_warning(renv, NULL, "addheader action: "
-			"specified header field `%s' is protected; modification denied",
-			str_sanitize(str_c(field_name), 80));
+			"adding specified header field `%s' is forbidden; "
+			"modification denied", str_sanitize(str_c(field_name), 80));
 		return SIEVE_EXEC_OK;
 	}
 
diff -r 3f1d2b649e19 -r c13471f102be src/lib-sieve/plugins/editheader/cmd-deleteheader.c
--- a/src/lib-sieve/plugins/editheader/cmd-deleteheader.c	Fri Mar 06 19:02:53 2015 +0100
+++ b/src/lib-sieve/plugins/editheader/cmd-deleteheader.c	Fri Mar 06 20:02:15 2015 +0100
@@ -259,10 +259,13 @@
 			return FALSE;
 		}
 
-		if ( ext_editheader_header_is_protected(cmd->ext, str_c(fname)) ) {
-			sieve_argument_validate_warning(valdtr, arg, "deleteheader command: "
-				"specified header field `%s' is protected; "
-				"modification will be denied", str_sanitize(str_c(fname), 80));
+		if ( !ext_editheader_header_allow_delete
+			(cmd->ext, str_c(fname)) ) {
+			sieve_argument_validate_warning
+				(valdtr, arg, "deleteheader command: "
+					"deleting specified header field `%s' is forbidden; "
+					"modification will be denied",
+					str_sanitize(str_c(fname), 80));
 		}
 	}
 
@@ -426,9 +429,11 @@
 		return SIEVE_EXEC_FAILURE;
 	}
 
-	if ( ext_editheader_header_is_protected(this_ext, str_c(field_name)) ) {
+	if ( !ext_editheader_header_allow_delete
+		(this_ext, str_c(field_name)) ) {
 		sieve_runtime_warning(renv, NULL, "deleteheader action: "
-			"specified header field `%s' is protected; modification denied",
+			"deleting specified header field `%s' is forbidden; "
+			"modification denied",
 			str_sanitize(str_c(field_name), 80));
 		return SIEVE_EXEC_OK;
 	}
diff -r 3f1d2b649e19 -r c13471f102be src/lib-sieve/plugins/editheader/ext-editheader-common.c
--- a/src/lib-sieve/plugins/editheader/ext-editheader-common.c	Fri Mar 06 19:02:53 2015 +0100
+++ b/src/lib-sieve/plugins/editheader/ext-editheader-common.c	Fri Mar 06 20:02:15 2015 +0100
@@ -22,8 +22,8 @@
 struct ext_editheader_header {
 	const char *name;
 
-	/* may extend this later */
-	unsigned int protected:1;
+	unsigned int forbid_add:1;
+	unsigned int forbid_delete:1;
 };
 
 struct ext_editheader_config {
@@ -49,12 +49,49 @@
 	return NULL;
 }
 
+static void ext_editheader_config_headers
+(struct sieve_instance *svinst,
+	struct ext_editheader_config *ext_config,
+	const char *setting, bool forbid_add, bool forbid_delete)
+{
+	const char *setval;
+
+	setval = sieve_setting_get(svinst, setting);
+	if ( setval != NULL ) {
+		const char **headers = t_strsplit_spaces(setval, " \t");
+
+		while ( *headers != NULL ) {
+			struct ext_editheader_header *header;
+
+			if ( !rfc2822_header_field_name_verify
+				(*headers, strlen(*headers)) ) {
+				sieve_sys_warning(svinst, "editheader: "
+					"setting %s contains invalid header field name "
+					"`%s' (ignored)", setting, *headers);
+				continue;
+			}
+
+			header=ext_editheader_config_header_find(ext_config, *headers);
+			if ( header == NULL ) {
+				header = array_append_space(&ext_config->headers);
+				header->name = p_strdup(ext_config->pool, *headers);
+			}
+
+			if (forbid_add)
+				header->forbid_add = TRUE;
+			if (forbid_delete)
+				header->forbid_delete = TRUE;
+
+			headers++;
+		}
+	}
+}
+
 bool ext_editheader_load
 (const struct sieve_extension *ext, void **context)
 {
 	struct ext_editheader_config *ext_config;
 	struct sieve_instance *svinst = ext->svinst;
-	const char *protected;
 	size_t max_header_size;
 	pool_t pool;
 
@@ -71,31 +108,12 @@
 
 		p_array_init(&ext_config->headers, pool, 16);
 
-		protected = sieve_setting_get(svinst, "sieve_editheader_protected");
-		if ( protected != NULL ) {
-			const char **headers = t_strsplit_spaces(protected, " \t");
-
-			while ( *headers != NULL ) {
-				struct ext_editheader_header *header;
-
-				if ( !rfc2822_header_field_name_verify(*headers, strlen(*headers)) ) {
-					sieve_sys_warning(svinst,
-						"editheader: setting sieve_editheader_protected contains "
-						"invalid header field name `%s' (ignored)", *headers);
-					continue;
-				}
-
-				header=ext_editheader_config_header_find(ext_config, *headers);
-				if ( header == NULL ) {
-					header = array_append_space(&ext_config->headers);
-					header->name = p_strdup(pool, *headers);
-				}
-
-				header->protected = TRUE;
-
-				headers++;
-			}
-		}
+		ext_editheader_config_headers(svinst, ext_config,
+			"sieve_editheader_protected", TRUE, TRUE);
+		ext_editheader_config_headers(svinst, ext_config,
+			"sieve_editheader_forbid_add", TRUE, FALSE);
+		ext_editheader_config_headers(svinst, ext_config,
+			"sieve_editheader_forbid_delete", FALSE, TRUE);
 
 		if ( sieve_setting_get_size_value
 			(svinst, "sieve_editheader_max_header_size", &max_header_size) ) {
@@ -129,7 +147,24 @@
  * Protected headers
  */
 
-bool ext_editheader_header_is_protected
+bool ext_editheader_header_allow_add
+(const struct sieve_extension *ext, const char *hname)
+{
+	struct ext_editheader_config *ext_config =
+		(struct ext_editheader_config *) ext->context;
+	const struct ext_editheader_header *header;
+
+	if ( strcasecmp(hname, "subject") == 0 )
+		return TRUE;
+
+	if ( (header=ext_editheader_config_header_find
+		(ext_config, hname)) == NULL )
+		return TRUE;
+
+	return !header->forbid_add;
+}
+
+bool ext_editheader_header_allow_delete
 (const struct sieve_extension *ext, const char *hname)
 {
 	struct ext_editheader_config *ext_config =
@@ -137,18 +172,17 @@
 	const struct ext_editheader_header *header;
 
 	if ( strcasecmp(hname, "received") == 0
-		|| strcasecmp(hname, "auto-submitted") == 0 ) {
-		return TRUE;
-	}
-
-	if ( strcasecmp(hname, "subject") == 0 ) {
-		return FALSE;
-	}
-
-	if ( (header=ext_editheader_config_header_find(ext_config, hname)) == NULL )
+		|| strcasecmp(hname, "auto-submitted") == 0 )
 		return FALSE;
 
-	return header->protected;
+	if ( strcasecmp(hname, "subject") == 0 )
+		return TRUE;
+
+	if ( (header=ext_editheader_config_header_find
+		(ext_config, hname)) == NULL )
+		return TRUE;
+
+	return !header->forbid_delete;
 }
 
 /*
diff -r 3f1d2b649e19 -r c13471f102be src/lib-sieve/plugins/editheader/ext-editheader-common.h
--- a/src/lib-sieve/plugins/editheader/ext-editheader-common.h	Fri Mar 06 19:02:53 2015 +0100
+++ b/src/lib-sieve/plugins/editheader/ext-editheader-common.h	Fri Mar 06 20:02:15 2015 +0100
@@ -37,8 +37,10 @@
  * Protected headers
  */
 
-bool ext_editheader_header_is_protected
-	(const struct sieve_extension *ext, const char *header);
+bool ext_editheader_header_allow_add
+	(const struct sieve_extension *ext, const char *hname);
+bool ext_editheader_header_allow_delete
+	(const struct sieve_extension *ext, const char *hname);
 
 /*
  * Limits
diff -r 3f1d2b649e19 -r c13471f102be tests/extensions/editheader/protected.svtest
--- a/tests/extensions/editheader/protected.svtest	Fri Mar 06 19:02:53 2015 +0100
+++ b/tests/extensions/editheader/protected.svtest	Fri Mar 06 20:02:15 2015 +0100
@@ -9,6 +9,7 @@
 	id 32A131WFW23QWE4; Mon, 21 Nov 2011 05:25:26 +0200 (EET)
 Delivery-date: Mon, 21 Nov 2011 04:26:04 +0100
 Auto-Submitted: yes
+X-Friep: frop 3
 Subject: Frop!
 From: stephan at example.com
 To: tss at example.com
@@ -29,6 +30,7 @@
 
 	deleteheader "received";


More information about the dovecot-cvs mailing list