[dovecot-cvs] dovecot/src/lib-mail message-body-search.c,1.1,1.2 message-body-search.h,1.1,1.2

cras at procontrol.fi cras at procontrol.fi
Sat Nov 30 16:58:25 EET 2002


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

Modified Files:
	message-body-search.c message-body-search.h 
Log Message:
Body searching wasn't working with unknown charsets, and SEARCH BODY
searched also headers.



Index: message-body-search.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-body-search.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- message-body-search.c	13 Nov 2002 11:08:18 -0000	1.1
+++ message-body-search.c	30 Nov 2002 14:58:23 -0000	1.2
@@ -21,6 +21,7 @@
 
 	const char *charset;
 	unsigned int unknown_charset:1;
+	unsigned int search_header:1;
 } BodySearchContext;
 
 typedef struct {
@@ -42,6 +43,7 @@
 	unsigned int content_base64:1;
 	unsigned int content_unknown:1;
 	unsigned int content_type_text:1; /* text/any or message/any */
+	unsigned int ignore_header:1;
 	unsigned int found:1;
 } PartSearchContext;
 
@@ -114,8 +116,10 @@
 	if (ctx->found)
 		return;
 
-	ctx->found = message_header_search(value, &value_len,
-					   ctx->hdr_search_ctx);
+	if (!ctx->ignore_header) {
+		ctx->found = message_header_search(value, &value_len,
+						   ctx->hdr_search_ctx);
+	}
 
 	if (name_len == 12 && strncasecmp(name, "Content-Type", 12) == 0) {
 		(void)message_content_parse_header(t_strndup(value, value_len),
@@ -201,9 +205,6 @@
 	unsigned char outbuf[DECODE_BLOCK_SIZE];
 	size_t inbuf_size, outbuf_size, max_size;
 
-	if (ctx->body_ctx->unknown_charset || ctx->translation == NULL)
-		return message_search_decoded_block(ctx, data, size);
-
 	while (size > 0) {
 		if (ctx->decode_buf_used == 0) {
 			inbuf = data;
@@ -271,9 +272,10 @@
 		return FALSE;
 	}
 
-	ctx->translation = charset_to_utf8_begin(ctx->content_charset != NULL ?
-						 ctx->content_charset : "ascii",
-						 NULL);
+	ctx->translation = ctx->content_charset == NULL ? NULL :
+		charset_to_utf8_begin(ctx->content_charset, NULL);
+	if (ctx->translation == NULL)
+		ctx->translation = charset_to_utf8_begin("ascii", NULL);
 
 	ctx->match_count = 0;
 	ctx->matches = t_malloc(sizeof(size_t) * ctx->body_ctx->key_len);
@@ -328,7 +330,8 @@
 }
 
 static int message_body_search_init(BodySearchContext *ctx, const char *key,
-				    const char *charset, int *unknown_charset)
+				    const char *charset, int *unknown_charset,
+				    int search_header)
 {
 	size_t size;
 
@@ -347,6 +350,7 @@
 	ctx->key_len = size;
 	ctx->charset = charset;
 	ctx->unknown_charset = charset == NULL;
+	ctx->search_header = search_header;
 
 	return TRUE;
 }
@@ -365,6 +369,8 @@
 
 		memset(&part_ctx, 0, sizeof(part_ctx));
 		part_ctx.body_ctx = ctx;
+		part_ctx.ignore_header =
+			part->parent == NULL && !ctx->search_header;
 
 		t_push();
 
@@ -389,11 +395,12 @@
 
 int message_body_search(const char *key, const char *charset,
 			int *unknown_charset, IBuffer *inbuf,
-			MessagePart *part)
+			MessagePart *part, int search_header)
 {
         BodySearchContext ctx;
 
-        if (!message_body_search_init(&ctx, key, charset, unknown_charset))
+	if (!message_body_search_init(&ctx, key, charset, unknown_charset,
+				      search_header))
 		return -1;
 
 	return message_body_search_ctx(&ctx, inbuf, part);

Index: message-body-search.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-body-search.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- message-body-search.h	13 Nov 2002 11:08:18 -0000	1.1
+++ message-body-search.h	30 Nov 2002 14:58:23 -0000	1.2
@@ -7,6 +7,6 @@
    specific charset but is compared to message data without any translation. */
 int message_body_search(const char *key, const char *charset,
 			int *unknown_charset, IBuffer *inbuf,
-			MessagePart *part);
+			MessagePart *part, int search_header);
 
 #endif




More information about the dovecot-cvs mailing list