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