changeset 6913:f28a14a07a98 HEAD

When searching only message bodies, we skipped headers completely so body decoding didn't work for non-ASCII.
author Timo Sirainen <tss@iki.fi>
date Mon, 03 Dec 2007 14:47:45 +0200
parents b326327b1f10
children 9c3f0e180751
files src/lib-mail/message-search.c
diffstat 1 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-mail/message-search.c	Mon Dec 03 14:37:30 2007 +0200
+++ b/src/lib-mail/message-search.c	Mon Dec 03 14:47:45 2007 +0200
@@ -132,6 +132,7 @@
 int message_search_more(struct message_search_context *ctx,
 			struct message_block *raw_block)
 {
+	struct message_header_line *hdr = raw_block->hdr;
 	struct message_block block;
 
 	if (raw_block->part != ctx->prev_part) {
@@ -141,10 +142,19 @@
 		ctx->prev_part = raw_block->part;
 	}
 
-	if (raw_block->hdr != NULL) {
-		handle_header(ctx, raw_block->hdr);
-		if ((ctx->flags & MESSAGE_SEARCH_FLAG_SKIP_HEADERS) != 0)
-			return 0;
+	if (hdr != NULL) {
+		handle_header(ctx, hdr);
+		if ((ctx->flags & MESSAGE_SEARCH_FLAG_SKIP_HEADERS) != 0) {
+			/* we want to search only message bodies, but
+			   but decoder needs some headers so that it can
+			   decode the body properly. */
+			if (hdr->name_len != 12 && hdr->name_len != 25)
+				return 0;
+			if (strcasecmp(hdr->name, "Content-Type") != 0 &&
+			    strcasecmp(hdr->name,
+				       "Content-Transfer-Encoding") != 0)
+				return 0;
+		}
 	} else {
 		/* body */
 		if (!ctx->content_type_text)
@@ -153,6 +163,12 @@
 	if (!message_decoder_decode_next_block(ctx->decoder, raw_block, &block))
 		return 0;
 
+	if (block.hdr != NULL &&
+	    (ctx->flags & MESSAGE_SEARCH_FLAG_SKIP_HEADERS) != 0) {
+		/* Content-* header */
+		return 0;
+	}
+
 	return message_search_more_decoded2(ctx, &block);
 }