From: Timo Sirainen Date: Thu, 8 Sep 2011 13:37:56 +0000 (+0300) Subject: fts-solr: Fixed indexing messages with multiple MIME body parts. X-Git-Tag: 2.1.alpha2~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a5074ab2bd5727e916ce18725a3d6f8025ab9b19;p=thirdparty%2Fdovecot%2Fcore.git fts-solr: Fixed indexing messages with multiple MIME body parts. --- diff --git a/src/plugins/fts-solr/fts-backend-solr-old.c b/src/plugins/fts-solr/fts-backend-solr-old.c index eab7500f18..57ed22e845 100644 --- a/src/plugins/fts-solr/fts-backend-solr-old.c +++ b/src/plugins/fts-solr/fts-backend-solr-old.c @@ -36,6 +36,7 @@ struct solr_fts_backend_update_context { string_t *cmd, *hdr; bool headers_open; + bool body_open; bool documents_added; }; @@ -513,6 +514,10 @@ fts_backend_solr_uid_changed(struct solr_fts_backend_update_context *ctx, str_append(ctx->cmd, ""); } else { ctx->headers_open = FALSE; + if (ctx->body_open) { + ctx->body_open = FALSE; + str_append(ctx->cmd, ""); + } str_append(ctx->cmd, ""); str_append_str(ctx->cmd, ctx->hdr); str_append(ctx->cmd, ""); @@ -547,7 +552,10 @@ fts_backend_solr_update_set_build_key(struct fts_backend_update_context *_ctx, break; case FTS_BACKEND_BUILD_KEY_BODY_PART: ctx->headers_open = FALSE; - str_append(ctx->cmd, ""); + if (!ctx->body_open) { + ctx->body_open = TRUE; + str_append(ctx->cmd, ""); + } break; case FTS_BACKEND_BUILD_KEY_BODY_PART_BINARY: i_unreached(); @@ -561,10 +569,12 @@ fts_backend_solr_update_unset_build_key(struct fts_backend_update_context *_ctx) struct solr_fts_backend_update_context *ctx = (struct solr_fts_backend_update_context *)_ctx; - if (!ctx->headers_open) - str_append(ctx->cmd, ""); - else + if (ctx->headers_open) str_append_c(ctx->hdr, '\n'); + else { + i_assert(ctx->body_open); + str_append_c(ctx->cmd, '\n'); + } } static int diff --git a/src/plugins/fts-solr/fts-backend-solr.c b/src/plugins/fts-solr/fts-backend-solr.c index e7270b76cf..d13fd0dcce 100644 --- a/src/plugins/fts-solr/fts-backend-solr.c +++ b/src/plugins/fts-solr/fts-backend-solr.c @@ -36,6 +36,7 @@ struct solr_fts_backend_update_context { unsigned int last_indexed_uid_set:1; unsigned int headers_open:1; + unsigned int body_open:1; unsigned int cur_header_index:1; unsigned int documents_added:1; unsigned int expunges:1; @@ -260,6 +261,10 @@ static void fts_backend_solr_doc_close(struct solr_fts_backend_update_context *ctx) { ctx->headers_open = FALSE; + if (ctx->body_open) { + ctx->body_open = FALSE; + str_append(ctx->cmd, ""); + } if (str_len(ctx->hdr) > 0) { str_append(ctx->cmd, ""); str_append_str(ctx->cmd, ctx->hdr); @@ -416,7 +421,10 @@ fts_backend_solr_update_set_build_key(struct fts_backend_update_context *_ctx, break; case FTS_BACKEND_BUILD_KEY_BODY_PART: ctx->headers_open = FALSE; - str_append(ctx->cmd, ""); + if (!ctx->body_open) { + ctx->body_open = TRUE; + str_append(ctx->cmd, ""); + } break; case FTS_BACKEND_BUILD_KEY_BODY_PART_BINARY: i_unreached(); @@ -430,12 +438,15 @@ fts_backend_solr_update_unset_build_key(struct fts_backend_update_context *_ctx) struct solr_fts_backend_update_context *ctx = (struct solr_fts_backend_update_context *)_ctx; - if (!ctx->headers_open) - str_append(ctx->cmd, ""); - else { + if (ctx->headers_open) { /* this is called individually for each header line. headers are finished only when key changes to body */ str_append_c(ctx->hdr, '\n'); + } else { + i_assert(ctx->body_open); + /* messages can have multiple MIME bodies. + add them all as one. */ + str_append_c(ctx->cmd, '\n'); } if (ctx->cur_header_index) {