]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
index-storage: Moved mail MD5 calculation code to mbox-specific code.
authorTimo Sirainen <tss@iki.fi>
Thu, 30 Jul 2009 23:37:50 +0000 (19:37 -0400)
committerTimo Sirainen <tss@iki.fi>
Thu, 30 Jul 2009 23:37:50 +0000 (19:37 -0400)
Nothing else used it.

--HG--
branch : HEAD

src/lib-storage/index/index-mail.c
src/lib-storage/index/index-storage.c
src/lib-storage/index/index-storage.h
src/lib-storage/index/mbox/mbox-mail.c
src/lib-storage/index/mbox/mbox-save.c
src/lib-storage/index/mbox/mbox-storage.c
src/lib-storage/index/mbox/mbox-storage.h
src/lib-storage/index/mbox/mbox-sync-parse.c
src/lib-storage/index/mbox/mbox-sync.c

index 5a77e5e736401aa983f38e086853fac29b53a2a9..d886ac6266f1a90073ead682a1122276064bd26d 100644 (file)
@@ -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;
index 8a31a3535ee01b82feccec1bda993f03983f9939..39ae0812228a3704f5db0539bd9b2b68624620f1 100644 (file)
@@ -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,
index cffece56edb798f00424513a8bd84ea6d0af4513..1941f97a88fa8d6710078b2d6d0f65b466dc0661 100644 (file)
@@ -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;
index 0747077cbb18e2a615120a66477aa61ec3bb70d0..0bbcea3b2afaf7a52a4e4ab09e6827d9f3d74d5e 100644 (file)
@@ -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;
index e4a756b374560162b371eda53b0bb9b4af0d6d58..f96017cf069c781a0e8f4a38a850dabb4080849a 100644 (file)
@@ -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);
        }
 
index 12918142fda96e25478ed2b68bf97aef07a6350f..8e836eb26df8006bedfb2018dc732d51deefc37d 100644 (file)
@@ -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;
index 09481397eddfab73103bbe1c66e932aecc5d16d9..d0bdf3bc82218662a7233cf3fa2e955febb0adec 100644 (file)
@@ -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;
 
index f0b1dc5ef0ee0c217fab58e4f63041a808e10ac0..b8e066d5356f73e906e1aa2074af43baf1c5bfe7 100644 (file)
@@ -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;
 }
index f7019f11a22e8a351a7a9e8aef37c91dc9394c52..c842d89ac7145203d6dab565b52049308b46524b 100644 (file)
@@ -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 {