changeset 4619:3111cf26ecac HEAD

Fixes to indexing
author Timo Sirainen <tss@iki.fi>
date Mon, 18 Sep 2006 02:07:55 +0300
parents a1621235f405
children f66c874602a4
files src/plugins/fts/fts-storage.c
diffstat 1 files changed, 44 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/fts/fts-storage.c	Mon Sep 18 01:27:16 2006 +0300
+++ b/src/plugins/fts/fts-storage.c	Mon Sep 18 02:07:55 2006 +0300
@@ -74,6 +74,32 @@
 	bool save_part;
 };
 
+static int fts_build_mail_flush(struct fts_storage_build_context *ctx)
+{
+	if (str_len(ctx->headers) == 0)
+		return 1;
+
+	if (fts_backend_build_more(ctx->build, ctx->uid, str_data(ctx->headers),
+				   str_len(ctx->headers)) < 0)
+		return -1;
+
+	str_truncate(ctx->headers, 0);
+	return 1;
+}
+
+static bool fts_build_update_save_part(struct fts_storage_build_context *ctx,
+				       const struct message_block *block)
+{
+	/* we'll index only text/xxx and message/rfc822 parts for now */
+	if ((block->part->flags &
+	     (MESSAGE_PART_FLAG_TEXT |
+	      MESSAGE_PART_FLAG_MESSAGE_RFC822)) == 0)
+		return FALSE;
+
+	ctx->save_part = TRUE;
+	return TRUE;
+}
+
 static int fts_build_mail_header(struct fts_storage_build_context *ctx,
 				 const struct message_block *block)
 {
@@ -89,22 +115,13 @@
 
 	if (!ctx->save_part) {
 		if (strcasecmp(hdr->name, "Content-Type") == 0) {
-			/* we'll index only text/xxx and message/rfc822 parts
-			   for now */
-			if ((block->part->flags &
-			     (MESSAGE_PART_FLAG_TEXT |
-			      MESSAGE_PART_FLAG_MESSAGE_RFC822)) == 0)
+			if (!fts_build_update_save_part(ctx, block))
 				return 0;
-			ctx->save_part = TRUE;
 		}
 		return 1;
 	}
 
-	if (fts_backend_build_more(ctx->build, ctx->uid, str_data(ctx->headers),
-				   str_len(ctx->headers)) < 0)
-		return -1;
-	str_truncate(ctx->headers, 0);
-	return 1;
+	return fts_build_mail_flush(ctx);
 }
 
 static int
@@ -134,24 +151,34 @@
 				ret = 0;
 			break;
 		}
-		if (raw_block.part != prev_part) {
-			str_truncate(ctx->headers, 0);
-			ctx->save_part = FALSE;
-			skip_part = NULL;
-		} else if (raw_block.part == skip_part)
+		if (raw_block.part == skip_part)
 			continue;
 
 		if (!message_decoder_decode_next_block(decoder, &raw_block,
 						       &block))
 			continue;
 
+		if (block.part != prev_part &&
+		    (block.hdr != NULL || block.size != 0)) {
+			str_truncate(ctx->headers, 0);
+			ctx->save_part = FALSE;
+			skip_part = NULL;
+		}
+
 		if (block.hdr != NULL) {
 			ret = fts_build_mail_header(ctx, &block);
 			if (ret < 0)
 				break;
 			if (ret == 0)
 				skip_part = raw_block.part;
-		} else if (block.size != 0) {
+		} else if (block.size == 0) {
+			/* end of headers */
+			if (fts_build_update_save_part(ctx, &block)) {
+				ret = fts_build_mail_flush(ctx);
+				if (ret < 0)
+					break;
+			}
+		} else {
 			if (fts_backend_build_more(ctx->build, mail->uid,
 						   block.data,
 						   block.size) < 0) {