X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=mailinfo.c;h=ff2d4d403826b035a7bb123dc74a50af9a76e353;hb=8bb2e03b9d47d87657b67ddfaf712e736cf3db8f;hp=de105acaa8898b637e53b9a38ca695ec9514d817;hpb=f1f909e3185b5ee366e198042447afe749bfc813;p=git.git diff --git a/mailinfo.c b/mailinfo.c index de105aca..ff2d4d40 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -8,12 +8,9 @@ #include #include #include +#include "git-compat-util.h" #include "cache.h" -#ifdef NO_STRCASESTR -extern char *gitstrcasestr(const char *haystack, const char *needle); -#endif - static FILE *cmitmsg, *patchfile; static int keep_subject = 0; @@ -43,13 +40,43 @@ static char *sanity_check(char *name, char *email) return name; } +static int bogus_from(char *line) +{ + /* John Doe */ + char *bra, *ket, *dst, *cp; + + /* This is fallback, so do not bother if we already have an + * e-mail address. + */ + if (*email) + return 0; + + bra = strchr(line, '<'); + if (!bra) + return 0; + ket = strchr(bra, '>'); + if (!ket) + return 0; + + for (dst = email, cp = bra+1; cp < ket; ) + *dst++ = *cp++; + *dst = 0; + for (cp = line; isspace(*cp); cp++) + ; + for (bra--; isspace(*bra); bra--) + *bra = 0; + cp = sanity_check(cp, email); + strcpy(name, cp); + return 1; +} + static int handle_from(char *line) { char *at = strchr(line, '@'); char *dst; if (!at) - return 0; + return bogus_from(line); /* * If we already have one email, don't take any confusing lines @@ -445,7 +472,7 @@ static void convert_to_utf8(char *line, char *charset) char *in, *out; size_t insize, outsize, nrc; char outbuf[4096]; /* cheat */ - static char latin_one[] = "latin-1"; + static char latin_one[] = "latin1"; char *input_charset = *charset ? charset : latin_one; iconv_t conv = iconv_open(metainfo_charset, input_charset); @@ -680,6 +707,9 @@ static void handle_multipart_body(void) if (!len) { if (handle_multipart_one_part() < 0) return; + /* Reset per part headers */ + transfer_encoding = TE_DONTCARE; + charset[0] = 0; } else check_subheader_line(line, len); @@ -717,7 +747,7 @@ static void handle_body(void) } static const char mailinfo_usage[] = - "git-mailinfo [-k] [-u] msg patch info"; + "git-mailinfo [-k] [-u | --encoding=] msg patch info"; int main(int argc, char **argv) { @@ -731,8 +761,8 @@ int main(int argc, char **argv) keep_subject = 1; else if (!strcmp(argv[1], "-u")) metainfo_charset = git_commit_encoding; - else if (!strncmp(argv[1], "-u=", 3)) - metainfo_charset = argv[1] + 3; + else if (!strncmp(argv[1], "--encoding=", 11)) + metainfo_charset = argv[1] + 11; else usage(mailinfo_usage); argc--; argv++;