static int check_inbody_header(struct mailinfo *mi, const struct strbuf *line) { if (mi->inbody_header_accum.len && (line->buf[0] == ' ' || line->buf[0] == '\t')) { if (mi->use_scissors && is_scissors_line(line->buf)) { /* * This is a scissors line; do not consider this line * as a header continuation line. */ flush_inbody_header_accum(mi); return 0; } strbuf_strip_suffix(&mi->inbody_header_accum, "\n"); strbuf_addbuf(&mi->inbody_header_accum, line); return 1; } flush_inbody_header_accum(mi); if (starts_with(line->buf, ">From") && isspace(line->buf[5])) return is_format_patch_separator(line->buf + 1, line->len - 1); if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) { int i; for (i = 0; header[i]; i++) if (!strcmp("Subject", header[i])) { handle_header(&mi->s_hdr_data[i], line); return 1; } return 0; } if (is_inbody_header(mi, line)) { strbuf_addbuf(&mi->inbody_header_accum, line); return 1; } return 0; }
static int check_header(struct mailinfo *mi, const struct strbuf *line, struct strbuf *hdr_data[], int overwrite) { int i, ret = 0, len; struct strbuf sb = STRBUF_INIT; /* search for the interesting parts */ for (i = 0; header[i]; i++) { int len = strlen(header[i]); if ((!hdr_data[i] || overwrite) && cmp_header(line, header[i])) { /* Unwrap inline B and Q encoding, and optionally * normalize the meta information to utf8. */ strbuf_add(&sb, line->buf + len + 2, line->len - len - 2); decode_header(mi, &sb); handle_header(&hdr_data[i], &sb); ret = 1; goto check_header_out; } } /* Content stuff */ if (cmp_header(line, "Content-Type")) { len = strlen("Content-Type: "); strbuf_add(&sb, line->buf + len, line->len - len); decode_header(mi, &sb); strbuf_insert(&sb, 0, "Content-Type: ", len); handle_content_type(mi, &sb); ret = 1; goto check_header_out; } if (cmp_header(line, "Content-Transfer-Encoding")) { len = strlen("Content-Transfer-Encoding: "); strbuf_add(&sb, line->buf + len, line->len - len); decode_header(mi, &sb); handle_content_transfer_encoding(mi, &sb); ret = 1; goto check_header_out; } if (cmp_header(line, "Message-Id")) { len = strlen("Message-Id: "); strbuf_add(&sb, line->buf + len, line->len - len); decode_header(mi, &sb); handle_message_id(mi, &sb); ret = 1; goto check_header_out; } /* for inbody stuff */ if (starts_with(line->buf, ">From") && isspace(line->buf[5])) { ret = is_format_patch_separator(line->buf + 1, line->len - 1); goto check_header_out; } if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) { for (i = 0; header[i]; i++) { if (!strcmp("Subject", header[i])) { handle_header(&hdr_data[i], line); ret = 1; goto check_header_out; } } } check_header_out: strbuf_release(&sb); return ret; }