6 static void cleanup_space(struct strbuf *sb)
9 for (pos = 0; pos < sb->len; pos++) {
10 if (isspace(sb->buf[pos])) {
12 for (cnt = 0; isspace(sb->buf[pos + cnt + 1]); cnt++);
13 strbuf_remove(sb, pos + 1, cnt);
18 static void get_sane_name(struct strbuf *out, struct strbuf *name, struct strbuf *email)
20 struct strbuf *src = name;
21 if (name->len < 3 || 60 < name->len || strchr(name->buf, '@') ||
22 strchr(name->buf, '<') || strchr(name->buf, '>'))
27 strbuf_addbuf(out, src);
30 static void parse_bogus_from(struct mailinfo *mi, const struct strbuf *line)
32 /* John Doe <johndoe> */
35 /* This is fallback, so do not bother if we already have an
41 bra = strchr(line->buf, '<');
44 ket = strchr(bra, '>');
48 strbuf_reset(&mi->email);
49 strbuf_add(&mi->email, bra + 1, ket - bra - 1);
51 strbuf_reset(&mi->name);
52 strbuf_add(&mi->name, line->buf, bra - line->buf);
53 strbuf_trim(&mi->name);
54 get_sane_name(&mi->name, &mi->name, &mi->email);
57 static void handle_from(struct mailinfo *mi, const struct strbuf *from)
63 strbuf_init(&f, from->len);
64 strbuf_addbuf(&f, from);
66 at = strchr(f.buf, '@');
68 parse_bogus_from(mi, from);
73 * If we already have one email, don't take any confusing lines
75 if (mi->email.len && strchr(at + 1, '@')) {
80 /* Pick up the string around '@', possibly delimited with <>
81 * pair; that is the email part.
93 el = strcspn(at, " \n\t\r\v\f>");
94 strbuf_reset(&mi->email);
95 strbuf_add(&mi->email, at, el);
96 strbuf_remove(&f, at - f.buf, el + (at[el] ? 1 : 0));
98 /* The remainder is name. It could be
100 * - "John Doe <john.doe@xz>" (a), or
101 * - "john.doe@xz (John Doe)" (b), or
102 * - "John (zzz) Doe <john.doe@xz> (Comment)" (c)
104 * but we have removed the email part, so
106 * - remove extra spaces which could stay after email (case 'c'), and
107 * - trim from both ends, possibly removing the () pair at the end
108 * (cases 'a' and 'b').
112 if (f.buf[0] == '(' && f.len && f.buf[f.len - 1] == ')') {
113 strbuf_remove(&f, 0, 1);
114 strbuf_setlen(&f, f.len - 1);
117 get_sane_name(&mi->name, &f, &mi->email);
121 static void handle_header(struct strbuf **out, const struct strbuf *line)
124 *out = xmalloc(sizeof(struct strbuf));
125 strbuf_init(*out, line->len);
129 strbuf_addbuf(*out, line);
132 /* NOTE NOTE NOTE. We do not claim we do full MIME. We just attempt
133 * to have enough heuristics to grok MIME encoded patches often found
134 * on our mailing lists. For example, we do not even treat header lines
135 * case insensitively.
138 static int slurp_attr(const char *line, const char *name, struct strbuf *attr)
140 const char *ends, *ap = strcasestr(line, name);
143 strbuf_setlen(attr, 0);
153 sz = strcspn(ap, ends);
154 strbuf_add(attr, ap, sz);
158 static void handle_content_type(struct mailinfo *mi, struct strbuf *line)
160 struct strbuf *boundary = xmalloc(sizeof(struct strbuf));
161 strbuf_init(boundary, line->len);
163 if (slurp_attr(line->buf, "boundary=", boundary)) {
164 strbuf_insert(boundary, 0, "--", 2);
165 if (++mi->content_top >= &mi->content[MAX_BOUNDARIES]) {
166 error("Too many boundaries to handle");
167 mi->input_error = -1;
168 mi->content_top = &mi->content[MAX_BOUNDARIES] - 1;
171 *(mi->content_top) = boundary;
174 slurp_attr(line->buf, "charset=", &mi->charset);
177 strbuf_release(boundary);
182 static void handle_content_transfer_encoding(struct mailinfo *mi,
183 const struct strbuf *line)
185 if (strcasestr(line->buf, "base64"))
186 mi->transfer_encoding = TE_BASE64;
187 else if (strcasestr(line->buf, "quoted-printable"))
188 mi->transfer_encoding = TE_QP;
190 mi->transfer_encoding = TE_DONTCARE;
193 static int is_multipart_boundary(struct mailinfo *mi, const struct strbuf *line)
195 struct strbuf *content_top = *(mi->content_top);
197 return ((content_top->len <= line->len) &&
198 !memcmp(line->buf, content_top->buf, content_top->len));
201 static void cleanup_subject(struct mailinfo *mi, struct strbuf *subject)
205 while (at < subject->len) {
209 switch (subject->buf[at]) {
211 if (subject->len <= at + 3)
213 if ((subject->buf[at + 1] == 'e' ||
214 subject->buf[at + 1] == 'E') &&
215 subject->buf[at + 2] == ':') {
216 strbuf_remove(subject, at, 3);
221 case ' ': case '\t': case ':':
222 strbuf_remove(subject, at, 1);
225 pos = strchr(subject->buf + at, ']');
228 remove = pos - subject->buf + at + 1;
229 if (!mi->keep_non_patch_brackets_in_subject ||
231 memmem(subject->buf + at, remove, "PATCH", 5)))
232 strbuf_remove(subject, at, remove);
236 * If the input had a space after the ], keep
237 * it. We don't bother with finding the end of
238 * the space, since we later normalize it
241 if (isspace(subject->buf[at]))
248 strbuf_trim(subject);
251 #define MAX_HDR_PARSED 10
252 static const char *header[MAX_HDR_PARSED] = {
253 "From","Subject","Date",
256 static inline int cmp_header(const struct strbuf *line, const char *hdr)
258 int len = strlen(hdr);
259 return !strncasecmp(line->buf, hdr, len) && line->len > len &&
260 line->buf[len] == ':' && isspace(line->buf[len + 1]);
263 static int is_format_patch_separator(const char *line, int len)
265 static const char SAMPLE[] =
266 "From e6807f3efca28b30decfecb1732a56c7db1137ee Mon Sep 17 00:00:00 2001\n";
269 if (len != strlen(SAMPLE))
271 if (!skip_prefix(line, "From ", &cp))
273 if (strspn(cp, "0123456789abcdef") != 40)
276 return !memcmp(SAMPLE + (cp - line), cp, strlen(SAMPLE) - (cp - line));
279 static struct strbuf *decode_q_segment(const struct strbuf *q_seg, int rfc2047)
281 const char *in = q_seg->buf;
283 struct strbuf *out = xmalloc(sizeof(struct strbuf));
284 strbuf_init(out, q_seg->len);
286 while ((c = *in++) != 0) {
290 break; /* drop trailing newline */
291 strbuf_addch(out, (hexval(d) << 4) | hexval(*in++));
294 if (rfc2047 && c == '_') /* rfc2047 4.2 (2) */
296 strbuf_addch(out, c);
301 static struct strbuf *decode_b_segment(const struct strbuf *b_seg)
303 /* Decode in..ep, possibly in-place to ot */
304 int c, pos = 0, acc = 0;
305 const char *in = b_seg->buf;
306 struct strbuf *out = xmalloc(sizeof(struct strbuf));
307 strbuf_init(out, b_seg->len);
309 while ((c = *in++) != 0) {
314 else if ('A' <= c && c <= 'Z')
316 else if ('a' <= c && c <= 'z')
318 else if ('0' <= c && c <= '9')
321 continue; /* garbage */
327 strbuf_addch(out, (acc | (c >> 4)));
331 strbuf_addch(out, (acc | (c >> 2)));
335 strbuf_addch(out, (acc | c));
343 static int convert_to_utf8(struct mailinfo *mi,
344 struct strbuf *line, const char *charset)
348 if (!mi->metainfo_charset || !charset || !*charset)
351 if (same_encoding(mi->metainfo_charset, charset))
353 out = reencode_string(line->buf, mi->metainfo_charset, charset);
355 mi->input_error = -1;
356 return error("cannot convert from %s to %s",
357 charset, mi->metainfo_charset);
359 strbuf_attach(line, out, strlen(out), strlen(out));
363 static void decode_header(struct mailinfo *mi, struct strbuf *it)
366 struct strbuf outbuf = STRBUF_INIT, *dec;
367 struct strbuf charset_q = STRBUF_INIT, piecebuf = STRBUF_INIT;
368 int found_error = 1; /* pessimism */
371 while (in - it->buf <= it->len && (ep = strstr(in, "=?")) != NULL) {
373 strbuf_reset(&charset_q);
374 strbuf_reset(&piecebuf);
378 * We are about to process an encoded-word
379 * that begins at ep, but there is something
380 * before the encoded word.
383 for (scan = in; scan < ep; scan++)
387 if (scan != ep || in == it->buf) {
389 * We should not lose that "something",
390 * unless we have just processed an
391 * encoded-word, and there is only LWS
392 * before the one we are about to process.
394 strbuf_add(&outbuf, in, ep - in);
398 * ep : "=?iso-2022-jp?B?GyR...?= foo"
399 * ep : "=?ISO-8859-1?Q?Foo=FCbar?= baz"
403 if (ep - it->buf >= it->len || !(cp = strchr(ep, '?')))
406 if (cp + 3 - it->buf > it->len)
408 strbuf_add(&charset_q, ep, cp - ep);
411 if (!encoding || cp[2] != '?')
413 ep = strstr(cp + 3, "?=");
416 strbuf_add(&piecebuf, cp + 3, ep - cp - 3);
417 switch (tolower(encoding)) {
421 dec = decode_b_segment(&piecebuf);
424 dec = decode_q_segment(&piecebuf, 1);
427 if (convert_to_utf8(mi, dec, charset_q.buf))
430 strbuf_addbuf(&outbuf, dec);
435 strbuf_addstr(&outbuf, in);
437 strbuf_addbuf(it, &outbuf);
440 strbuf_release(&outbuf);
441 strbuf_release(&charset_q);
442 strbuf_release(&piecebuf);
445 mi->input_error = -1;
448 static int check_header(struct mailinfo *mi,
449 const struct strbuf *line,
450 struct strbuf *hdr_data[], int overwrite)
453 struct strbuf sb = STRBUF_INIT;
455 /* search for the interesting parts */
456 for (i = 0; header[i]; i++) {
457 int len = strlen(header[i]);
458 if ((!hdr_data[i] || overwrite) && cmp_header(line, header[i])) {
459 /* Unwrap inline B and Q encoding, and optionally
460 * normalize the meta information to utf8.
462 strbuf_add(&sb, line->buf + len + 2, line->len - len - 2);
463 decode_header(mi, &sb);
464 handle_header(&hdr_data[i], &sb);
466 goto check_header_out;
471 if (cmp_header(line, "Content-Type")) {
472 len = strlen("Content-Type: ");
473 strbuf_add(&sb, line->buf + len, line->len - len);
474 decode_header(mi, &sb);
475 strbuf_insert(&sb, 0, "Content-Type: ", len);
476 handle_content_type(mi, &sb);
478 goto check_header_out;
480 if (cmp_header(line, "Content-Transfer-Encoding")) {
481 len = strlen("Content-Transfer-Encoding: ");
482 strbuf_add(&sb, line->buf + len, line->len - len);
483 decode_header(mi, &sb);
484 handle_content_transfer_encoding(mi, &sb);
486 goto check_header_out;
488 if (cmp_header(line, "Message-Id")) {
489 len = strlen("Message-Id: ");
490 strbuf_add(&sb, line->buf + len, line->len - len);
491 decode_header(mi, &sb);
492 if (mi->add_message_id)
493 mi->message_id = strbuf_detach(&sb, NULL);
495 goto check_header_out;
504 * Returns 1 if the given line or any line beginning with the given line is an
505 * in-body header (that is, check_header will succeed when passed
508 static int is_inbody_header(const struct mailinfo *mi,
509 const struct strbuf *line)
512 for (i = 0; header[i]; i++)
513 if (!mi->s_hdr_data[i] && cmp_header(line, header[i]))
518 static void decode_transfer_encoding(struct mailinfo *mi, struct strbuf *line)
522 switch (mi->transfer_encoding) {
524 ret = decode_q_segment(line, 0);
527 ret = decode_b_segment(line);
534 strbuf_addbuf(line, ret);
539 static inline int patchbreak(const struct strbuf *line)
543 /* Beginning of a "diff -" header? */
544 if (starts_with(line->buf, "diff -"))
547 /* CVS "Index: " line? */
548 if (starts_with(line->buf, "Index: "))
552 * "--- <filename>" starts patches without headers
553 * "---<sp>*" is a manual separator
558 if (starts_with(line->buf, "---")) {
559 /* space followed by a filename? */
560 if (line->buf[3] == ' ' && !isspace(line->buf[4]))
562 /* Just whitespace? */
563 for (i = 3; i < line->len; i++) {
564 unsigned char c = line->buf[i];
575 static int is_scissors_line(const char *line)
578 int scissors = 0, gap = 0;
579 const char *first_nonblank = NULL, *last_nonblank = NULL;
580 int visible, perforation = 0, in_perforation = 0;
582 for (c = line; *c; c++) {
584 if (in_perforation) {
591 if (first_nonblank == NULL)
598 if ((!memcmp(c, ">8", 2) || !memcmp(c, "8<", 2) ||
599 !memcmp(c, ">%", 2) || !memcmp(c, "%<", 2))) {
610 * The mark must be at least 8 bytes long (e.g. "-- >8 --").
611 * Even though there can be arbitrary cruft on the same line
612 * (e.g. "cut here"), in order to avoid misidentification, the
613 * perforation must occupy more than a third of the visible
614 * width of the line, and dashes and scissors must occupy more
615 * than half of the perforation.
618 if (first_nonblank && last_nonblank)
619 visible = last_nonblank - first_nonblank + 1;
622 return (scissors && 8 <= visible &&
623 visible < perforation * 3 &&
624 gap * 2 < perforation);
627 static void flush_inbody_header_accum(struct mailinfo *mi)
629 if (!mi->inbody_header_accum.len)
631 if (!check_header(mi, &mi->inbody_header_accum, mi->s_hdr_data, 0))
632 die("BUG: inbody_header_accum, if not empty, must always contain a valid in-body header");
633 strbuf_reset(&mi->inbody_header_accum);
636 static int check_inbody_header(struct mailinfo *mi, const struct strbuf *line)
638 if (mi->inbody_header_accum.len &&
639 (line->buf[0] == ' ' || line->buf[0] == '\t')) {
640 if (mi->use_scissors && is_scissors_line(line->buf)) {
642 * This is a scissors line; do not consider this line
643 * as a header continuation line.
645 flush_inbody_header_accum(mi);
648 strbuf_strip_suffix(&mi->inbody_header_accum, "\n");
649 strbuf_addbuf(&mi->inbody_header_accum, line);
653 flush_inbody_header_accum(mi);
655 if (starts_with(line->buf, ">From") && isspace(line->buf[5]))
656 return is_format_patch_separator(line->buf + 1, line->len - 1);
657 if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) {
659 for (i = 0; header[i]; i++)
660 if (!strcmp("Subject", header[i])) {
661 handle_header(&mi->s_hdr_data[i], line);
666 if (is_inbody_header(mi, line)) {
667 strbuf_addbuf(&mi->inbody_header_accum, line);
673 static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
675 assert(!mi->filter_stage);
677 if (mi->header_stage) {
678 if (!line->len || (line->len == 1 && line->buf[0] == '\n'))
682 if (mi->use_inbody_headers && mi->header_stage) {
683 mi->header_stage = check_inbody_header(mi, line);
684 if (mi->header_stage)
687 /* Only trim the first (blank) line of the commit message
688 * when ignoring in-body headers.
690 mi->header_stage = 0;
692 /* normalize the log message to UTF-8. */
693 if (convert_to_utf8(mi, line, mi->charset.buf))
694 return 0; /* mi->input_error already set */
696 if (mi->use_scissors && is_scissors_line(line->buf)) {
699 strbuf_setlen(&mi->log_message, 0);
700 mi->header_stage = 1;
703 * We may have already read "secondary headers"; purge
704 * them to give ourselves a clean restart.
706 for (i = 0; header[i]; i++) {
707 if (mi->s_hdr_data[i])
708 strbuf_release(mi->s_hdr_data[i]);
709 mi->s_hdr_data[i] = NULL;
714 if (patchbreak(line)) {
716 strbuf_addf(&mi->log_message,
717 "Message-Id: %s\n", mi->message_id);
721 strbuf_addbuf(&mi->log_message, line);
725 static void handle_patch(struct mailinfo *mi, const struct strbuf *line)
727 fwrite(line->buf, 1, line->len, mi->patchfile);
731 static void handle_filter(struct mailinfo *mi, struct strbuf *line)
733 switch (mi->filter_stage) {
735 if (!handle_commit_msg(mi, line))
739 handle_patch(mi, line);
744 static int is_rfc2822_header(const struct strbuf *line)
747 * The section that defines the loosest possible
748 * field name is "3.6.8 Optional fields".
750 * optional-field = field-name ":" unstructured CRLF
751 * field-name = 1*ftext
752 * ftext = %d33-57 / %59-126
755 char *cp = line->buf;
757 /* Count mbox From headers as headers */
758 if (starts_with(cp, "From ") || starts_with(cp, ">From "))
761 while ((ch = *cp++)) {
764 if ((33 <= ch && ch <= 57) ||
765 (59 <= ch && ch <= 126))
772 static int read_one_header_line(struct strbuf *line, FILE *in)
774 struct strbuf continuation = STRBUF_INIT;
776 /* Get the first part of the line. */
777 if (strbuf_getline_lf(line, in))
781 * Is it an empty line or not a valid rfc2822 header?
782 * If so, stop here, and return false ("not a header")
785 if (!line->len || !is_rfc2822_header(line)) {
786 /* Re-add the newline */
787 strbuf_addch(line, '\n');
792 * Now we need to eat all the continuation lines..
793 * Yuck, 2822 header "folding"
798 peek = fgetc(in); ungetc(peek, in);
799 if (peek != ' ' && peek != '\t')
801 if (strbuf_getline_lf(&continuation, in))
803 continuation.buf[0] = ' ';
804 strbuf_rtrim(&continuation);
805 strbuf_addbuf(line, &continuation);
807 strbuf_release(&continuation);
812 static int find_boundary(struct mailinfo *mi, struct strbuf *line)
814 while (!strbuf_getline_lf(line, mi->input)) {
815 if (*(mi->content_top) && is_multipart_boundary(mi, line))
821 static int handle_boundary(struct mailinfo *mi, struct strbuf *line)
823 struct strbuf newline = STRBUF_INIT;
825 strbuf_addch(&newline, '\n');
827 if (line->len >= (*(mi->content_top))->len + 2 &&
828 !memcmp(line->buf + (*(mi->content_top))->len, "--", 2)) {
829 /* we hit an end boundary */
830 /* pop the current boundary off the stack */
831 strbuf_release(*(mi->content_top));
832 free(*(mi->content_top));
833 *(mi->content_top) = NULL;
835 /* technically won't happen as is_multipart_boundary()
836 will fail first. But just in case..
838 if (--mi->content_top < mi->content) {
839 error("Detected mismatched boundaries, can't recover");
840 mi->input_error = -1;
841 mi->content_top = mi->content;
844 handle_filter(mi, &newline);
845 strbuf_release(&newline);
849 /* skip to the next boundary */
850 if (!find_boundary(mi, line))
855 /* set some defaults */
856 mi->transfer_encoding = TE_DONTCARE;
857 strbuf_reset(&mi->charset);
859 /* slurp in this section's info */
860 while (read_one_header_line(line, mi->input))
861 check_header(mi, line, mi->p_hdr_data, 0);
863 strbuf_release(&newline);
865 if (strbuf_getline_lf(line, mi->input))
867 strbuf_addch(line, '\n');
871 static void handle_body(struct mailinfo *mi, struct strbuf *line)
873 struct strbuf prev = STRBUF_INIT;
875 /* Skip up to the first boundary */
876 if (*(mi->content_top)) {
877 if (!find_boundary(mi, line))
878 goto handle_body_out;
882 /* process any boundary lines */
883 if (*(mi->content_top) && is_multipart_boundary(mi, line)) {
884 /* flush any leftover */
886 handle_filter(mi, &prev);
889 if (!handle_boundary(mi, line))
890 goto handle_body_out;
893 /* Unwrap transfer encoding */
894 decode_transfer_encoding(mi, line);
896 switch (mi->transfer_encoding) {
900 struct strbuf **lines, **it, *sb;
902 /* Prepend any previous partial lines */
903 strbuf_insert(line, 0, prev.buf, prev.len);
907 * This is a decoded line that may contain
908 * multiple new lines. Pass only one chunk
909 * at a time to handle_filter()
911 lines = strbuf_split(line, '\n');
912 for (it = lines; (sb = *it); it++) {
913 if (*(it + 1) == NULL) /* The last line */
914 if (sb->buf[sb->len - 1] != '\n') {
915 /* Partial line, save it for later. */
916 strbuf_addbuf(&prev, sb);
919 handle_filter(mi, sb);
922 * The partial chunk is saved in "prev" and will be
923 * appended by the next iteration of read_line_with_nul().
925 strbuf_list_free(lines);
929 handle_filter(mi, line);
934 } while (!strbuf_getwholeline(line, mi->input, '\n'));
936 flush_inbody_header_accum(mi);
939 strbuf_release(&prev);
942 static void output_header_lines(FILE *fout, const char *hdr, const struct strbuf *data)
944 const char *sp = data->buf;
946 char *ep = strchr(sp, '\n');
952 fprintf(fout, "%s: %.*s\n", hdr, len, sp);
959 static void handle_info(struct mailinfo *mi)
964 for (i = 0; header[i]; i++) {
965 /* only print inbody headers if we output a patch file */
966 if (mi->patch_lines && mi->s_hdr_data[i])
967 hdr = mi->s_hdr_data[i];
968 else if (mi->p_hdr_data[i])
969 hdr = mi->p_hdr_data[i];
973 if (!strcmp(header[i], "Subject")) {
974 if (!mi->keep_subject) {
975 cleanup_subject(mi, hdr);
978 output_header_lines(mi->output, "Subject", hdr);
979 } else if (!strcmp(header[i], "From")) {
981 handle_from(mi, hdr);
982 fprintf(mi->output, "Author: %s\n", mi->name.buf);
983 fprintf(mi->output, "Email: %s\n", mi->email.buf);
986 fprintf(mi->output, "%s: %s\n", header[i], hdr->buf);
989 fprintf(mi->output, "\n");
992 int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
996 struct strbuf line = STRBUF_INIT;
998 cmitmsg = fopen(msg, "w");
1003 mi->patchfile = fopen(patch, "w");
1004 if (!mi->patchfile) {
1010 mi->p_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*(mi->p_hdr_data)));
1011 mi->s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*(mi->s_hdr_data)));
1014 peek = fgetc(mi->input);
1015 } while (isspace(peek));
1016 ungetc(peek, mi->input);
1018 /* process the email header */
1019 while (read_one_header_line(&line, mi->input))
1020 check_header(mi, &line, mi->p_hdr_data, 1);
1022 handle_body(mi, &line);
1023 fwrite(mi->log_message.buf, 1, mi->log_message.len, cmitmsg);
1025 fclose(mi->patchfile);
1028 strbuf_release(&line);
1029 return mi->input_error;
1032 static int git_mailinfo_config(const char *var, const char *value, void *mi_)
1034 struct mailinfo *mi = mi_;
1036 if (!starts_with(var, "mailinfo."))
1037 return git_default_config(var, value, NULL);
1038 if (!strcmp(var, "mailinfo.scissors")) {
1039 mi->use_scissors = git_config_bool(var, value);
1042 /* perhaps others here */
1046 void setup_mailinfo(struct mailinfo *mi)
1048 memset(mi, 0, sizeof(*mi));
1049 strbuf_init(&mi->name, 0);
1050 strbuf_init(&mi->email, 0);
1051 strbuf_init(&mi->charset, 0);
1052 strbuf_init(&mi->log_message, 0);
1053 strbuf_init(&mi->inbody_header_accum, 0);
1054 mi->header_stage = 1;
1055 mi->use_inbody_headers = 1;
1056 mi->content_top = mi->content;
1057 git_config(git_mailinfo_config, mi);
1060 void clear_mailinfo(struct mailinfo *mi)
1064 strbuf_release(&mi->name);
1065 strbuf_release(&mi->email);
1066 strbuf_release(&mi->charset);
1067 strbuf_release(&mi->inbody_header_accum);
1068 free(mi->message_id);
1070 for (i = 0; mi->p_hdr_data[i]; i++)
1071 strbuf_release(mi->p_hdr_data[i]);
1072 free(mi->p_hdr_data);
1073 for (i = 0; mi->s_hdr_data[i]; i++)
1074 strbuf_release(mi->s_hdr_data[i]);
1075 free(mi->s_hdr_data);
1077 while (mi->content < mi->content_top) {
1078 free(*(mi->content_top));
1082 strbuf_release(&mi->log_message);