]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: If we detect a broken cached message size, log more information about it.
authorTimo Sirainen <tss@iki.fi>
Fri, 17 Oct 2014 22:55:02 +0000 (01:55 +0300)
committerTimo Sirainen <tss@iki.fi>
Fri, 17 Oct 2014 22:55:02 +0000 (01:55 +0300)
Also try to include one of the cached headers in the message, which could
allow detecting if the cached data pointed to a completely different
message.

src/lib-storage/index/istream-mail.c

index ee8d0dc29c2bbc684120cfa3a724c0ee2b048a46..721e02b5f31fa805b781ca368fbf939bb9459c16 100644 (file)
@@ -31,11 +31,36 @@ static bool i_stream_mail_try_get_cached_size(struct mail_istream *mstream)
        return mstream->expected_size != (uoff_t)-1;
 }
 
+static const char *
+i_stream_mail_get_cached_mail_id(struct mail_istream *mstream)
+{
+       static const char *headers[] = {
+               "Message-Id",
+               "Date",
+               "Subject"
+       };
+       struct mail *mail = mstream->mail;
+       enum mail_lookup_abort orig_lookup_abort;
+       const char *value, *ret = "";
+       unsigned int i;
+
+       orig_lookup_abort = mail->lookup_abort;
+       mail->lookup_abort = MAIL_LOOKUP_ABORT_NOT_IN_CACHE;
+       for (i = 0; i < N_ELEMENTS(headers); i++) {
+               if (mail_get_first_header(mail, headers[i], &value) > 0) {
+                       ret = t_strdup_printf("%s=%s", headers[i], value);
+                       break;
+               }
+       }
+       mail->lookup_abort = orig_lookup_abort;
+       return ret;
+}
+
 static void
 i_stream_mail_set_size_corrupted(struct mail_istream *mstream, size_t size)
 {
        uoff_t cur_size = mstream->istream.istream.v_offset + size;
-       const char *str;
+       const char *str, *mail_id;
        char chr;
 
        if (mstream->expected_size < cur_size) {
@@ -46,10 +71,15 @@ i_stream_mail_set_size_corrupted(struct mail_istream *mstream, size_t size)
                chr = '>';
        }
 
+       mail_id = i_stream_mail_get_cached_mail_id(mstream);
+       if (mail_id[0] != '\0')
+               mail_id = t_strconcat(", cached ", mail_id, NULL);
        io_stream_set_error(&mstream->istream.iostream,
                "Cached message size %s than expected "
-               "(%"PRIuUOFF_T" %c %"PRIuUOFF_T")", str,
-               mstream->expected_size, chr, cur_size);
+               "(%"PRIuUOFF_T" %c %"PRIuUOFF_T", box=%s, UID=%u%s)", str,
+               mstream->expected_size, chr, cur_size,
+               mailbox_get_vname(mstream->mail->box),
+               mstream->mail->uid, mail_id);
        mail_storage_set_critical(mstream->mail->box->storage, "%s",
                                  mstream->istream.iostream.error);
        mail_set_cache_corrupted(mstream->mail, MAIL_FETCH_PHYSICAL_SIZE);