2005-04-12 14:46:50 +08:00
|
|
|
/*
|
|
|
|
* Another stupid program, this one parsing the headers of an
|
|
|
|
* email to figure out authorship and subject
|
|
|
|
*/
|
2005-11-28 08:29:38 +08:00
|
|
|
#include "cache.h"
|
2006-06-14 04:21:50 +08:00
|
|
|
#include "builtin.h"
|
2006-12-24 15:36:55 +08:00
|
|
|
#include "utf8.h"
|
2008-07-14 02:30:12 +08:00
|
|
|
#include "strbuf.h"
|
2015-10-15 08:44:55 +08:00
|
|
|
#include "mailinfo.h"
|
2015-10-19 13:22:10 +08:00
|
|
|
|
2005-08-17 13:18:27 +08:00
|
|
|
static const char mailinfo_usage[] =
|
2015-01-13 15:44:47 +08:00
|
|
|
"git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] <msg> <patch> < mail >info";
|
2005-08-29 03:33:16 +08:00
|
|
|
|
2006-07-29 13:44:25 +08:00
|
|
|
int cmd_mailinfo(int argc, const char **argv, const char *prefix)
|
2005-04-12 14:46:50 +08:00
|
|
|
{
|
2007-01-10 13:31:36 +08:00
|
|
|
const char *def_charset;
|
2015-10-19 13:22:10 +08:00
|
|
|
struct mailinfo mi;
|
|
|
|
int status;
|
2007-01-10 13:31:36 +08:00
|
|
|
|
2005-11-28 08:29:38 +08:00
|
|
|
/* NEEDSWORK: might want to do the optional .git/ directory
|
|
|
|
* discovery
|
|
|
|
*/
|
2015-10-19 13:22:10 +08:00
|
|
|
setup_mailinfo(&mi);
|
2005-11-28 08:29:38 +08:00
|
|
|
|
2010-11-03 03:59:07 +08:00
|
|
|
def_charset = get_commit_output_encoding();
|
2015-10-15 07:15:40 +08:00
|
|
|
mi.metainfo_charset = def_charset;
|
2007-01-10 13:31:36 +08:00
|
|
|
|
2005-08-17 13:18:27 +08:00
|
|
|
while (1 < argc && argv[1][0] == '-') {
|
|
|
|
if (!strcmp(argv[1], "-k"))
|
2015-10-15 06:39:37 +08:00
|
|
|
mi.keep_subject = 1;
|
2009-07-16 06:31:12 +08:00
|
|
|
else if (!strcmp(argv[1], "-b"))
|
2015-10-15 06:39:37 +08:00
|
|
|
mi.keep_non_patch_brackets_in_subject = 1;
|
2014-11-25 22:00:55 +08:00
|
|
|
else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id"))
|
2015-10-19 13:27:56 +08:00
|
|
|
mi.add_message_id = 1;
|
2005-08-29 03:33:16 +08:00
|
|
|
else if (!strcmp(argv[1], "-u"))
|
2015-10-15 07:15:40 +08:00
|
|
|
mi.metainfo_charset = def_charset;
|
2007-01-10 13:31:36 +08:00
|
|
|
else if (!strcmp(argv[1], "-n"))
|
2015-10-15 07:15:40 +08:00
|
|
|
mi.metainfo_charset = NULL;
|
2013-12-01 04:55:40 +08:00
|
|
|
else if (starts_with(argv[1], "--encoding="))
|
2015-10-15 07:15:40 +08:00
|
|
|
mi.metainfo_charset = argv[1] + 11;
|
2009-08-27 12:36:05 +08:00
|
|
|
else if (!strcmp(argv[1], "--scissors"))
|
2015-10-15 07:14:57 +08:00
|
|
|
mi.use_scissors = 1;
|
2009-08-27 12:36:05 +08:00
|
|
|
else if (!strcmp(argv[1], "--no-scissors"))
|
2015-10-15 07:14:57 +08:00
|
|
|
mi.use_scissors = 0;
|
2009-11-21 00:12:47 +08:00
|
|
|
else if (!strcmp(argv[1], "--no-inbody-headers"))
|
2015-10-15 07:14:57 +08:00
|
|
|
mi.use_inbody_headers = 0;
|
2005-08-29 03:33:16 +08:00
|
|
|
else
|
2005-11-28 08:29:38 +08:00
|
|
|
usage(mailinfo_usage);
|
2005-08-17 13:18:27 +08:00
|
|
|
argc--; argv++;
|
|
|
|
}
|
|
|
|
|
2005-06-24 00:40:23 +08:00
|
|
|
if (argc != 3)
|
2005-11-28 08:29:38 +08:00
|
|
|
usage(mailinfo_usage);
|
2006-06-14 04:21:50 +08:00
|
|
|
|
2015-10-15 06:40:04 +08:00
|
|
|
mi.input = stdin;
|
|
|
|
mi.output = stdout;
|
|
|
|
status = !!mailinfo(&mi, argv[1], argv[2]);
|
2015-10-19 13:22:10 +08:00
|
|
|
clear_mailinfo(&mi);
|
|
|
|
|
|
|
|
return status;
|
2005-04-12 14:46:50 +08:00
|
|
|
}
|