]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Added mail_cache_get_missing_reason()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 28 Jul 2016 21:37:07 +0000 (00:37 +0300)
committerGitLab <gitlab@git.dovecot.net>
Wed, 3 Aug 2016 08:52:57 +0000 (11:52 +0300)
src/lib-index/mail-cache-lookup.c
src/lib-index/mail-cache.h

index 206c8fd15d0694ee0d6e5e6f839e62533358ebec..f3d2bc3850c83f46159a885624bbe3e56259f63a 100644 (file)
@@ -609,3 +609,45 @@ int mail_cache_lookup_headers(struct mail_cache_view *view, string_t *dest,
        } T_END;
        return ret;
 }
+
+const char *
+mail_cache_get_missing_reason(struct mail_cache_view *view, uint32_t seq)
+{
+       uint32_t offset, reset_id;
+
+       if (MAIL_CACHE_IS_UNUSABLE(view->cache))
+               return "Cache file is unusable";
+
+       offset = mail_cache_lookup_cur_offset(view->view, seq, &reset_id);
+       if (offset != 0) {
+               if (view->cache->hdr->file_seq != reset_id) {
+                       return t_strdup_printf(
+                               "Index reset_id=%u doesn't match cache reset_id=%u",
+                               reset_id, view->cache->hdr->file_seq);
+               }
+               return t_strdup_printf(
+                       "Mail has other cached fields, reset_id=%u", reset_id);
+       }
+
+       /* find the newest mail that has anything in cache */
+       for (; seq > 0; seq--) {
+               offset = mail_cache_lookup_cur_offset(view->view, seq, &reset_id);
+               if (offset != 0)
+                       break;
+       }
+       if (seq == 0)
+               return t_strdup_printf("Cache file is empty, reset_id=%u", reset_id);
+
+       uint32_t uid;
+       mail_index_lookup_uid(view->view, seq, &uid);
+
+       if (view->cache->hdr->file_seq != reset_id) {
+               return t_strdup_printf(
+                       "Mail not cached, highest cached seq=%u uid=%u: "
+                       "Index reset_id=%u doesn't match cache reset_id=%u",
+                       seq, uid, reset_id, view->cache->hdr->file_seq);
+       }
+       return t_strdup_printf(
+               "Mail not cached, highest cached seq=%u uid=%u: reset_id=%u",
+               seq, uid, reset_id);
+}
index d6771768d1106c1fa956523e0d7aafece58099c5..2cc798934622a39c81bebeabb0bbefdbe9b69f57 100644 (file)
@@ -137,4 +137,10 @@ void mail_cache_set_corrupted(struct mail_cache *cache, const char *fmt, ...)
 /* Delete the cache file. */
 void mail_cache_reset(struct mail_cache *cache);
 
+/* Returns human-readable reason for why a cached field is missing for
+   the specified mail. This is mainly for debugging purposes, so the exact
+   field doesn't matter here. */
+const char *
+mail_cache_get_missing_reason(struct mail_cache_view *view, uint32_t seq);
+
 #endif