]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/mailinfo.c
mailinfo: warn if CRLF found in decoded base64/QP email
[thirdparty/git.git] / builtin / mailinfo.c
CommitLineData
2744b234
LT
1/*
2 * Another stupid program, this one parsing the headers of an
3 * email to figure out authorship and subject
4 */
f1f909e3 5#include "cache.h"
34488e3c 6#include "builtin.h"
b45974a6 7#include "utf8.h"
3b6121f6 8#include "strbuf.h"
c6905e45 9#include "mailinfo.h"
dd9323b7 10#include "parse-options.h"
c69f2395 11
dd9323b7
ĐTCD
12static const char * const mailinfo_usage[] = {
13 /* TRANSLATORS: keep <> in "<" mail ">" info. */
14 N_("git mailinfo [<options>] <msg> <patch> < mail >info"),
15 NULL,
16};
d4a9ce78 17
d582992e
ĐTCD
18struct metainfo_charset
19{
20 enum {
21 CHARSET_DEFAULT,
22 CHARSET_NO_REENCODE,
23 CHARSET_EXPLICIT,
24 } policy;
25 const char *charset;
26};
27
dd9323b7
ĐTCD
28static int parse_opt_explicit_encoding(const struct option *opt,
29 const char *arg, int unset)
30{
31 struct metainfo_charset *meta_charset = opt->value;
32
33 BUG_ON_OPT_NEG(unset);
34
35 meta_charset->policy = CHARSET_EXPLICIT;
36 meta_charset->charset = arg;
37
38 return 0;
39}
40
a633fca0 41int cmd_mailinfo(int argc, const char **argv, const char *prefix)
2744b234 42{
d582992e 43 struct metainfo_charset meta_charset;
c69f2395
JH
44 struct mailinfo mi;
45 int status;
3f0ec068 46 char *msgfile, *patchfile;
bb1091a4 47
dd9323b7
ĐTCD
48 struct option options[] = {
49 OPT_BOOL('k', NULL, &mi.keep_subject, N_("keep subject")),
50 OPT_BOOL('b', NULL, &mi.keep_non_patch_brackets_in_subject,
51 N_("keep non patch brackets in subject")),
52 OPT_BOOL('m', "message-id", &mi.add_message_id,
53 N_("copy Message-ID to the end of commit message")),
54 OPT_SET_INT_F('u', NULL, &meta_charset.policy,
55 N_("re-code metadata to i18n.commitEncoding"),
56 CHARSET_DEFAULT, PARSE_OPT_NONEG),
57 OPT_SET_INT_F('n', NULL, &meta_charset.policy,
58 N_("disable charset re-coding of metadata"),
59 CHARSET_NO_REENCODE, PARSE_OPT_NONEG),
60 OPT_CALLBACK_F(0, "encoding", &meta_charset, N_("encoding"),
61 N_("re-code metadata to this encoding"),
62 PARSE_OPT_NONEG, parse_opt_explicit_encoding),
63 OPT_BOOL(0, "scissors", &mi.use_scissors, N_("use scissors")),
64 OPT_HIDDEN_BOOL(0, "inbody-headers", &mi.use_inbody_headers,
65 N_("use headers in message's body")),
66 OPT_END()
67 };
68
c69f2395 69 setup_mailinfo(&mi);
d582992e 70 meta_charset.policy = CHARSET_DEFAULT;
bb1091a4 71
dd9323b7 72 argc = parse_options(argc, argv, prefix, options, mailinfo_usage, 0);
6bff6a60 73
dd9323b7
ĐTCD
74 if (argc != 2)
75 usage_with_options(mailinfo_usage, options);
34488e3c 76
d582992e
ĐTCD
77 switch (meta_charset.policy) {
78 case CHARSET_DEFAULT:
79 mi.metainfo_charset = get_commit_output_encoding();
80 break;
81 case CHARSET_NO_REENCODE:
82 mi.metainfo_charset = NULL;
83 break;
84 case CHARSET_EXPLICIT:
85 break;
86 default:
87 BUG("invalid meta_charset.policy");
88 }
89
173aef7c
JH
90 mi.input = stdin;
91 mi.output = stdout;
3f0ec068 92
dd9323b7
ĐTCD
93 msgfile = prefix_filename(prefix, argv[0]);
94 patchfile = prefix_filename(prefix, argv[1]);
3f0ec068
JH
95
96 status = !!mailinfo(&mi, msgfile, patchfile);
c69f2395
JH
97 clear_mailinfo(&mi);
98
3f0ec068
JH
99 free(msgfile);
100 free(patchfile);
c69f2395 101 return status;
2744b234 102}