X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=mailinfo.c;h=9f95f37651e2ce5a3930051fe875f1c16ede97c2;hb=ee34518d629331dadd58b1a75294369d679eda8b;hp=890e3487adf65b937f9a9d1ec82d59c746bf62de;hpb=36d277c72d90d32f99616072b64a2652248f5264;p=git.git diff --git a/mailinfo.c b/mailinfo.c index 890e3487..9f95f376 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