Regarding that loop termination condition, you wrote up a long explanation, which means this code will need to be simplified or else there will be mistakes (if not now, then in the future). Postfix is about not writing clever code.
I took a little time to fix the delivered_hdr.c code, so now I have an example of how to process large headers without surprises. This code works until someone sets main.cf:line_length_limit to an insanely small value (it's 2048 by default). We could use similar code to pick up Message-Id: headers in the bounce daemon. That would really be a weekend project. Wietse int curr_type; int prev_type; ... for (prev_type = REC_TYPE_NORM; info->table->used < DELIVERED_HDR_LIMIT && ((curr_type = rec_get(fp, info->buf, 0)) == REC_TYPE_NORM || curr_type == REC_TYPE_CONT); prev_type = curr_type) { if (prev_type != REC_TYPE_NORM) continue; /* From here on, no code change */ if (is_header(STR(info->buf))) { /* see if it is interesting */ } else if (ISSPACE(STR(info->buf)[0])) { continue; } else { break; } }