dovecot-sieve-1.1: Unfold multiline headers before comparing them.

dovecot at dovecot.org dovecot at dovecot.org
Fri Apr 25 02:54:16 EEST 2008


details:   http://hg.dovecot.org/dovecot-sieve-1.1/rev/486736da7e4c
changeset: 55:486736da7e4c
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Apr 25 02:54:14 2008 +0300
description:
Unfold multiline headers before comparing them.

diffstat:

1 file changed, 53 insertions(+)
src/sieve-cmu.c |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++

diffs (70 lines):

diff -r af18c7215bde -r 486736da7e4c src/sieve-cmu.c
--- a/src/sieve-cmu.c	Fri Apr 18 13:32:43 2008 +0300
+++ b/src/sieve-cmu.c	Fri Apr 25 02:54:14 2008 +0300
@@ -66,6 +66,58 @@ dovecot_sieve_compile(script_data_t *sda
 dovecot_sieve_compile(script_data_t *sdata, const char *script_path,
 		      const char *compiled_path);
 
+static const char *unfold_header(const char *str)
+{
+	char *new_str;
+	unsigned int i, j;
+
+	for (i = 0; str[i] != '\0'; i++) {
+		if (str[i] == '\n')
+			break;
+	}
+	if (str[i] == '\0')
+		return str;
+
+	/* @UNSAFE */
+	new_str = t_malloc(i + strlen(str+i) + 1);
+	memcpy(new_str, str, i);
+	for (j = i; str[i] != '\0'; i++) {
+		if (str[i] == '\n') {
+			new_str[j++] = ' ';
+			i++;
+			i_assert(str[i] == ' ' || str[i] == '\t');
+		} else {
+			new_str[j++] = str[i];
+		}
+	}
+	new_str[j] = '\0';
+	return new_str;
+}
+
+static const char *const *
+unfold_multiline_headers(const char *const *headers)
+{
+	const char **new_headers;
+	unsigned int i;
+
+	/* see if there are any multiline headers */
+	for (i = 0; headers[i] != NULL; i++) {
+		if (strchr(headers[i], '\n') != NULL)
+			break;
+	}
+	if (headers[i] == NULL) {
+		/* no multilines */
+		return headers;
+	}
+
+	/* @UNSAFE */
+	for (; headers[i] != NULL; i++) ;
+	new_headers = t_new(const char *, i + 1);
+	for (i = 0; headers[i] != NULL; i++)
+		new_headers[i] = unfold_header(headers[i]);
+	return new_headers;
+}
+
 /* gets the header "head" from msg. */
 static int getheader(void *v, const char *phead, const char ***body)
 {
@@ -75,6 +127,7 @@ static int getheader(void *v, const char
     if (phead==NULL) return SIEVE_FAIL;
     if (mail_get_headers_utf8(m->mail, phead, &headers) < 0)
 	    return SIEVE_FAIL;
+    headers = unfold_multiline_headers(headers);
     *body = (const char **)headers;
 
     if (**body) {


More information about the dovecot-cvs mailing list