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)
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,
{
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) {
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);
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