mailinfo.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Another stupid program, this one parsing the headers of an
  3. * email to figure out authorship and subject
  4. */
  5. #include "cache.h"
  6. #include "builtin.h"
  7. #include "utf8.h"
  8. #include "strbuf.h"
  9. #include "mailinfo.h"
  10. static const char mailinfo_usage[] =
  11. "git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] <msg> <patch> < mail >info";
  12. int cmd_mailinfo(int argc, const char **argv, const char *prefix)
  13. {
  14. const char *def_charset;
  15. struct mailinfo mi;
  16. int status;
  17. char *msgfile, *patchfile;
  18. setup_mailinfo(&mi);
  19. def_charset = get_commit_output_encoding();
  20. mi.metainfo_charset = def_charset;
  21. while (1 < argc && argv[1][0] == '-') {
  22. if (!strcmp(argv[1], "-k"))
  23. mi.keep_subject = 1;
  24. else if (!strcmp(argv[1], "-b"))
  25. mi.keep_non_patch_brackets_in_subject = 1;
  26. else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id"))
  27. mi.add_message_id = 1;
  28. else if (!strcmp(argv[1], "-u"))
  29. mi.metainfo_charset = def_charset;
  30. else if (!strcmp(argv[1], "-n"))
  31. mi.metainfo_charset = NULL;
  32. else if (starts_with(argv[1], "--encoding="))
  33. mi.metainfo_charset = argv[1] + 11;
  34. else if (!strcmp(argv[1], "--scissors"))
  35. mi.use_scissors = 1;
  36. else if (!strcmp(argv[1], "--no-scissors"))
  37. mi.use_scissors = 0;
  38. else if (!strcmp(argv[1], "--no-inbody-headers"))
  39. mi.use_inbody_headers = 0;
  40. else
  41. usage(mailinfo_usage);
  42. argc--; argv++;
  43. }
  44. if (argc != 3)
  45. usage(mailinfo_usage);
  46. mi.input = stdin;
  47. mi.output = stdout;
  48. msgfile = prefix_filename(prefix, argv[1]);
  49. patchfile = prefix_filename(prefix, argv[2]);
  50. status = !!mailinfo(&mi, msgfile, patchfile);
  51. clear_mailinfo(&mi);
  52. free(msgfile);
  53. free(patchfile);
  54. return status;
  55. }