2 * Another stupid program, this one parsing the headers of an
3 * email to figure out authorship and subject
8 #include "environment.h"
13 #include "parse-options.h"
15 static const char * const mailinfo_usage
[] = {
16 /* TRANSLATORS: keep <> in "<" mail ">" info. */
17 N_("git mailinfo [<options>] <msg> <patch> < mail >info"),
21 struct metainfo_charset
31 static int parse_opt_explicit_encoding(const struct option
*opt
,
32 const char *arg
, int unset
)
34 struct metainfo_charset
*meta_charset
= opt
->value
;
36 BUG_ON_OPT_NEG(unset
);
38 meta_charset
->policy
= CHARSET_EXPLICIT
;
39 meta_charset
->charset
= arg
;
44 static int parse_opt_quoted_cr(const struct option
*opt
, const char *arg
, int unset
)
46 BUG_ON_OPT_NEG(unset
);
48 if (mailinfo_parse_quoted_cr_action(arg
, opt
->value
) != 0)
49 return error(_("bad action '%s' for '%s'"), arg
, "--quoted-cr");
53 int cmd_mailinfo(int argc
, const char **argv
, const char *prefix
)
55 struct metainfo_charset meta_charset
;
58 char *msgfile
, *patchfile
;
60 struct option options
[] = {
61 OPT_BOOL('k', NULL
, &mi
.keep_subject
, N_("keep subject")),
62 OPT_BOOL('b', NULL
, &mi
.keep_non_patch_brackets_in_subject
,
63 N_("keep non patch brackets in subject")),
64 OPT_BOOL('m', "message-id", &mi
.add_message_id
,
65 N_("copy Message-ID to the end of commit message")),
66 OPT_SET_INT_F('u', NULL
, &meta_charset
.policy
,
67 N_("re-code metadata to i18n.commitEncoding"),
68 CHARSET_DEFAULT
, PARSE_OPT_NONEG
),
69 OPT_SET_INT_F('n', NULL
, &meta_charset
.policy
,
70 N_("disable charset re-coding of metadata"),
71 CHARSET_NO_REENCODE
, PARSE_OPT_NONEG
),
72 OPT_CALLBACK_F(0, "encoding", &meta_charset
, N_("encoding"),
73 N_("re-code metadata to this encoding"),
74 PARSE_OPT_NONEG
, parse_opt_explicit_encoding
),
75 OPT_BOOL(0, "scissors", &mi
.use_scissors
, N_("use scissors")),
76 OPT_CALLBACK_F(0, "quoted-cr", &mi
.quoted_cr
, N_("<action>"),
77 N_("action when quoted CR is found"),
78 PARSE_OPT_NONEG
, parse_opt_quoted_cr
),
79 OPT_HIDDEN_BOOL(0, "inbody-headers", &mi
.use_inbody_headers
,
80 N_("use headers in message's body")),
85 meta_charset
.policy
= CHARSET_DEFAULT
;
87 argc
= parse_options(argc
, argv
, prefix
, options
, mailinfo_usage
, 0);
90 usage_with_options(mailinfo_usage
, options
);
92 switch (meta_charset
.policy
) {
94 mi
.metainfo_charset
= get_commit_output_encoding();
96 case CHARSET_NO_REENCODE
:
97 mi
.metainfo_charset
= NULL
;
99 case CHARSET_EXPLICIT
:
102 BUG("invalid meta_charset.policy");
108 msgfile
= prefix_filename(prefix
, argv
[0]);
109 patchfile
= prefix_filename(prefix
, argv
[1]);
111 status
= !!mailinfo(&mi
, msgfile
, patchfile
);