Merge branch 'jc/rerere'
[git/jnareb-git.git] / builtin-mailinfo.c
blobfa6e8f90a4d54eb07f2af80620e35e617c94d605
1 /*
2 * Another stupid program, this one parsing the headers of an
3 * email to figure out authorship and subject
4 */
5 #include "cache.h"
6 #include "builtin.h"
7 #include "utf8.h"
9 static FILE *cmitmsg, *patchfile, *fin, *fout;
11 static int keep_subject;
12 static const char *metainfo_charset;
13 static char line[1000];
14 static char name[1000];
15 static char email[1000];
17 static enum {
18 TE_DONTCARE, TE_QP, TE_BASE64,
19 } transfer_encoding;
20 static enum {
21 TYPE_TEXT, TYPE_OTHER,
22 } message_type;
24 static char charset[256];
25 static int patch_lines;
26 static char **p_hdr_data, **s_hdr_data;
28 #define MAX_HDR_PARSED 10
29 #define MAX_BOUNDARIES 5
31 static char *sanity_check(char *name, char *email)
33 int len = strlen(name);
34 if (len < 3 || len > 60)
35 return email;
36 if (strchr(name, '@') || strchr(name, '<') || strchr(name, '>'))
37 return email;
38 return name;
41 static int bogus_from(char *line)
43 /* John Doe <johndoe> */
44 char *bra, *ket, *dst, *cp;
46 /* This is fallback, so do not bother if we already have an
47 * e-mail address.
49 if (*email)
50 return 0;
52 bra = strchr(line, '<');
53 if (!bra)
54 return 0;
55 ket = strchr(bra, '>');
56 if (!ket)
57 return 0;
59 for (dst = email, cp = bra+1; cp < ket; )
60 *dst++ = *cp++;
61 *dst = 0;
62 for (cp = line; isspace(*cp); cp++)
64 for (bra--; isspace(*bra); bra--)
65 *bra = 0;
66 cp = sanity_check(cp, email);
67 strcpy(name, cp);
68 return 1;
71 static int handle_from(char *in_line)
73 char line[1000];
74 char *at;
75 char *dst;
77 strcpy(line, in_line);
78 at = strchr(line, '@');
79 if (!at)
80 return bogus_from(line);
83 * If we already have one email, don't take any confusing lines
85 if (*email && strchr(at+1, '@'))
86 return 0;
88 /* Pick up the string around '@', possibly delimited with <>
89 * pair; that is the email part. White them out while copying.
91 while (at > line) {
92 char c = at[-1];
93 if (isspace(c))
94 break;
95 if (c == '<') {
96 at[-1] = ' ';
97 break;
99 at--;
101 dst = email;
102 for (;;) {
103 unsigned char c = *at;
104 if (!c || c == '>' || isspace(c)) {
105 if (c == '>')
106 *at = ' ';
107 break;
109 *at++ = ' ';
110 *dst++ = c;
112 *dst++ = 0;
114 /* The remainder is name. It could be "John Doe <john.doe@xz>"
115 * or "john.doe@xz (John Doe)", but we have whited out the
116 * email part, so trim from both ends, possibly removing
117 * the () pair at the end.
119 at = line + strlen(line);
120 while (at > line) {
121 unsigned char c = *--at;
122 if (!isspace(c)) {
123 at[(c == ')') ? 0 : 1] = 0;
124 break;
128 at = line;
129 for (;;) {
130 unsigned char c = *at;
131 if (!c || !isspace(c)) {
132 if (c == '(')
133 at++;
134 break;
136 at++;
138 at = sanity_check(at, email);
139 strcpy(name, at);
140 return 1;
143 static int handle_header(char *line, char *data, int ofs)
145 if (!line || !data)
146 return 1;
148 strcpy(data, line+ofs);
150 return 0;
153 /* NOTE NOTE NOTE. We do not claim we do full MIME. We just attempt
154 * to have enough heuristics to grok MIME encoded patches often found
155 * on our mailing lists. For example, we do not even treat header lines
156 * case insensitively.
159 static int slurp_attr(const char *line, const char *name, char *attr)
161 const char *ends, *ap = strcasestr(line, name);
162 size_t sz;
164 if (!ap) {
165 *attr = 0;
166 return 0;
168 ap += strlen(name);
169 if (*ap == '"') {
170 ap++;
171 ends = "\"";
173 else
174 ends = "; \t";
175 sz = strcspn(ap, ends);
176 memcpy(attr, ap, sz);
177 attr[sz] = 0;
178 return 1;
181 struct content_type {
182 char *boundary;
183 int boundary_len;
186 static struct content_type content[MAX_BOUNDARIES];
188 static struct content_type *content_top = content;
190 static int handle_content_type(char *line)
192 char boundary[256];
194 if (strcasestr(line, "text/") == NULL)
195 message_type = TYPE_OTHER;
196 if (slurp_attr(line, "boundary=", boundary + 2)) {
197 memcpy(boundary, "--", 2);
198 if (content_top++ >= &content[MAX_BOUNDARIES]) {
199 fprintf(stderr, "Too many boundaries to handle\n");
200 exit(1);
202 content_top->boundary_len = strlen(boundary);
203 content_top->boundary = xmalloc(content_top->boundary_len+1);
204 strcpy(content_top->boundary, boundary);
206 if (slurp_attr(line, "charset=", charset)) {
207 int i, c;
208 for (i = 0; (c = charset[i]) != 0; i++)
209 charset[i] = tolower(c);
211 return 0;
214 static int handle_content_transfer_encoding(char *line)
216 if (strcasestr(line, "base64"))
217 transfer_encoding = TE_BASE64;
218 else if (strcasestr(line, "quoted-printable"))
219 transfer_encoding = TE_QP;
220 else
221 transfer_encoding = TE_DONTCARE;
222 return 0;
225 static int is_multipart_boundary(const char *line)
227 return (!memcmp(line, content_top->boundary, content_top->boundary_len));
230 static int eatspace(char *line)
232 int len = strlen(line);
233 while (len > 0 && isspace(line[len-1]))
234 line[--len] = 0;
235 return len;
238 static char *cleanup_subject(char *subject)
240 for (;;) {
241 char *p;
242 int len, remove;
243 switch (*subject) {
244 case 'r': case 'R':
245 if (!memcmp("e:", subject+1, 2)) {
246 subject += 3;
247 continue;
249 break;
250 case ' ': case '\t': case ':':
251 subject++;
252 continue;
254 case '[':
255 p = strchr(subject, ']');
256 if (!p) {
257 subject++;
258 continue;
260 len = strlen(p);
261 remove = p - subject;
262 if (remove <= len *2) {
263 subject = p+1;
264 continue;
266 break;
268 eatspace(subject);
269 return subject;
273 static void cleanup_space(char *buf)
275 unsigned char c;
276 while ((c = *buf) != 0) {
277 buf++;
278 if (isspace(c)) {
279 buf[-1] = ' ';
280 c = *buf;
281 while (isspace(c)) {
282 int len = strlen(buf);
283 memmove(buf, buf+1, len);
284 c = *buf;
290 static void decode_header(char *it, unsigned itsize);
291 static const char *header[MAX_HDR_PARSED] = {
292 "From","Subject","Date",
295 static int check_header(char *line, unsigned linesize, char **hdr_data, int overwrite)
297 int i;
299 /* search for the interesting parts */
300 for (i = 0; header[i]; i++) {
301 int len = strlen(header[i]);
302 if ((!hdr_data[i] || overwrite) &&
303 !strncasecmp(line, header[i], len) &&
304 line[len] == ':' && isspace(line[len + 1])) {
305 /* Unwrap inline B and Q encoding, and optionally
306 * normalize the meta information to utf8.
308 decode_header(line + len + 2, linesize - len - 2);
309 hdr_data[i] = xmalloc(1000 * sizeof(char));
310 if (! handle_header(line, hdr_data[i], len + 2)) {
311 return 1;
316 /* Content stuff */
317 if (!strncasecmp(line, "Content-Type", 12) &&
318 line[12] == ':' && isspace(line[12 + 1])) {
319 decode_header(line + 12 + 2, linesize - 12 - 2);
320 if (! handle_content_type(line)) {
321 return 1;
324 if (!strncasecmp(line, "Content-Transfer-Encoding", 25) &&
325 line[25] == ':' && isspace(line[25 + 1])) {
326 decode_header(line + 25 + 2, linesize - 25 - 2);
327 if (! handle_content_transfer_encoding(line)) {
328 return 1;
332 /* for inbody stuff */
333 if (!memcmp(">From", line, 5) && isspace(line[5]))
334 return 1;
335 if (!memcmp("[PATCH]", line, 7) && isspace(line[7])) {
336 for (i = 0; header[i]; i++) {
337 if (!memcmp("Subject: ", header[i], 9)) {
338 if (! handle_header(line, hdr_data[i], 0)) {
339 return 1;
345 /* no match */
346 return 0;
349 static int is_rfc2822_header(char *line)
352 * The section that defines the loosest possible
353 * field name is "3.6.8 Optional fields".
355 * optional-field = field-name ":" unstructured CRLF
356 * field-name = 1*ftext
357 * ftext = %d33-57 / %59-126
359 int ch;
360 char *cp = line;
362 /* Count mbox From headers as headers */
363 if (!memcmp(line, "From ", 5) || !memcmp(line, ">From ", 6))
364 return 1;
366 while ((ch = *cp++)) {
367 if (ch == ':')
368 return cp != line;
369 if ((33 <= ch && ch <= 57) ||
370 (59 <= ch && ch <= 126))
371 continue;
372 break;
374 return 0;
378 * sz is size of 'line' buffer in bytes. Must be reasonably
379 * long enough to hold one physical real-world e-mail line.
381 static int read_one_header_line(char *line, int sz, FILE *in)
383 int len;
386 * We will read at most (sz-1) bytes and then potentially
387 * re-add NUL after it. Accessing line[sz] after this is safe
388 * and we can allow len to grow up to and including sz.
390 sz--;
392 /* Get the first part of the line. */
393 if (!fgets(line, sz, in))
394 return 0;
397 * Is it an empty line or not a valid rfc2822 header?
398 * If so, stop here, and return false ("not a header")
400 len = eatspace(line);
401 if (!len || !is_rfc2822_header(line)) {
402 /* Re-add the newline */
403 line[len] = '\n';
404 line[len + 1] = '\0';
405 return 0;
409 * Now we need to eat all the continuation lines..
410 * Yuck, 2822 header "folding"
412 for (;;) {
413 int peek, addlen;
414 static char continuation[1000];
416 peek = fgetc(in); ungetc(peek, in);
417 if (peek != ' ' && peek != '\t')
418 break;
419 if (!fgets(continuation, sizeof(continuation), in))
420 break;
421 addlen = eatspace(continuation);
422 if (len < sz - 1) {
423 if (addlen >= sz - len)
424 addlen = sz - len - 1;
425 memcpy(line + len, continuation, addlen);
426 line[len] = '\n';
427 len += addlen;
430 line[len] = 0;
432 return 1;
435 static int decode_q_segment(char *in, char *ot, unsigned otsize, char *ep, int rfc2047)
437 char *otbegin = ot;
438 char *otend = ot + otsize;
439 int c;
440 while ((c = *in++) != 0 && (in <= ep)) {
441 if (ot == otend) {
442 *--ot = '\0';
443 return -1;
445 if (c == '=') {
446 int d = *in++;
447 if (d == '\n' || !d)
448 break; /* drop trailing newline */
449 *ot++ = ((hexval(d) << 4) | hexval(*in++));
450 continue;
452 if (rfc2047 && c == '_') /* rfc2047 4.2 (2) */
453 c = 0x20;
454 *ot++ = c;
456 *ot = 0;
457 return (ot - otbegin);
460 static int decode_b_segment(char *in, char *ot, unsigned otsize, char *ep)
462 /* Decode in..ep, possibly in-place to ot */
463 int c, pos = 0, acc = 0;
464 char *otbegin = ot;
465 char *otend = ot + otsize;
467 while ((c = *in++) != 0 && (in <= ep)) {
468 if (ot == otend) {
469 *--ot = '\0';
470 return -1;
472 if (c == '+')
473 c = 62;
474 else if (c == '/')
475 c = 63;
476 else if ('A' <= c && c <= 'Z')
477 c -= 'A';
478 else if ('a' <= c && c <= 'z')
479 c -= 'a' - 26;
480 else if ('0' <= c && c <= '9')
481 c -= '0' - 52;
482 else if (c == '=') {
483 /* padding is almost like (c == 0), except we do
484 * not output NUL resulting only from it;
485 * for now we just trust the data.
487 c = 0;
489 else
490 continue; /* garbage */
491 switch (pos++) {
492 case 0:
493 acc = (c << 2);
494 break;
495 case 1:
496 *ot++ = (acc | (c >> 4));
497 acc = (c & 15) << 4;
498 break;
499 case 2:
500 *ot++ = (acc | (c >> 2));
501 acc = (c & 3) << 6;
502 break;
503 case 3:
504 *ot++ = (acc | c);
505 acc = pos = 0;
506 break;
509 *ot = 0;
510 return (ot - otbegin);
514 * When there is no known charset, guess.
516 * Right now we assume that if the target is UTF-8 (the default),
517 * and it already looks like UTF-8 (which includes US-ASCII as its
518 * subset, of course) then that is what it is and there is nothing
519 * to do.
521 * Otherwise, we default to assuming it is Latin1 for historical
522 * reasons.
524 static const char *guess_charset(const char *line, const char *target_charset)
526 if (is_encoding_utf8(target_charset)) {
527 if (is_utf8(line))
528 return NULL;
530 return "latin1";
533 static void convert_to_utf8(char *line, unsigned linesize, const char *charset)
535 char *out;
537 if (!charset || !*charset) {
538 charset = guess_charset(line, metainfo_charset);
539 if (!charset)
540 return;
543 if (!strcmp(metainfo_charset, charset))
544 return;
545 out = reencode_string(line, metainfo_charset, charset);
546 if (!out)
547 die("cannot convert from %s to %s\n",
548 charset, metainfo_charset);
549 strlcpy(line, out, linesize);
550 free(out);
553 static int decode_header_bq(char *it, unsigned itsize)
555 char *in, *out, *ep, *cp, *sp;
556 char outbuf[1000];
557 int rfc2047 = 0;
559 in = it;
560 out = outbuf;
561 while ((ep = strstr(in, "=?")) != NULL) {
562 int sz, encoding;
563 char charset_q[256], piecebuf[256];
564 rfc2047 = 1;
566 if (in != ep) {
567 sz = ep - in;
568 memcpy(out, in, sz);
569 out += sz;
570 in += sz;
572 /* E.g.
573 * ep : "=?iso-2022-jp?B?GyR...?= foo"
574 * ep : "=?ISO-8859-1?Q?Foo=FCbar?= baz"
576 ep += 2;
577 cp = strchr(ep, '?');
578 if (!cp)
579 return rfc2047; /* no munging */
580 for (sp = ep; sp < cp; sp++)
581 charset_q[sp - ep] = tolower(*sp);
582 charset_q[cp - ep] = 0;
583 encoding = cp[1];
584 if (!encoding || cp[2] != '?')
585 return rfc2047; /* no munging */
586 ep = strstr(cp + 3, "?=");
587 if (!ep)
588 return rfc2047; /* no munging */
589 switch (tolower(encoding)) {
590 default:
591 return rfc2047; /* no munging */
592 case 'b':
593 sz = decode_b_segment(cp + 3, piecebuf, sizeof(piecebuf), ep);
594 break;
595 case 'q':
596 sz = decode_q_segment(cp + 3, piecebuf, sizeof(piecebuf), ep, 1);
597 break;
599 if (sz < 0)
600 return rfc2047;
601 if (metainfo_charset)
602 convert_to_utf8(piecebuf, sizeof(piecebuf), charset_q);
604 sz = strlen(piecebuf);
605 if (outbuf + sizeof(outbuf) <= out + sz)
606 return rfc2047; /* no munging */
607 strcpy(out, piecebuf);
608 out += sz;
609 in = ep + 2;
611 strcpy(out, in);
612 strlcpy(it, outbuf, itsize);
613 return rfc2047;
616 static void decode_header(char *it, unsigned itsize)
619 if (decode_header_bq(it, itsize))
620 return;
621 /* otherwise "it" is a straight copy of the input.
622 * This can be binary guck but there is no charset specified.
624 if (metainfo_charset)
625 convert_to_utf8(it, itsize, "");
628 static int decode_transfer_encoding(char *line, unsigned linesize, int inputlen)
630 char *ep;
632 switch (transfer_encoding) {
633 case TE_QP:
634 ep = line + inputlen;
635 return decode_q_segment(line, line, linesize, ep, 0);
636 case TE_BASE64:
637 ep = line + inputlen;
638 return decode_b_segment(line, line, linesize, ep);
639 case TE_DONTCARE:
640 default:
641 return inputlen;
645 static int handle_filter(char *line, unsigned linesize, int linelen);
647 static int find_boundary(void)
649 while(fgets(line, sizeof(line), fin) != NULL) {
650 if (is_multipart_boundary(line))
651 return 1;
653 return 0;
656 static int handle_boundary(void)
658 char newline[]="\n";
659 again:
660 if (!memcmp(line+content_top->boundary_len, "--", 2)) {
661 /* we hit an end boundary */
662 /* pop the current boundary off the stack */
663 free(content_top->boundary);
665 /* technically won't happen as is_multipart_boundary()
666 will fail first. But just in case..
668 if (content_top-- < content) {
669 fprintf(stderr, "Detected mismatched boundaries, "
670 "can't recover\n");
671 exit(1);
673 handle_filter(newline, sizeof(newline), strlen(newline));
675 /* skip to the next boundary */
676 if (!find_boundary())
677 return 0;
678 goto again;
681 /* set some defaults */
682 transfer_encoding = TE_DONTCARE;
683 charset[0] = 0;
684 message_type = TYPE_TEXT;
686 /* slurp in this section's info */
687 while (read_one_header_line(line, sizeof(line), fin))
688 check_header(line, sizeof(line), p_hdr_data, 0);
690 /* eat the blank line after section info */
691 return (fgets(line, sizeof(line), fin) != NULL);
694 static inline int patchbreak(const char *line)
696 /* Beginning of a "diff -" header? */
697 if (!memcmp("diff -", line, 6))
698 return 1;
700 /* CVS "Index: " line? */
701 if (!memcmp("Index: ", line, 7))
702 return 1;
705 * "--- <filename>" starts patches without headers
706 * "---<sp>*" is a manual separator
708 if (!memcmp("---", line, 3)) {
709 line += 3;
710 /* space followed by a filename? */
711 if (line[0] == ' ' && !isspace(line[1]))
712 return 1;
713 /* Just whitespace? */
714 for (;;) {
715 unsigned char c = *line++;
716 if (c == '\n')
717 return 1;
718 if (!isspace(c))
719 break;
721 return 0;
723 return 0;
727 static int handle_commit_msg(char *line, unsigned linesize)
729 static int still_looking = 1;
730 char *endline = line + linesize;
732 if (!cmitmsg)
733 return 0;
735 if (still_looking) {
736 char *cp = line;
737 if (isspace(*line)) {
738 for (cp = line + 1; *cp; cp++) {
739 if (!isspace(*cp))
740 break;
742 if (!*cp)
743 return 0;
745 if ((still_looking = check_header(cp, endline - cp, s_hdr_data, 0)) != 0)
746 return 0;
749 /* normalize the log message to UTF-8. */
750 if (metainfo_charset)
751 convert_to_utf8(line, endline - line, charset);
753 if (patchbreak(line)) {
754 fclose(cmitmsg);
755 cmitmsg = NULL;
756 return 1;
759 fputs(line, cmitmsg);
760 return 0;
763 static int handle_patch(char *line, int len)
765 fwrite(line, 1, len, patchfile);
766 patch_lines++;
767 return 0;
770 static int handle_filter(char *line, unsigned linesize, int linelen)
772 static int filter = 0;
774 /* filter tells us which part we left off on
775 * a non-zero return indicates we hit a filter point
777 switch (filter) {
778 case 0:
779 if (!handle_commit_msg(line, linesize))
780 break;
781 filter++;
782 case 1:
783 if (!handle_patch(line, linelen))
784 break;
785 filter++;
786 default:
787 return 1;
790 return 0;
793 static void handle_body(void)
795 int rc = 0;
796 static char newline[2000];
797 static char *np = newline;
798 int len = strlen(line);
800 /* Skip up to the first boundary */
801 if (content_top->boundary) {
802 if (!find_boundary())
803 return;
806 do {
807 /* process any boundary lines */
808 if (content_top->boundary && is_multipart_boundary(line)) {
809 /* flush any leftover */
810 if (np != newline)
811 handle_filter(newline, sizeof(newline),
812 np - newline);
813 if (!handle_boundary())
814 return;
815 len = strlen(line);
818 /* Unwrap transfer encoding */
819 len = decode_transfer_encoding(line, sizeof(line), len);
820 if (len < 0) {
821 error("Malformed input line");
822 return;
825 switch (transfer_encoding) {
826 case TE_BASE64:
827 case TE_QP:
829 char *op = line;
831 /* binary data most likely doesn't have newlines */
832 if (message_type != TYPE_TEXT) {
833 rc = handle_filter(line, sizeof(line), len);
834 break;
838 * This is a decoded line that may contain
839 * multiple new lines. Pass only one chunk
840 * at a time to handle_filter()
842 do {
843 while (op < line + len && *op != '\n')
844 *np++ = *op++;
845 *np = *op;
846 if (*np != 0) {
847 /* should be sitting on a new line */
848 *(++np) = 0;
849 op++;
850 rc = handle_filter(newline, sizeof(newline), np - newline);
851 np = newline;
853 } while (op < line + len);
855 * The partial chunk is saved in newline and will be
856 * appended by the next iteration of read_line_with_nul().
858 break;
860 default:
861 rc = handle_filter(line, sizeof(line), len);
863 if (rc)
864 /* nothing left to filter */
865 break;
866 } while ((len = read_line_with_nul(line, sizeof(line), fin)));
868 return;
871 static void output_header_lines(FILE *fout, const char *hdr, char *data)
873 while (1) {
874 char *ep = strchr(data, '\n');
875 int len;
876 if (!ep)
877 len = strlen(data);
878 else
879 len = ep - data;
880 fprintf(fout, "%s: %.*s\n", hdr, len, data);
881 if (!ep)
882 break;
883 data = ep + 1;
887 static void handle_info(void)
889 char *sub;
890 char *hdr;
891 int i;
893 for (i = 0; header[i]; i++) {
895 /* only print inbody headers if we output a patch file */
896 if (patch_lines && s_hdr_data[i])
897 hdr = s_hdr_data[i];
898 else if (p_hdr_data[i])
899 hdr = p_hdr_data[i];
900 else
901 continue;
903 if (!memcmp(header[i], "Subject", 7)) {
904 if (keep_subject)
905 sub = hdr;
906 else {
907 sub = cleanup_subject(hdr);
908 cleanup_space(sub);
910 output_header_lines(fout, "Subject", sub);
911 } else if (!memcmp(header[i], "From", 4)) {
912 handle_from(hdr);
913 fprintf(fout, "Author: %s\n", name);
914 fprintf(fout, "Email: %s\n", email);
915 } else {
916 cleanup_space(hdr);
917 fprintf(fout, "%s: %s\n", header[i], hdr);
920 fprintf(fout, "\n");
923 static int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,
924 const char *msg, const char *patch)
926 int peek;
927 keep_subject = ks;
928 metainfo_charset = encoding;
929 fin = in;
930 fout = out;
932 cmitmsg = fopen(msg, "w");
933 if (!cmitmsg) {
934 perror(msg);
935 return -1;
937 patchfile = fopen(patch, "w");
938 if (!patchfile) {
939 perror(patch);
940 fclose(cmitmsg);
941 return -1;
944 p_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(char *));
945 s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(char *));
947 do {
948 peek = fgetc(in);
949 } while (isspace(peek));
950 ungetc(peek, in);
952 /* process the email header */
953 while (read_one_header_line(line, sizeof(line), fin))
954 check_header(line, sizeof(line), p_hdr_data, 1);
956 handle_body();
957 handle_info();
959 return 0;
962 static const char mailinfo_usage[] =
963 "git-mailinfo [-k] [-u | --encoding=<encoding>] msg patch <mail >info";
965 int cmd_mailinfo(int argc, const char **argv, const char *prefix)
967 const char *def_charset;
969 /* NEEDSWORK: might want to do the optional .git/ directory
970 * discovery
972 git_config(git_default_config, NULL);
974 def_charset = (git_commit_encoding ? git_commit_encoding : "utf-8");
975 metainfo_charset = def_charset;
977 while (1 < argc && argv[1][0] == '-') {
978 if (!strcmp(argv[1], "-k"))
979 keep_subject = 1;
980 else if (!strcmp(argv[1], "-u"))
981 metainfo_charset = def_charset;
982 else if (!strcmp(argv[1], "-n"))
983 metainfo_charset = NULL;
984 else if (!prefixcmp(argv[1], "--encoding="))
985 metainfo_charset = argv[1] + 11;
986 else
987 usage(mailinfo_usage);
988 argc--; argv++;
991 if (argc != 3)
992 usage(mailinfo_usage);
994 return !!mailinfo(stdin, stdout, keep_subject, metainfo_charset, argv[1], argv[2]);