2 * Another stupid program, this one parsing the headers of an
3 * email to figure out authorship and subject
10 #include "parse-options.h"
12 static const char * const mailinfo_usage
[] = {
13 /* TRANSLATORS: keep <> in "<" mail ">" info. */
14 N_("git mailinfo [<options>] <msg> <patch> < mail >info"),
18 struct metainfo_charset
28 static int parse_opt_explicit_encoding(const struct option
*opt
,
29 const char *arg
, int unset
)
31 struct metainfo_charset
*meta_charset
= opt
->value
;
33 BUG_ON_OPT_NEG(unset
);
35 meta_charset
->policy
= CHARSET_EXPLICIT
;
36 meta_charset
->charset
= arg
;
41 static int parse_opt_quoted_cr(const struct option
*opt
, const char *arg
, int unset
)
43 BUG_ON_OPT_NEG(unset
);
45 if (mailinfo_parse_quoted_cr_action(arg
, opt
->value
) != 0)
46 return error(_("bad action '%s' for '%s'"), arg
, "--quoted-cr");
50 int cmd_mailinfo(int argc
, const char **argv
, const char *prefix
)
52 struct metainfo_charset meta_charset
;
55 char *msgfile
, *patchfile
;
57 struct option options
[] = {
58 OPT_BOOL('k', NULL
, &mi
.keep_subject
, N_("keep subject")),
59 OPT_BOOL('b', NULL
, &mi
.keep_non_patch_brackets_in_subject
,
60 N_("keep non patch brackets in subject")),
61 OPT_BOOL('m', "message-id", &mi
.add_message_id
,
62 N_("copy Message-ID to the end of commit message")),
63 OPT_SET_INT_F('u', NULL
, &meta_charset
.policy
,
64 N_("re-code metadata to i18n.commitEncoding"),
65 CHARSET_DEFAULT
, PARSE_OPT_NONEG
),
66 OPT_SET_INT_F('n', NULL
, &meta_charset
.policy
,
67 N_("disable charset re-coding of metadata"),
68 CHARSET_NO_REENCODE
, PARSE_OPT_NONEG
),
69 OPT_CALLBACK_F(0, "encoding", &meta_charset
, N_("encoding"),
70 N_("re-code metadata to this encoding"),
71 PARSE_OPT_NONEG
, parse_opt_explicit_encoding
),
72 OPT_BOOL(0, "scissors", &mi
.use_scissors
, N_("use scissors")),
73 OPT_CALLBACK_F(0, "quoted-cr", &mi
.quoted_cr
, N_("<action>"),
74 N_("action when quoted CR is found"),
75 PARSE_OPT_NONEG
, parse_opt_quoted_cr
),
76 OPT_HIDDEN_BOOL(0, "inbody-headers", &mi
.use_inbody_headers
,
77 N_("use headers in message's body")),
82 meta_charset
.policy
= CHARSET_DEFAULT
;
84 argc
= parse_options(argc
, argv
, prefix
, options
, mailinfo_usage
, 0);
87 usage_with_options(mailinfo_usage
, options
);
89 switch (meta_charset
.policy
) {
91 mi
.metainfo_charset
= get_commit_output_encoding();
93 case CHARSET_NO_REENCODE
:
94 mi
.metainfo_charset
= NULL
;
96 case CHARSET_EXPLICIT
:
99 BUG("invalid meta_charset.policy");
105 msgfile
= prefix_filename(prefix
, argv
[0]);
106 patchfile
= prefix_filename(prefix
, argv
[1]);
108 status
= !!mailinfo(&mi
, msgfile
, patchfile
);