]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: Assume that empty uid maps found during sync are harmless
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Mon, 23 Apr 2018 22:15:51 +0000 (18:15 -0400)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 4 May 2018 13:30:00 +0000 (16:30 +0300)
Instead of failing the sync and causing index rebuild, just skip over
the empty uid maps.  Chances are that they these records came from
various plugins that create fake mails.

src/lib-storage/index/dbox-multi/mdbox-sync.c

index 1ba673223beb507097931c1bd963ed5ae22b7578..76b68d69d920212a13f606a96a7d08c972f26df1 100644 (file)
@@ -23,6 +23,7 @@
 #include "mdbox-sync.h"
 
 
+/* returns -1 on error, 1 on success, 0 if guid is empty/missing */
 static int
 dbox_sync_verify_expunge_guid(struct mdbox_sync_context *ctx, uint32_t seq,
                              const guid_128_t guid_128)
@@ -33,9 +34,13 @@ dbox_sync_verify_expunge_guid(struct mdbox_sync_context *ctx, uint32_t seq,
        mail_index_lookup_uid(ctx->sync_view, seq, &uid);
        mail_index_lookup_ext(ctx->sync_view, seq,
                              ctx->mbox->guid_ext_id, &data, NULL);
+
+       if ((data == NULL) || guid_128_is_empty(data))
+               return 0;
+
        if (guid_128_is_empty(guid_128) ||
            memcmp(data, guid_128, GUID_128_SIZE) == 0)
-               return 0;
+               return 1;
 
        mail_storage_set_critical(&ctx->mbox->storage->storage.storage,
                "Mailbox %s: Expunged GUID mismatch for UID %u: %s vs %s",
@@ -49,14 +54,16 @@ static int mdbox_sync_expunge(struct mdbox_sync_context *ctx, uint32_t seq,
                              const guid_128_t guid_128)
 {
        uint32_t map_uid;
+       int ret;
 
        if (seq_range_array_add(&ctx->expunged_seqs, seq)) {
                /* already marked as expunged in this sync */
                return 0;
        }
 
-       if (dbox_sync_verify_expunge_guid(ctx, seq, guid_128) < 0)
-               return -1;
+       ret = dbox_sync_verify_expunge_guid(ctx, seq, guid_128);
+       if (ret <= 0)
+               return ret;
        if (mdbox_mail_lookup(ctx->mbox, ctx->sync_view, seq, &map_uid) < 0)
                return -1;
        if (mdbox_map_update_refcount(ctx->map_trans, map_uid, -1) < 0)
@@ -107,7 +114,10 @@ static int dbox_sync_mark_expunges(struct mdbox_sync_context *ctx)
                mail_index_lookup_uid(ctx->sync_view, seq, &uid);
                mail_index_lookup_ext(ctx->sync_view, seq,
                                      ctx->mbox->guid_ext_id, &data, NULL);
-               mail_index_expunge_guid(trans, seq, data);
+               if ((data == NULL) || guid_128_is_empty(data))
+                       mail_index_expunge(trans, seq);
+               else
+                       mail_index_expunge_guid(trans, seq, data);
        }
        if (mail_index_transaction_commit(&trans) < 0)
                return -1;