dovecot-2.0: index-storage: Moved mail MD5 calculation code to m...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jul 31 02:37:57 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/9f1616eeffb8
changeset: 9702:9f1616eeffb8
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jul 30 19:37:50 2009 -0400
description:
index-storage: Moved mail MD5 calculation code to mbox-specific code.
Nothing else used it.

diffstat:

9 files changed, 28 insertions(+), 33 deletions(-)
src/lib-storage/index/index-mail.c           |   13 +------------
src/lib-storage/index/index-storage.c        |    2 --
src/lib-storage/index/index-storage.h        |    2 --
src/lib-storage/index/mbox/mbox-mail.c       |   25 +++++++++++++++++--------
src/lib-storage/index/mbox/mbox-save.c       |    2 +-
src/lib-storage/index/mbox/mbox-storage.c    |    3 +++
src/lib-storage/index/mbox/mbox-storage.h    |    2 +-
src/lib-storage/index/mbox/mbox-sync-parse.c |    3 +--
src/lib-storage/index/mbox/mbox-sync.c       |    9 ++++-----

diffs (198 lines):

diff -r fa5e27725f6b -r 9f1616eeffb8 src/lib-storage/index/index-mail.c
--- a/src/lib-storage/index/index-mail.c	Thu Jul 30 19:30:15 2009 -0400
+++ b/src/lib-storage/index/index-mail.c	Thu Jul 30 19:37:50 2009 -0400
@@ -5,7 +5,6 @@
 #include "buffer.h"
 #include "ioloop.h"
 #include "istream.h"
-#include "hex-binary.h"
 #include "str.h"
 #include "message-date.h"
 #include "message-part-serialize.h"
@@ -943,7 +942,6 @@ int index_mail_get_special(struct mail *
 	struct index_mail_data *data = &mail->data;
 	struct mail_cache_field *cache_fields = mail->ibox->cache_fields;
 	string_t *str;
-	const void *ext_data;
 
 	switch (field) {
 	case MAIL_FETCH_IMAP_BODY: {
@@ -1038,17 +1036,8 @@ int index_mail_get_special(struct mail *
 	case MAIL_FETCH_UIDL_BACKEND:
 	case MAIL_FETCH_SEARCH_SCORE:
 	case MAIL_FETCH_GUID:
+	case MAIL_FETCH_HEADER_MD5:
 		*value_r = "";
-		return 0;
-	case MAIL_FETCH_HEADER_MD5:
-		mail_index_lookup_ext(mail->trans->trans_view, data->seq,
-				      mail->ibox->md5hdr_ext_idx,
-				      &ext_data, NULL);
-		if (ext_data == NULL) {
-			*value_r = "";
-			return 0;
-		}
-		*value_r = binary_to_hex(ext_data, 16);
 		return 0;
 	case MAIL_FETCH_MAILBOX_NAME:
 		*value_r = _mail->box->name;
diff -r fa5e27725f6b -r 9f1616eeffb8 src/lib-storage/index/index-storage.c
--- a/src/lib-storage/index/index-storage.c	Thu Jul 30 19:30:15 2009 -0400
+++ b/src/lib-storage/index/index-storage.c	Thu Jul 30 19:37:50 2009 -0400
@@ -487,8 +487,6 @@ void index_storage_mailbox_alloc(struct 
 	ibox->next_lock_notify = time(NULL) + LOCK_NOTIFY_INTERVAL;
 	ibox->commit_log_file_seq = 0;
 	ibox->index = index_storage_alloc(box->list, name, flags, index_prefix);
-	ibox->md5hdr_ext_idx =
-		mail_index_ext_register(ibox->index, "header-md5", 0, 16, 1);
 
 	if (box->file_create_mode == 0) {
 		mailbox_list_get_permissions(box->list, name,
diff -r fa5e27725f6b -r 9f1616eeffb8 src/lib-storage/index/index-storage.h
--- a/src/lib-storage/index/index-storage.h	Thu Jul 30 19:30:15 2009 -0400
+++ b/src/lib-storage/index/index-storage.h	Thu Jul 30 19:37:50 2009 -0400
@@ -25,8 +25,6 @@ struct index_mailbox {
 	struct mail_index_view *view;
 	struct mail_cache *cache;
 	struct mail_vfuncs *mail_vfuncs;
-
-	uint32_t md5hdr_ext_idx;
 
 	struct timeout *notify_to;
 	struct index_notify_file *notify_files;
diff -r fa5e27725f6b -r 9f1616eeffb8 src/lib-storage/index/mbox/mbox-mail.c
--- a/src/lib-storage/index/mbox/mbox-mail.c	Thu Jul 30 19:30:15 2009 -0400
+++ b/src/lib-storage/index/mbox/mbox-mail.c	Thu Jul 30 19:37:50 2009 -0400
@@ -3,6 +3,7 @@
 #include "lib.h"
 #include "ioloop.h"
 #include "istream.h"
+#include "hex-binary.h"
 #include "index-mail.h"
 #include "mbox-storage.h"
 #include "mbox-file.h"
@@ -148,9 +149,11 @@ mbox_mail_get_special(struct mail *_mail
 mbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
 		      const char **value_r)
 {
-#define EMPTY_MD5_SUM "00000000000000000000000000000000"
-	struct index_mail *mail = (struct index_mail *)_mail;
-	struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
+	static uint8_t empty_md5[16] =
+		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+	struct index_mail *mail = (struct index_mail *)_mail;
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
+	const void *ext_data;
 
 	switch (field) {
 	case MAIL_FETCH_FROM_ENVELOPE:
@@ -160,12 +163,18 @@ mbox_mail_get_special(struct mail *_mail
 		*value_r = istream_raw_mbox_get_sender(mbox->mbox_stream);
 		return 0;
 	case MAIL_FETCH_HEADER_MD5:
-		if (index_mail_get_special(_mail, field, value_r) < 0)
-			return -1;
-		if (**value_r != '\0' && strcmp(*value_r, EMPTY_MD5_SUM) != 0)
+		mail_index_lookup_ext(mail->trans->trans_view, _mail->seq,
+				      mbox->md5hdr_ext_idx, &ext_data, NULL);
+		if (ext_data == NULL) {
+			*value_r = "";
 			return 0;
-
-		/* i guess in theory the EMPTY_MD5_SUM is valid and can happen,
+		}
+		if (memcmp(ext_data, empty_md5, 16) != 0) {
+			*value_r = binary_to_hex(ext_data, 16);
+			return 0;
+		}
+
+		/* i guess in theory the empty_md5 is valid and can happen,
 		   but it's almost guaranteed that it means the MD5 sum is
 		   missing. recalculate it. */
 		mbox->mbox_save_md5 = TRUE;
diff -r fa5e27725f6b -r 9f1616eeffb8 src/lib-storage/index/mbox/mbox-save.c
--- a/src/lib-storage/index/mbox/mbox-save.c	Thu Jul 30 19:30:15 2009 -0400
+++ b/src/lib-storage/index/mbox/mbox-save.c	Thu Jul 30 19:37:50 2009 -0400
@@ -642,7 +642,7 @@ int mbox_save_continue(struct mail_save_
 		}
 		mbox_md5_finish(ctx->mbox_md5_ctx, hdr_md5_sum);
 		mail_index_update_ext(ctx->trans, ctx->seq,
-				      ctx->mbox->ibox.md5hdr_ext_idx,
+				      ctx->mbox->md5hdr_ext_idx,
 				      hdr_md5_sum, NULL);
 	}
 
diff -r fa5e27725f6b -r 9f1616eeffb8 src/lib-storage/index/mbox/mbox-storage.c
--- a/src/lib-storage/index/mbox/mbox-storage.c	Thu Jul 30 19:30:15 2009 -0400
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Thu Jul 30 19:37:50 2009 -0400
@@ -358,6 +358,9 @@ mbox_mailbox_alloc(struct mail_storage *
 		mail_index_ext_register(mbox->ibox.index, "mbox",
 					sizeof(mbox->mbox_hdr),
 					sizeof(uint64_t), sizeof(uint64_t));
+	mbox->md5hdr_ext_idx =
+		mail_index_ext_register(mbox->ibox.index, "header-md5",
+					0, 16, 1);
 
 	if ((storage->flags & MAIL_STORAGE_FLAG_KEEP_HEADER_MD5) != 0)
 		mbox->mbox_save_md5 = TRUE;
diff -r fa5e27725f6b -r 9f1616eeffb8 src/lib-storage/index/mbox/mbox-storage.h
--- a/src/lib-storage/index/mbox/mbox-storage.h	Thu Jul 30 19:30:15 2009 -0400
+++ b/src/lib-storage/index/mbox/mbox-storage.h	Thu Jul 30 19:37:50 2009 -0400
@@ -46,7 +46,7 @@ struct mbox_mailbox {
 	struct timeout *keep_lock_to;
 	bool mbox_writeonly;
 
-	uint32_t mbox_ext_idx;
+	uint32_t mbox_ext_idx, md5hdr_ext_idx;
 	struct mbox_index_header mbox_hdr;
 	const struct mailbox_update *sync_hdr_update;
 
diff -r fa5e27725f6b -r 9f1616eeffb8 src/lib-storage/index/mbox/mbox-sync-parse.c
--- a/src/lib-storage/index/mbox/mbox-sync-parse.c	Thu Jul 30 19:30:15 2009 -0400
+++ b/src/lib-storage/index/mbox/mbox-sync-parse.c	Thu Jul 30 19:37:50 2009 -0400
@@ -592,8 +592,7 @@ bool mbox_sync_parse_match_mail(struct m
 	/* match by MD5 sum */
 	mbox->mbox_save_md5 = TRUE;
 
-	mail_index_lookup_ext(view, seq, mbox->ibox.md5hdr_ext_idx,
-			      &data, NULL);
+	mail_index_lookup_ext(view, seq, mbox->md5hdr_ext_idx, &data, NULL);
 	return data == NULL ? 0 :
 		memcmp(data, ctx.hdr_md5_sum, 16) == 0;
 }
diff -r fa5e27725f6b -r 9f1616eeffb8 src/lib-storage/index/mbox/mbox-sync.c
--- a/src/lib-storage/index/mbox/mbox-sync.c	Thu Jul 30 19:30:15 2009 -0400
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Thu Jul 30 19:37:50 2009 -0400
@@ -252,7 +252,7 @@ static void mbox_sync_find_index_md5(str
 		rec = mail_index_lookup(sync_ctx->sync_view, sync_ctx->idx_seq);
 		mail_index_lookup_ext(sync_ctx->sync_view,
 				      sync_ctx->idx_seq,
-				      sync_ctx->mbox->ibox.md5hdr_ext_idx,
+				      sync_ctx->mbox->md5hdr_ext_idx,
 				      &data, NULL);
 		if (data != NULL && memcmp(data, hdr_md5_sum, 16) == 0)
 			break;
@@ -311,12 +311,11 @@ mbox_sync_update_md5_if_changed(struct m
 	const void *ext_data;
 
 	mail_index_lookup_ext(sync_ctx->sync_view, sync_ctx->idx_seq,
-			      sync_ctx->mbox->ibox.md5hdr_ext_idx,
-			      &ext_data, NULL);
+			      sync_ctx->mbox->md5hdr_ext_idx, &ext_data, NULL);
 	if (ext_data == NULL ||
 	    memcmp(mail_ctx->hdr_md5_sum, ext_data, 16) != 0) {
 		mail_index_update_ext(sync_ctx->t, sync_ctx->idx_seq,
-				      sync_ctx->mbox->ibox.md5hdr_ext_idx,
+				      sync_ctx->mbox->md5hdr_ext_idx,
 				      mail_ctx->hdr_md5_sum, NULL);
 	}
 }
@@ -425,7 +424,7 @@ static void mbox_sync_update_index(struc
 
 		if (sync_ctx->mbox->mbox_save_md5 != 0) {
 			mail_index_update_ext(sync_ctx->t, sync_ctx->idx_seq,
-				sync_ctx->mbox->ibox.md5hdr_ext_idx,
+				sync_ctx->mbox->md5hdr_ext_idx,
 				mail_ctx->hdr_md5_sum, NULL);
 		}
 	} else {


More information about the dovecot-cvs mailing list