2 * Another stupid program, this one parsing the headers of an
3 * email to figure out authorship and subject
19 int keep_non_patch_brackets_in_subject;
22 int use_inbody_headers;
23 const char *metainfo_charset;
25 struct strbuf charset;
28 TE_DONTCARE, TE_QP, TE_BASE64
31 int filter_stage; /* still reading log or are we copying patch? */
32 int header_stage; /* still checking in-body headers? */
33 struct strbuf **p_hdr_data;
34 struct strbuf **s_hdr_data;
37 #define MAX_BOUNDARIES 5
39 static void cleanup_space(struct strbuf *sb)
42 for (pos = 0; pos < sb->len; pos++) {
43 if (isspace(sb->buf[pos])) {
45 for (cnt = 0; isspace(sb->buf[pos + cnt + 1]); cnt++);
46 strbuf_remove(sb, pos + 1, cnt);
51 static void get_sane_name(struct strbuf *out, struct strbuf *name, struct strbuf *email)
53 struct strbuf *src = name;
54 if (name->len < 3 || 60 < name->len || strchr(name->buf, '@') ||
55 strchr(name->buf, '<') || strchr(name->buf, '>'))
60 strbuf_addbuf(out, src);
63 static void parse_bogus_from(struct mailinfo *mi, const struct strbuf *line)
65 /* John Doe <johndoe> */
68 /* This is fallback, so do not bother if we already have an
74 bra = strchr(line->buf, '<');
77 ket = strchr(bra, '>');
81 strbuf_reset(&mi->email);
82 strbuf_add(&mi->email, bra + 1, ket - bra - 1);
84 strbuf_reset(&mi->name);
85 strbuf_add(&mi->name, line->buf, bra - line->buf);
86 strbuf_trim(&mi->name);
87 get_sane_name(&mi->name, &mi->name, &mi->email);
90 static void handle_from(struct mailinfo *mi, const struct strbuf *from)
96 strbuf_init(&f, from->len);
97 strbuf_addbuf(&f, from);
99 at = strchr(f.buf, '@');
101 parse_bogus_from(mi, from);
106 * If we already have one email, don't take any confusing lines
108 if (mi->email.len && strchr(at + 1, '@')) {
113 /* Pick up the string around '@', possibly delimited with <>
114 * pair; that is the email part.
126 el = strcspn(at, " \n\t\r\v\f>");
127 strbuf_reset(&mi->email);
128 strbuf_add(&mi->email, at, el);
129 strbuf_remove(&f, at - f.buf, el + (at[el] ? 1 : 0));
131 /* The remainder is name. It could be
133 * - "John Doe <john.doe@xz>" (a), or
134 * - "john.doe@xz (John Doe)" (b), or
135 * - "John (zzz) Doe <john.doe@xz> (Comment)" (c)
137 * but we have removed the email part, so
139 * - remove extra spaces which could stay after email (case 'c'), and
140 * - trim from both ends, possibly removing the () pair at the end
141 * (cases 'a' and 'b').
145 if (f.buf[0] == '(' && f.len && f.buf[f.len - 1] == ')') {
146 strbuf_remove(&f, 0, 1);
147 strbuf_setlen(&f, f.len - 1);
150 get_sane_name(&mi->name, &f, &mi->email);
154 static void handle_header(struct strbuf **out, const struct strbuf *line)
157 *out = xmalloc(sizeof(struct strbuf));
158 strbuf_init(*out, line->len);
162 strbuf_addbuf(*out, line);
165 /* NOTE NOTE NOTE. We do not claim we do full MIME. We just attempt
166 * to have enough heuristics to grok MIME encoded patches often found
167 * on our mailing lists. For example, we do not even treat header lines
168 * case insensitively.
171 static int slurp_attr(const char *line, const char *name, struct strbuf *attr)
173 const char *ends, *ap = strcasestr(line, name);
176 strbuf_setlen(attr, 0);
186 sz = strcspn(ap, ends);
187 strbuf_add(attr, ap, sz);
191 static struct strbuf *content[MAX_BOUNDARIES];
193 static struct strbuf **content_top = content;
195 static void handle_content_type(struct mailinfo *mi, struct strbuf *line)
197 struct strbuf *boundary = xmalloc(sizeof(struct strbuf));
198 strbuf_init(boundary, line->len);
200 if (slurp_attr(line->buf, "boundary=", boundary)) {
201 strbuf_insert(boundary, 0, "--", 2);
202 if (++content_top >= &content[MAX_BOUNDARIES]) {
203 fprintf(stderr, "Too many boundaries to handle\n");
206 *content_top = boundary;
209 slurp_attr(line->buf, "charset=", &mi->charset);
212 strbuf_release(boundary);
217 static void handle_message_id(struct mailinfo *mi, const struct strbuf *line)
219 if (mi->add_message_id)
220 mi->message_id = strdup(line->buf);
223 static void handle_content_transfer_encoding(struct mailinfo *mi,
224 const struct strbuf *line)
226 if (strcasestr(line->buf, "base64"))
227 mi->transfer_encoding = TE_BASE64;
228 else if (strcasestr(line->buf, "quoted-printable"))
229 mi->transfer_encoding = TE_QP;
231 mi->transfer_encoding = TE_DONTCARE;
234 static int is_multipart_boundary(const struct strbuf *line)
236 return (((*content_top)->len <= line->len) &&
237 !memcmp(line->buf, (*content_top)->buf, (*content_top)->len));
240 static void cleanup_subject(struct mailinfo *mi, struct strbuf *subject)
244 while (at < subject->len) {
248 switch (subject->buf[at]) {
250 if (subject->len <= at + 3)
252 if ((subject->buf[at + 1] == 'e' ||
253 subject->buf[at + 1] == 'E') &&
254 subject->buf[at + 2] == ':') {
255 strbuf_remove(subject, at, 3);
260 case ' ': case '\t': case ':':
261 strbuf_remove(subject, at, 1);
264 pos = strchr(subject->buf + at, ']');
267 remove = pos - subject->buf + at + 1;
268 if (!mi->keep_non_patch_brackets_in_subject ||
270 memmem(subject->buf + at, remove, "PATCH", 5)))
271 strbuf_remove(subject, at, remove);
275 * If the input had a space after the ], keep
276 * it. We don't bother with finding the end of
277 * the space, since we later normalize it
280 if (isspace(subject->buf[at]))
287 strbuf_trim(subject);
290 #define MAX_HDR_PARSED 10
291 static const char *header[MAX_HDR_PARSED] = {
292 "From","Subject","Date",
295 static inline int cmp_header(const struct strbuf *line, const char *hdr)
297 int len = strlen(hdr);
298 return !strncasecmp(line->buf, hdr, len) && line->len > len &&
299 line->buf[len] == ':' && isspace(line->buf[len + 1]);
302 static int is_format_patch_separator(const char *line, int len)
304 static const char SAMPLE[] =
305 "From e6807f3efca28b30decfecb1732a56c7db1137ee Mon Sep 17 00:00:00 2001\n";
308 if (len != strlen(SAMPLE))
310 if (!skip_prefix(line, "From ", &cp))
312 if (strspn(cp, "0123456789abcdef") != 40)
315 return !memcmp(SAMPLE + (cp - line), cp, strlen(SAMPLE) - (cp - line));
318 static struct strbuf *decode_q_segment(const struct strbuf *q_seg, int rfc2047)
320 const char *in = q_seg->buf;
322 struct strbuf *out = xmalloc(sizeof(struct strbuf));
323 strbuf_init(out, q_seg->len);
325 while ((c = *in++) != 0) {
329 break; /* drop trailing newline */
330 strbuf_addch(out, (hexval(d) << 4) | hexval(*in++));
333 if (rfc2047 && c == '_') /* rfc2047 4.2 (2) */
335 strbuf_addch(out, c);
340 static struct strbuf *decode_b_segment(const struct strbuf *b_seg)
342 /* Decode in..ep, possibly in-place to ot */
343 int c, pos = 0, acc = 0;
344 const char *in = b_seg->buf;
345 struct strbuf *out = xmalloc(sizeof(struct strbuf));
346 strbuf_init(out, b_seg->len);
348 while ((c = *in++) != 0) {
353 else if ('A' <= c && c <= 'Z')
355 else if ('a' <= c && c <= 'z')
357 else if ('0' <= c && c <= '9')
360 continue; /* garbage */
366 strbuf_addch(out, (acc | (c >> 4)));
370 strbuf_addch(out, (acc | (c >> 2)));
374 strbuf_addch(out, (acc | c));
382 static void convert_to_utf8(struct mailinfo *mi,
383 struct strbuf *line, const char *charset)
387 if (!mi->metainfo_charset || !charset || !*charset)
390 if (same_encoding(mi->metainfo_charset, charset))
392 out = reencode_string(line->buf, mi->metainfo_charset, charset);
394 die("cannot convert from %s to %s",
395 charset, mi->metainfo_charset);
396 strbuf_attach(line, out, strlen(out), strlen(out));
399 static void decode_header(struct mailinfo *mi, struct strbuf *it)
402 struct strbuf outbuf = STRBUF_INIT, *dec;
403 struct strbuf charset_q = STRBUF_INIT, piecebuf = STRBUF_INIT;
406 while (in - it->buf <= it->len && (ep = strstr(in, "=?")) != NULL) {
408 strbuf_reset(&charset_q);
409 strbuf_reset(&piecebuf);
413 * We are about to process an encoded-word
414 * that begins at ep, but there is something
415 * before the encoded word.
418 for (scan = in; scan < ep; scan++)
422 if (scan != ep || in == it->buf) {
424 * We should not lose that "something",
425 * unless we have just processed an
426 * encoded-word, and there is only LWS
427 * before the one we are about to process.
429 strbuf_add(&outbuf, in, ep - in);
433 * ep : "=?iso-2022-jp?B?GyR...?= foo"
434 * ep : "=?ISO-8859-1?Q?Foo=FCbar?= baz"
438 if (ep - it->buf >= it->len || !(cp = strchr(ep, '?')))
441 if (cp + 3 - it->buf > it->len)
443 strbuf_add(&charset_q, ep, cp - ep);
446 if (!encoding || cp[2] != '?')
448 ep = strstr(cp + 3, "?=");
451 strbuf_add(&piecebuf, cp + 3, ep - cp - 3);
452 switch (tolower(encoding)) {
456 dec = decode_b_segment(&piecebuf);
459 dec = decode_q_segment(&piecebuf, 1);
462 convert_to_utf8(mi, dec, charset_q.buf);
464 strbuf_addbuf(&outbuf, dec);
469 strbuf_addstr(&outbuf, in);
471 strbuf_addbuf(it, &outbuf);
473 strbuf_release(&outbuf);
474 strbuf_release(&charset_q);
475 strbuf_release(&piecebuf);
478 static int check_header(struct mailinfo *mi,
479 const struct strbuf *line,
480 struct strbuf *hdr_data[], int overwrite)
483 struct strbuf sb = STRBUF_INIT;
485 /* search for the interesting parts */
486 for (i = 0; header[i]; i++) {
487 int len = strlen(header[i]);
488 if ((!hdr_data[i] || overwrite) && cmp_header(line, header[i])) {
489 /* Unwrap inline B and Q encoding, and optionally
490 * normalize the meta information to utf8.
492 strbuf_add(&sb, line->buf + len + 2, line->len - len - 2);
493 decode_header(mi, &sb);
494 handle_header(&hdr_data[i], &sb);
496 goto check_header_out;
501 if (cmp_header(line, "Content-Type")) {
502 len = strlen("Content-Type: ");
503 strbuf_add(&sb, line->buf + len, line->len - len);
504 decode_header(mi, &sb);
505 strbuf_insert(&sb, 0, "Content-Type: ", len);
506 handle_content_type(mi, &sb);
508 goto check_header_out;
510 if (cmp_header(line, "Content-Transfer-Encoding")) {
511 len = strlen("Content-Transfer-Encoding: ");
512 strbuf_add(&sb, line->buf + len, line->len - len);
513 decode_header(mi, &sb);
514 handle_content_transfer_encoding(mi, &sb);
516 goto check_header_out;
518 if (cmp_header(line, "Message-Id")) {
519 len = strlen("Message-Id: ");
520 strbuf_add(&sb, line->buf + len, line->len - len);
521 decode_header(mi, &sb);
522 handle_message_id(mi, &sb);
524 goto check_header_out;
527 /* for inbody stuff */
528 if (starts_with(line->buf, ">From") && isspace(line->buf[5])) {
529 ret = is_format_patch_separator(line->buf + 1, line->len - 1);
530 goto check_header_out;
532 if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) {
533 for (i = 0; header[i]; i++) {
534 if (!strcmp("Subject", header[i])) {
535 handle_header(&hdr_data[i], line);
537 goto check_header_out;
547 static void decode_transfer_encoding(struct mailinfo *mi, struct strbuf *line)
551 switch (mi->transfer_encoding) {
553 ret = decode_q_segment(line, 0);
556 ret = decode_b_segment(line);
563 strbuf_addbuf(line, ret);
568 static inline int patchbreak(const struct strbuf *line)
572 /* Beginning of a "diff -" header? */
573 if (starts_with(line->buf, "diff -"))
576 /* CVS "Index: " line? */
577 if (starts_with(line->buf, "Index: "))
581 * "--- <filename>" starts patches without headers
582 * "---<sp>*" is a manual separator
587 if (starts_with(line->buf, "---")) {
588 /* space followed by a filename? */
589 if (line->buf[3] == ' ' && !isspace(line->buf[4]))
591 /* Just whitespace? */
592 for (i = 3; i < line->len; i++) {
593 unsigned char c = line->buf[i];
604 static int is_scissors_line(const struct strbuf *line)
606 size_t i, len = line->len;
607 int scissors = 0, gap = 0;
608 int first_nonblank = -1;
609 int last_nonblank = 0, visible, perforation = 0, in_perforation = 0;
610 const char *buf = line->buf;
612 for (i = 0; i < len; i++) {
613 if (isspace(buf[i])) {
614 if (in_perforation) {
621 if (first_nonblank < 0)
629 (!memcmp(buf + i, ">8", 2) || !memcmp(buf + i, "8<", 2) ||
630 !memcmp(buf + i, ">%", 2) || !memcmp(buf + i, "%<", 2))) {
641 * The mark must be at least 8 bytes long (e.g. "-- >8 --").
642 * Even though there can be arbitrary cruft on the same line
643 * (e.g. "cut here"), in order to avoid misidentification, the
644 * perforation must occupy more than a third of the visible
645 * width of the line, and dashes and scissors must occupy more
646 * than half of the perforation.
649 visible = last_nonblank - first_nonblank + 1;
650 return (scissors && 8 <= visible &&
651 visible < perforation * 3 &&
652 gap * 2 < perforation);
655 static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
660 if (mi->header_stage) {
661 if (!line->len || (line->len == 1 && line->buf[0] == '\n'))
665 if (mi->use_inbody_headers && mi->header_stage) {
666 mi->header_stage = check_header(mi, line, mi->s_hdr_data, 0);
667 if (mi->header_stage)
670 /* Only trim the first (blank) line of the commit message
671 * when ignoring in-body headers.
673 mi->header_stage = 0;
675 /* normalize the log message to UTF-8. */
676 convert_to_utf8(mi, line, mi->charset.buf);
678 if (mi->use_scissors && is_scissors_line(line)) {
680 if (fseek(mi->cmitmsg, 0L, SEEK_SET))
681 die_errno("Could not rewind output message file");
682 if (ftruncate(fileno(mi->cmitmsg), 0))
683 die_errno("Could not truncate output message file at scissors");
684 mi->header_stage = 1;
687 * We may have already read "secondary headers"; purge
688 * them to give ourselves a clean restart.
690 for (i = 0; header[i]; i++) {
691 if (mi->s_hdr_data[i])
692 strbuf_release(mi->s_hdr_data[i]);
693 mi->s_hdr_data[i] = NULL;
698 if (patchbreak(line)) {
700 fprintf(mi->cmitmsg, "Message-Id: %s\n", mi->message_id);
706 fputs(line->buf, mi->cmitmsg);
710 static void handle_patch(struct mailinfo *mi, const struct strbuf *line)
712 fwrite(line->buf, 1, line->len, mi->patchfile);
716 static void handle_filter(struct mailinfo *mi, struct strbuf *line)
718 switch (mi->filter_stage) {
720 if (!handle_commit_msg(mi, line))
724 handle_patch(mi, line);
729 static int is_rfc2822_header(const struct strbuf *line)
732 * The section that defines the loosest possible
733 * field name is "3.6.8 Optional fields".
735 * optional-field = field-name ":" unstructured CRLF
736 * field-name = 1*ftext
737 * ftext = %d33-57 / %59-126
740 char *cp = line->buf;
742 /* Count mbox From headers as headers */
743 if (starts_with(cp, "From ") || starts_with(cp, ">From "))
746 while ((ch = *cp++)) {
749 if ((33 <= ch && ch <= 57) ||
750 (59 <= ch && ch <= 126))
757 static int read_one_header_line(struct strbuf *line, FILE *in)
759 struct strbuf continuation = STRBUF_INIT;
761 /* Get the first part of the line. */
762 if (strbuf_getline(line, in, '\n'))
766 * Is it an empty line or not a valid rfc2822 header?
767 * If so, stop here, and return false ("not a header")
770 if (!line->len || !is_rfc2822_header(line)) {
771 /* Re-add the newline */
772 strbuf_addch(line, '\n');
777 * Now we need to eat all the continuation lines..
778 * Yuck, 2822 header "folding"
783 peek = fgetc(in); ungetc(peek, in);
784 if (peek != ' ' && peek != '\t')
786 if (strbuf_getline(&continuation, in, '\n'))
788 continuation.buf[0] = ' ';
789 strbuf_rtrim(&continuation);
790 strbuf_addbuf(line, &continuation);
792 strbuf_release(&continuation);
797 static int find_boundary(struct mailinfo *mi, struct strbuf *line)
799 while (!strbuf_getline(line, mi->input, '\n')) {
800 if (*content_top && is_multipart_boundary(line))
806 static int handle_boundary(struct mailinfo *mi, struct strbuf *line)
808 struct strbuf newline = STRBUF_INIT;
810 strbuf_addch(&newline, '\n');
812 if (line->len >= (*content_top)->len + 2 &&
813 !memcmp(line->buf + (*content_top)->len, "--", 2)) {
814 /* we hit an end boundary */
815 /* pop the current boundary off the stack */
816 strbuf_release(*content_top);
820 /* technically won't happen as is_multipart_boundary()
821 will fail first. But just in case..
823 if (--content_top < content) {
824 fprintf(stderr, "Detected mismatched boundaries, "
828 handle_filter(mi, &newline);
829 strbuf_release(&newline);
831 /* skip to the next boundary */
832 if (!find_boundary(mi, line))
837 /* set some defaults */
838 mi->transfer_encoding = TE_DONTCARE;
839 strbuf_reset(&mi->charset);
841 /* slurp in this section's info */
842 while (read_one_header_line(line, mi->input))
843 check_header(mi, line, mi->p_hdr_data, 0);
845 strbuf_release(&newline);
847 if (strbuf_getline(line, mi->input, '\n'))
849 strbuf_addch(line, '\n');
853 static void handle_body(struct mailinfo *mi, struct strbuf *line)
855 struct strbuf prev = STRBUF_INIT;
857 /* Skip up to the first boundary */
859 if (!find_boundary(mi, line))
860 goto handle_body_out;
864 /* process any boundary lines */
865 if (*content_top && is_multipart_boundary(line)) {
866 /* flush any leftover */
868 handle_filter(mi, &prev);
871 if (!handle_boundary(mi, line))
872 goto handle_body_out;
875 /* Unwrap transfer encoding */
876 decode_transfer_encoding(mi, line);
878 switch (mi->transfer_encoding) {
882 struct strbuf **lines, **it, *sb;
884 /* Prepend any previous partial lines */
885 strbuf_insert(line, 0, prev.buf, prev.len);
889 * This is a decoded line that may contain
890 * multiple new lines. Pass only one chunk
891 * at a time to handle_filter()
893 lines = strbuf_split(line, '\n');
894 for (it = lines; (sb = *it); it++) {
895 if (*(it + 1) == NULL) /* The last line */
896 if (sb->buf[sb->len - 1] != '\n') {
897 /* Partial line, save it for later. */
898 strbuf_addbuf(&prev, sb);
901 handle_filter(mi, sb);
904 * The partial chunk is saved in "prev" and will be
905 * appended by the next iteration of read_line_with_nul().
907 strbuf_list_free(lines);
911 handle_filter(mi, line);
914 } while (!strbuf_getwholeline(line, mi->input, '\n'));
917 strbuf_release(&prev);
920 static void output_header_lines(FILE *fout, const char *hdr, const struct strbuf *data)
922 const char *sp = data->buf;
924 char *ep = strchr(sp, '\n');
930 fprintf(fout, "%s: %.*s\n", hdr, len, sp);
937 static void handle_info(struct mailinfo *mi)
942 for (i = 0; header[i]; i++) {
943 /* only print inbody headers if we output a patch file */
944 if (mi->patch_lines && mi->s_hdr_data[i])
945 hdr = mi->s_hdr_data[i];
946 else if (mi->p_hdr_data[i])
947 hdr = mi->p_hdr_data[i];
951 if (!strcmp(header[i], "Subject")) {
952 if (!mi->keep_subject) {
953 cleanup_subject(mi, hdr);
956 output_header_lines(mi->output, "Subject", hdr);
957 } else if (!strcmp(header[i], "From")) {
959 handle_from(mi, hdr);
960 fprintf(mi->output, "Author: %s\n", mi->name.buf);
961 fprintf(mi->output, "Email: %s\n", mi->email.buf);
964 fprintf(mi->output, "%s: %s\n", header[i], hdr->buf);
967 fprintf(mi->output, "\n");
970 static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
973 struct strbuf line = STRBUF_INIT;
975 mi->cmitmsg = fopen(msg, "w");
980 mi->patchfile = fopen(patch, "w");
981 if (!mi->patchfile) {
987 mi->p_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*(mi->p_hdr_data)));
988 mi->s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*(mi->s_hdr_data)));
991 peek = fgetc(mi->input);
992 } while (isspace(peek));
993 ungetc(peek, mi->input);
995 /* process the email header */
996 while (read_one_header_line(&line, mi->input))
997 check_header(mi, &line, mi->p_hdr_data, 1);
999 handle_body(mi, &line);
1000 fclose(mi->patchfile);
1003 strbuf_release(&line);
1007 static int git_mailinfo_config(const char *var, const char *value, void *mi_)
1009 struct mailinfo *mi = mi_;
1011 if (!starts_with(var, "mailinfo."))
1012 return git_default_config(var, value, NULL);
1013 if (!strcmp(var, "mailinfo.scissors")) {
1014 mi->use_scissors = git_config_bool(var, value);
1017 /* perhaps others here */
1021 static void setup_mailinfo(struct mailinfo *mi)
1023 memset(mi, 0, sizeof(*mi));
1024 strbuf_init(&mi->name, 0);
1025 strbuf_init(&mi->email, 0);
1026 strbuf_init(&mi->charset, 0);
1027 mi->header_stage = 1;
1028 mi->use_inbody_headers = 1;
1029 git_config(git_mailinfo_config, &mi);
1032 static void clear_mailinfo(struct mailinfo *mi)
1036 strbuf_release(&mi->name);
1037 strbuf_release(&mi->email);
1038 strbuf_release(&mi->charset);
1039 free(mi->message_id);
1041 for (i = 0; mi->p_hdr_data[i]; i++)
1042 strbuf_release(mi->p_hdr_data[i]);
1043 free(mi->p_hdr_data);
1044 for (i = 0; mi->s_hdr_data[i]; i++)
1045 strbuf_release(mi->s_hdr_data[i]);
1046 free(mi->s_hdr_data);
1049 static const char mailinfo_usage[] =
1050 "git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] <msg> <patch> < mail >info";
1052 int cmd_mailinfo(int argc, const char **argv, const char *prefix)
1054 const char *def_charset;
1058 /* NEEDSWORK: might want to do the optional .git/ directory
1061 setup_mailinfo(&mi);
1063 def_charset = get_commit_output_encoding();
1064 mi.metainfo_charset = def_charset;
1066 while (1 < argc && argv[1][0] == '-') {
1067 if (!strcmp(argv[1], "-k"))
1068 mi.keep_subject = 1;
1069 else if (!strcmp(argv[1], "-b"))
1070 mi.keep_non_patch_brackets_in_subject = 1;
1071 else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id"))
1072 mi.add_message_id = 1;
1073 else if (!strcmp(argv[1], "-u"))
1074 mi.metainfo_charset = def_charset;
1075 else if (!strcmp(argv[1], "-n"))
1076 mi.metainfo_charset = NULL;
1077 else if (starts_with(argv[1], "--encoding="))
1078 mi.metainfo_charset = argv[1] + 11;
1079 else if (!strcmp(argv[1], "--scissors"))
1080 mi.use_scissors = 1;
1081 else if (!strcmp(argv[1], "--no-scissors"))
1082 mi.use_scissors = 0;
1083 else if (!strcmp(argv[1], "--no-inbody-headers"))
1084 mi.use_inbody_headers = 0;
1086 usage(mailinfo_usage);
1091 usage(mailinfo_usage);
1095 status = !!mailinfo(&mi, argv[1], argv[2]);
1096 clear_mailinfo(&mi);