2005-04-12 08:46:50 +02:00
|
|
|
/*
|
|
|
|
* Another stupid program, this one parsing the headers of an
|
|
|
|
* email to figure out authorship and subject
|
|
|
|
*/
|
2005-11-28 01:29:38 +01:00
|
|
|
#include "cache.h"
|
2023-03-21 07:25:58 +01:00
|
|
|
#include "abspath.h"
|
2006-06-13 22:21:50 +02:00
|
|
|
#include "builtin.h"
|
2023-03-21 07:26:03 +01:00
|
|
|
#include "environment.h"
|
2023-03-21 07:25:54 +01:00
|
|
|
#include "gettext.h"
|
2006-12-24 08:36:55 +01:00
|
|
|
#include "utf8.h"
|
2008-07-13 20:30:12 +02:00
|
|
|
#include "strbuf.h"
|
2015-10-15 02:44:55 +02:00
|
|
|
#include "mailinfo.h"
|
2021-05-06 17:02:20 +02:00
|
|
|
#include "parse-options.h"
|
2015-10-19 07:22:10 +02:00
|
|
|
|
2021-05-06 17:02:20 +02:00
|
|
|
static const char * const mailinfo_usage[] = {
|
|
|
|
/* TRANSLATORS: keep <> in "<" mail ">" info. */
|
|
|
|
N_("git mailinfo [<options>] <msg> <patch> < mail >info"),
|
|
|
|
NULL,
|
|
|
|
};
|
2005-08-28 21:33:16 +02:00
|
|
|
|
2021-05-06 17:02:18 +02:00
|
|
|
struct metainfo_charset
|
|
|
|
{
|
|
|
|
enum {
|
|
|
|
CHARSET_DEFAULT,
|
|
|
|
CHARSET_NO_REENCODE,
|
|
|
|
CHARSET_EXPLICIT,
|
|
|
|
} policy;
|
|
|
|
const char *charset;
|
|
|
|
};
|
|
|
|
|
2021-05-06 17:02:20 +02:00
|
|
|
static int parse_opt_explicit_encoding(const struct option *opt,
|
|
|
|
const char *arg, int unset)
|
|
|
|
{
|
|
|
|
struct metainfo_charset *meta_charset = opt->value;
|
|
|
|
|
|
|
|
BUG_ON_OPT_NEG(unset);
|
|
|
|
|
|
|
|
meta_charset->policy = CHARSET_EXPLICIT;
|
|
|
|
meta_charset->charset = arg;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-09 19:12:11 +02:00
|
|
|
static int parse_opt_quoted_cr(const struct option *opt, const char *arg, int unset)
|
|
|
|
{
|
|
|
|
BUG_ON_OPT_NEG(unset);
|
|
|
|
|
|
|
|
if (mailinfo_parse_quoted_cr_action(arg, opt->value) != 0)
|
|
|
|
return error(_("bad action '%s' for '%s'"), arg, "--quoted-cr");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-29 07:44:25 +02:00
|
|
|
int cmd_mailinfo(int argc, const char **argv, const char *prefix)
|
2005-04-12 08:46:50 +02:00
|
|
|
{
|
2021-05-06 17:02:18 +02:00
|
|
|
struct metainfo_charset meta_charset;
|
2015-10-19 07:22:10 +02:00
|
|
|
struct mailinfo mi;
|
|
|
|
int status;
|
2016-11-22 22:13:16 +01:00
|
|
|
char *msgfile, *patchfile;
|
2007-01-10 06:31:36 +01:00
|
|
|
|
2021-05-06 17:02:20 +02:00
|
|
|
struct option options[] = {
|
|
|
|
OPT_BOOL('k', NULL, &mi.keep_subject, N_("keep subject")),
|
|
|
|
OPT_BOOL('b', NULL, &mi.keep_non_patch_brackets_in_subject,
|
|
|
|
N_("keep non patch brackets in subject")),
|
|
|
|
OPT_BOOL('m', "message-id", &mi.add_message_id,
|
|
|
|
N_("copy Message-ID to the end of commit message")),
|
|
|
|
OPT_SET_INT_F('u', NULL, &meta_charset.policy,
|
|
|
|
N_("re-code metadata to i18n.commitEncoding"),
|
|
|
|
CHARSET_DEFAULT, PARSE_OPT_NONEG),
|
|
|
|
OPT_SET_INT_F('n', NULL, &meta_charset.policy,
|
|
|
|
N_("disable charset re-coding of metadata"),
|
|
|
|
CHARSET_NO_REENCODE, PARSE_OPT_NONEG),
|
|
|
|
OPT_CALLBACK_F(0, "encoding", &meta_charset, N_("encoding"),
|
|
|
|
N_("re-code metadata to this encoding"),
|
|
|
|
PARSE_OPT_NONEG, parse_opt_explicit_encoding),
|
|
|
|
OPT_BOOL(0, "scissors", &mi.use_scissors, N_("use scissors")),
|
2021-05-09 19:12:11 +02:00
|
|
|
OPT_CALLBACK_F(0, "quoted-cr", &mi.quoted_cr, N_("<action>"),
|
|
|
|
N_("action when quoted CR is found"),
|
|
|
|
PARSE_OPT_NONEG, parse_opt_quoted_cr),
|
2021-05-06 17:02:20 +02:00
|
|
|
OPT_HIDDEN_BOOL(0, "inbody-headers", &mi.use_inbody_headers,
|
|
|
|
N_("use headers in message's body")),
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2015-10-19 07:22:10 +02:00
|
|
|
setup_mailinfo(&mi);
|
2021-05-06 17:02:18 +02:00
|
|
|
meta_charset.policy = CHARSET_DEFAULT;
|
2007-01-10 06:31:36 +01:00
|
|
|
|
2021-05-06 17:02:20 +02:00
|
|
|
argc = parse_options(argc, argv, prefix, options, mailinfo_usage, 0);
|
2005-08-17 07:18:27 +02:00
|
|
|
|
2021-05-06 17:02:20 +02:00
|
|
|
if (argc != 2)
|
|
|
|
usage_with_options(mailinfo_usage, options);
|
2006-06-13 22:21:50 +02:00
|
|
|
|
2021-05-06 17:02:18 +02:00
|
|
|
switch (meta_charset.policy) {
|
|
|
|
case CHARSET_DEFAULT:
|
|
|
|
mi.metainfo_charset = get_commit_output_encoding();
|
|
|
|
break;
|
|
|
|
case CHARSET_NO_REENCODE:
|
|
|
|
mi.metainfo_charset = NULL;
|
|
|
|
break;
|
|
|
|
case CHARSET_EXPLICIT:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG("invalid meta_charset.policy");
|
|
|
|
}
|
|
|
|
|
2015-10-15 00:40:04 +02:00
|
|
|
mi.input = stdin;
|
|
|
|
mi.output = stdout;
|
2016-11-22 22:13:16 +01:00
|
|
|
|
2021-05-06 17:02:20 +02:00
|
|
|
msgfile = prefix_filename(prefix, argv[0]);
|
|
|
|
patchfile = prefix_filename(prefix, argv[1]);
|
2016-11-22 22:13:16 +01:00
|
|
|
|
|
|
|
status = !!mailinfo(&mi, msgfile, patchfile);
|
2015-10-19 07:22:10 +02:00
|
|
|
clear_mailinfo(&mi);
|
|
|
|
|
2016-11-22 22:13:16 +01:00
|
|
|
free(msgfile);
|
|
|
|
free(patchfile);
|
2015-10-19 07:22:10 +02:00
|
|
|
return status;
|
2005-04-12 08:46:50 +02:00
|
|
|
}
|