2 * Another stupid program, this one parsing the headers of an
3 * email to figure out authorship and subject
11 static const char mailinfo_usage
[] =
12 "git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] <msg> <patch> < mail >info";
14 static char *prefix_copy(const char *prefix
, const char *filename
)
16 if (!prefix
|| is_absolute_path(filename
))
17 return xstrdup(filename
);
18 return xstrdup(prefix_filename(prefix
, strlen(prefix
), filename
));
21 int cmd_mailinfo(int argc
, const char **argv
, const char *prefix
)
23 const char *def_charset
;
26 char *msgfile
, *patchfile
;
30 def_charset
= get_commit_output_encoding();
31 mi
.metainfo_charset
= def_charset
;
33 while (1 < argc
&& argv
[1][0] == '-') {
34 if (!strcmp(argv
[1], "-k"))
36 else if (!strcmp(argv
[1], "-b"))
37 mi
.keep_non_patch_brackets_in_subject
= 1;
38 else if (!strcmp(argv
[1], "-m") || !strcmp(argv
[1], "--message-id"))
39 mi
.add_message_id
= 1;
40 else if (!strcmp(argv
[1], "-u"))
41 mi
.metainfo_charset
= def_charset
;
42 else if (!strcmp(argv
[1], "-n"))
43 mi
.metainfo_charset
= NULL
;
44 else if (starts_with(argv
[1], "--encoding="))
45 mi
.metainfo_charset
= argv
[1] + 11;
46 else if (!strcmp(argv
[1], "--scissors"))
48 else if (!strcmp(argv
[1], "--no-scissors"))
50 else if (!strcmp(argv
[1], "--no-inbody-headers"))
51 mi
.use_inbody_headers
= 0;
53 usage(mailinfo_usage
);
58 usage(mailinfo_usage
);
63 msgfile
= prefix_copy(prefix
, argv
[1]);
64 patchfile
= prefix_copy(prefix
, argv
[2]);
66 status
= !!mailinfo(&mi
, msgfile
, patchfile
);