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