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

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


details:   http://hg.dovecot.org/dovecot-sieve-1.0/rev/5c3ba11994cb
changeset: 33:5c3ba11994cb
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Apr 25 02:54:13 2008 +0300
description:
Unfold multiline headers before comparing them.

diffstat:

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

diffs (74 lines):

diff -r 9dd6226f6ace -r 5c3ba11994cb src/sieve-cmu.c
--- a/src/sieve-cmu.c	Tue Apr 01 16:52:33 2008 +0300
+++ b/src/sieve-cmu.c	Fri Apr 25 02:54:13 2008 +0300
@@ -39,13 +39,69 @@ typedef struct {
 	const char *temp[10];
 } sieve_msgdata_t;
 
+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)
 {
     sieve_msgdata_t *m = v;
+    const char *const *headers;
 
     if (phead==NULL) return SIEVE_FAIL;
-    *body = (const char **)mail_get_headers(m->mail, phead);
+    headers = mail_get_headers(m->mail, phead);
+    if (headers != NULL)
+	    headers = unfold_multiline_headers(headers);
+    *body = (const char **)headers;
 
     if (*body) {
 	return SIEVE_OK;


More information about the dovecot-cvs mailing list