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"
|
2006-06-13 22:21:50 +02:00
|
|
|
#include "builtin.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"
|
2015-10-19 07:22:10 +02:00
|
|
|
|
2005-08-17 07:18:27 +02:00
|
|
|
static const char mailinfo_usage[] =
|
2015-01-13 08:44:47 +01:00
|
|
|
"git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] <msg> <patch> < mail >info";
|
2005-08-28 21:33:16 +02:00
|
|
|
|
2016-11-22 22:13:16 +01:00
|
|
|
static char *prefix_copy(const char *prefix, const char *filename)
|
|
|
|
{
|
|
|
|
if (!prefix || is_absolute_path(filename))
|
|
|
|
return xstrdup(filename);
|
|
|
|
return xstrdup(prefix_filename(prefix, strlen(prefix), filename));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2007-01-10 06:31:36 +01:00
|
|
|
const char *def_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
|
|
|
|
2015-10-19 07:22:10 +02:00
|
|
|
setup_mailinfo(&mi);
|
2005-11-28 01:29:38 +01:00
|
|
|
|
2010-11-02 20:59:07 +01:00
|
|
|
def_charset = get_commit_output_encoding();
|
2015-10-15 01:15:40 +02:00
|
|
|
mi.metainfo_charset = def_charset;
|
2007-01-10 06:31:36 +01:00
|
|
|
|
2005-08-17 07:18:27 +02:00
|
|
|
while (1 < argc && argv[1][0] == '-') {
|
|
|
|
if (!strcmp(argv[1], "-k"))
|
2015-10-15 00:39:37 +02:00
|
|
|
mi.keep_subject = 1;
|
2009-07-16 00:31:12 +02:00
|
|
|
else if (!strcmp(argv[1], "-b"))
|
2015-10-15 00:39:37 +02:00
|
|
|
mi.keep_non_patch_brackets_in_subject = 1;
|
2014-11-25 15:00:55 +01:00
|
|
|
else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id"))
|
2015-10-19 07:27:56 +02:00
|
|
|
mi.add_message_id = 1;
|
2005-08-28 21:33:16 +02:00
|
|
|
else if (!strcmp(argv[1], "-u"))
|
2015-10-15 01:15:40 +02:00
|
|
|
mi.metainfo_charset = def_charset;
|
2007-01-10 06:31:36 +01:00
|
|
|
else if (!strcmp(argv[1], "-n"))
|
2015-10-15 01:15:40 +02:00
|
|
|
mi.metainfo_charset = NULL;
|
2013-11-30 21:55:40 +01:00
|
|
|
else if (starts_with(argv[1], "--encoding="))
|
2015-10-15 01:15:40 +02:00
|
|
|
mi.metainfo_charset = argv[1] + 11;
|
2009-08-27 06:36:05 +02:00
|
|
|
else if (!strcmp(argv[1], "--scissors"))
|
2015-10-15 01:14:57 +02:00
|
|
|
mi.use_scissors = 1;
|
2009-08-27 06:36:05 +02:00
|
|
|
else if (!strcmp(argv[1], "--no-scissors"))
|
2015-10-15 01:14:57 +02:00
|
|
|
mi.use_scissors = 0;
|
2009-11-20 17:12:47 +01:00
|
|
|
else if (!strcmp(argv[1], "--no-inbody-headers"))
|
2015-10-15 01:14:57 +02:00
|
|
|
mi.use_inbody_headers = 0;
|
2005-08-28 21:33:16 +02:00
|
|
|
else
|
2005-11-28 01:29:38 +01:00
|
|
|
usage(mailinfo_usage);
|
2005-08-17 07:18:27 +02:00
|
|
|
argc--; argv++;
|
|
|
|
}
|
|
|
|
|
2005-06-23 18:40:23 +02:00
|
|
|
if (argc != 3)
|
2005-11-28 01:29:38 +01:00
|
|
|
usage(mailinfo_usage);
|
2006-06-13 22:21:50 +02:00
|
|
|
|
2015-10-15 00:40:04 +02:00
|
|
|
mi.input = stdin;
|
|
|
|
mi.output = stdout;
|
2016-11-22 22:13:16 +01:00
|
|
|
|
|
|
|
msgfile = prefix_copy(prefix, argv[1]);
|
|
|
|
patchfile = prefix_copy(prefix, argv[2]);
|
|
|
|
|
|
|
|
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
|
|
|
}
|