]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: If uncached header unfolding fails, panic instead of returning error.
authorTimo Sirainen <tss@iki.fi>
Thu, 9 Oct 2014 13:42:01 +0000 (16:42 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 9 Oct 2014 13:42:01 +0000 (16:42 +0300)
This really shouldn't be happening. This also makes it clear that return
value -1 means some kind of I/O error instead of corruption.

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

index 986949bfd36106847a3cc8cbe12b9f75bf1e565e..47f883304e8ec7485150ec3582ef522961b0d36e 100644 (file)
@@ -773,9 +773,10 @@ int index_mail_get_headers(struct mail *_mail, const char *field,
                           bool decode_to_utf8, const char *const **value_r)
 {
        struct index_mail *mail = (struct index_mail *)_mail;
-       int ret, i;
+       bool retry = TRUE;
+       int ret;
 
-       for (i = 0; i < 2; i++) {
+       for (;; retry = FALSE) {
                if (index_mail_get_raw_headers(mail, field, value_r) < 0)
                        return -1;
                if (!decode_to_utf8 || **value_r == NULL)
@@ -785,16 +786,20 @@ int index_mail_get_headers(struct mail *_mail, const char *field,
                        ret = index_mail_headers_decode(mail, value_r, UINT_MAX);
                } T_END;
 
-               if (ret < 0) {
+               if (ret < 0 && retry) {
                        mail_cache_set_corrupted(_mail->box->cache,
                                "Broken header %s for mail UID %u",
                                field, _mail->uid);
-                       /* retry by parsing the full header */
                } else {
                        break;
                }
        }
-       return ret;
+       if (ret < 0) {
+               i_panic("BUG: Broken header %s for mail UID %u "
+                       "wasn't fixed by re-parsing the header",
+                       field, _mail->uid);
+       }
+       return 1;
 }
 
 int index_mail_get_first_header(struct mail *_mail, const char *field,
@@ -802,9 +807,10 @@ int index_mail_get_first_header(struct mail *_mail, const char *field,
 {
        struct index_mail *mail = (struct index_mail *)_mail;
        const char *const *list;
-       int ret, i;
+       bool retry = TRUE;
+       int ret;
 
-       for (i = 0; i < 2; i++) {
+       for (;; retry = FALSE) {
                if (index_mail_get_raw_headers(mail, field, &list) < 0)
                        return -1;
                if (!decode_to_utf8 || list[0] == NULL) {
@@ -816,7 +822,7 @@ int index_mail_get_first_header(struct mail *_mail, const char *field,
                        ret = index_mail_headers_decode(mail, &list, 1);
                } T_END;
 
-               if (ret < 0) {
+               if (ret < 0 && retry) {
                        mail_cache_set_corrupted(_mail->box->cache,
                                "Broken header %s for mail UID %u",
                                field, _mail->uid);
@@ -825,8 +831,13 @@ int index_mail_get_first_header(struct mail *_mail, const char *field,
                        break;
                }
        }
+       if (ret < 0) {
+               i_panic("BUG: Broken header %s for mail UID %u "
+                       "wasn't fixed by re-parsing the header",
+                       field, _mail->uid);
+       }
        *value_r = list[0];
-       return ret < 0 ? -1 : (list[0] != NULL ? 1 : 0);
+       return list[0] != NULL ? 1 : 0;
 }
 
 static void