From: Timo Sirainen Date: Thu, 30 Jul 2009 23:37:50 +0000 (-0400) Subject: index-storage: Moved mail MD5 calculation code to mbox-specific code. X-Git-Tag: 2.0.alpha1~350 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ea5f188fc29dfaa0c4071e6413e16e1d04263722;p=thirdparty%2Fdovecot%2Fcore.git index-storage: Moved mail MD5 calculation code to mbox-specific code. Nothing else used it. --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/index-mail.c b/src/lib-storage/index/index-mail.c index 5a77e5e736..d886ac6266 100644 --- a/src/lib-storage/index/index-mail.c +++ b/src/lib-storage/index/index-mail.c @@ -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 *_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 *_mail, case MAIL_FETCH_UIDL_BACKEND: case MAIL_FETCH_SEARCH_SCORE: case MAIL_FETCH_GUID: - *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); + *value_r = ""; return 0; case MAIL_FETCH_MAILBOX_NAME: *value_r = _mail->box->name; diff --git a/src/lib-storage/index/index-storage.c b/src/lib-storage/index/index-storage.c index 8a31a3535e..39ae081222 100644 --- a/src/lib-storage/index/index-storage.c +++ b/src/lib-storage/index/index-storage.c @@ -487,8 +487,6 @@ void index_storage_mailbox_alloc(struct index_mailbox *ibox, const char *name, 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 --git a/src/lib-storage/index/index-storage.h b/src/lib-storage/index/index-storage.h index cffece56ed..1941f97a88 100644 --- a/src/lib-storage/index/index-storage.h +++ b/src/lib-storage/index/index-storage.h @@ -26,8 +26,6 @@ struct index_mailbox { struct mail_cache *cache; struct mail_vfuncs *mail_vfuncs; - uint32_t md5hdr_ext_idx; - struct timeout *notify_to; struct index_notify_file *notify_files; struct index_notify_io *notify_ios; diff --git a/src/lib-storage/index/mbox/mbox-mail.c b/src/lib-storage/index/mbox/mbox-mail.c index 0747077cbb..0bbcea3b2a 100644 --- a/src/lib-storage/index/mbox/mbox-mail.c +++ b/src/lib-storage/index/mbox/mbox-mail.c @@ -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 @@ static int mbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field, const char **value_r) { -#define EMPTY_MD5_SUM "00000000000000000000000000000000" + 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, enum mail_fetch_field field, *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; + } + 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_SUM is valid and can happen, + /* 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 --git a/src/lib-storage/index/mbox/mbox-save.c b/src/lib-storage/index/mbox/mbox-save.c index e4a756b374..f96017cf06 100644 --- a/src/lib-storage/index/mbox/mbox-save.c +++ b/src/lib-storage/index/mbox/mbox-save.c @@ -642,7 +642,7 @@ int mbox_save_continue(struct mail_save_context *_ctx) } 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 --git a/src/lib-storage/index/mbox/mbox-storage.c b/src/lib-storage/index/mbox/mbox-storage.c index 12918142fd..8e836eb26d 100644 --- a/src/lib-storage/index/mbox/mbox-storage.c +++ b/src/lib-storage/index/mbox/mbox-storage.c @@ -358,6 +358,9 @@ mbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list, 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 --git a/src/lib-storage/index/mbox/mbox-storage.h b/src/lib-storage/index/mbox/mbox-storage.h index 09481397ed..d0bdf3bc82 100644 --- a/src/lib-storage/index/mbox/mbox-storage.h +++ b/src/lib-storage/index/mbox/mbox-storage.h @@ -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 --git a/src/lib-storage/index/mbox/mbox-sync-parse.c b/src/lib-storage/index/mbox/mbox-sync-parse.c index f0b1dc5ef0..b8e066d535 100644 --- a/src/lib-storage/index/mbox/mbox-sync-parse.c +++ b/src/lib-storage/index/mbox/mbox-sync-parse.c @@ -592,8 +592,7 @@ bool mbox_sync_parse_match_mail(struct mbox_mailbox *mbox, /* 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 --git a/src/lib-storage/index/mbox/mbox-sync.c b/src/lib-storage/index/mbox/mbox-sync.c index f7019f11a2..c842d89ac7 100644 --- a/src/lib-storage/index/mbox/mbox-sync.c +++ b/src/lib-storage/index/mbox/mbox-sync.c @@ -252,7 +252,7 @@ static void mbox_sync_find_index_md5(struct mbox_sync_context *sync_ctx, 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 mbox_sync_mail_context *mail_ctx) 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(struct mbox_sync_mail_context *mail_ctx, 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 {