[dovecot-cvs] dovecot/src/lib-mail message-header-search.c,1.3,1.4

cras at procontrol.fi cras at procontrol.fi
Sat Nov 30 16:36:22 EET 2002


Update of /home/cvs/dovecot/src/lib-mail
In directory danu:/tmp/cvs-serv15771/lib-mail

Modified Files:
	message-header-search.c 
Log Message:
Non-envelope-cached header searching wasn't working. Also now search works
with messages having 8bit headers, assuming them being in same charset as
search key.



Index: message-header-search.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-header-search.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- message-header-search.c	26 Nov 2002 10:14:29 -0000	1.3
+++ message-header-search.c	30 Nov 2002 14:36:20 -0000	1.4
@@ -14,6 +14,7 @@
 
 	unsigned char *key;
 	size_t key_len;
+	char *key_charset;
 
 	size_t *matches; /* size of strlen(key) */
 	ssize_t match_count;
@@ -21,6 +22,7 @@
 	unsigned int last_newline:1;
 	unsigned int submatch:1;
 	unsigned int eoh:1;
+	unsigned int key_ascii:1;
 	unsigned int unknown_charset:1;
 };
 
@@ -29,6 +31,7 @@
 			   int *unknown_charset)
 {
 	HeaderSearchContext *ctx;
+	const char *p;
 	size_t size;
 
 	ctx = p_new(pool, HeaderSearchContext, 1);
@@ -45,8 +48,17 @@
 
 	ctx->key = p_strdup(pool, key);
 	ctx->key_len = size;
+	ctx->key_charset = p_strdup(pool, charset);
 	ctx->unknown_charset = charset == NULL;
 
+	ctx->key_ascii = TRUE;
+	for (p = key; *p != '\0'; p++) {
+		if ((*p & 0x80) != 0) {
+			ctx->key_ascii = FALSE;
+			break;
+		}
+	}
+
 	ctx->matches = p_malloc(pool, sizeof(size_t) * ctx->key_len);
 	return ctx;
 }
@@ -57,6 +69,7 @@
 
 	pool = ctx->pool;
 	p_free(pool, ctx->key);
+	p_free(pool, ctx->key_charset);
 	p_free(pool, ctx->matches);
 	p_free(pool, ctx);
 }
@@ -70,6 +83,10 @@
 		/* we don't know the source charset, so assume we want to
 		   match using same charsets */
 		charset = NULL;
+	} else if (charset != NULL && strcasecmp(charset, "x-unknown") == 0) {
+		/* compare with same charset as search key. the key is already
+		   in utf-8 so we can't use charset = NULL comparing. */
+		charset = ctx->key_charset;
 	}
 
 	data = (const unsigned char *)
@@ -184,6 +201,20 @@
 
 			i_assert(p != end);
 			continue;
+		}
+
+		if (ctx->submatch)
+			chr = *p;
+		else if ((*p & 0x80) == 0)
+			chr = i_toupper(*p);
+		else if (ctx->key_ascii || ctx->unknown_charset)
+			chr = *p;
+		else {
+			/* we have non-ascii in header. treat the rest of the
+			   header as encoded with the key's charset */
+			found = match_data(p, (size_t) (end-p),
+					   ctx->key_charset, ctx);
+			break;
 		}
 
 		chr = ctx->submatch || (*p & 0x80) != 0 ? *p : i_toupper(*p);




More information about the dovecot-cvs mailing list