changeset 2973:32cc9186d8eb HEAD

If we want MD5 sums in indexes, mail saving should also add them.
author Timo Sirainen <tss@iki.fi>
date Wed, 15 Dec 2004 20:48:06 +0200
parents 7c4238c78aee
children 8ef9f3d640e0
files src/lib-storage/index/mbox/mbox-save.c
diffstat 1 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/mbox-save.c	Wed Dec 15 20:43:40 2004 +0200
+++ b/src/lib-storage/index/mbox/mbox-save.c	Wed Dec 15 20:48:06 2004 +0200
@@ -14,6 +14,7 @@
 #include "mbox-file.h"
 #include "mbox-from.h"
 #include "mbox-lock.h"
+#include "mbox-md5.h"
 #include "mbox-sync-private.h"
 
 #include <stddef.h>
@@ -41,6 +42,7 @@
 
 	struct index_mail mail;
 	const struct mail_full_flags *flags;
+	struct mbox_md5_context *mbox_md5_ctx;
 
 	unsigned int synced:1;
 	unsigned int failed:1;
@@ -276,10 +278,13 @@
 }
 
 static void save_header_callback(struct message_header_line *hdr,
-				 int *matched __attr_unused__, void *context)
+				 int *matched, void *context)
 {
 	struct mbox_save_context *ctx = context;
 
+	if (!*matched && ctx->ibox->mbox_save_md5 && hdr != NULL)
+		mbox_md5_continue(ctx->mbox_md5_ctx, hdr);
+
 	if ((hdr == NULL && ctx->eoh_input_offset == (uoff_t)-1) ||
 	    (hdr != NULL && hdr->eoh))
 		ctx->eoh_input_offset = ctx->input->v_offset;
@@ -371,6 +376,8 @@
 		ctx->body_output = getenv("MAIL_SAVE_CRLF") != NULL ?
 			o_stream_create_crlf(default_pool, ctx->output) :
 			o_stream_create_lf(default_pool, ctx->output);
+		if (ctx->ibox->mbox_save_md5)
+			ctx->mbox_md5_ctx = mbox_md5_init();
 	}
 
 	return &ctx->ctx;
@@ -429,6 +436,15 @@
 		}
 	}
 
+	if (ctx->ibox->mbox_save_md5) {
+		unsigned char hdr_md5_sum[16];
+
+		mbox_md5_finish(ctx->mbox_md5_ctx, hdr_md5_sum);
+		mail_index_update_ext(ctx->trans, ctx->seq,
+				      ctx->ibox->md5hdr_ext_idx,
+				      hdr_md5_sum, NULL);
+	}
+
 	/* append our own headers and ending empty line */
 	ctx->extra_hdr_offset = ctx->output->offset;
 	if (o_stream_send(ctx->output, str_data(ctx->headers),