]> git.ipfire.org Git - thirdparty/git.git/blobdiff - mailinfo.c
Merge branch 'ml/cvsserver'
[thirdparty/git.git] / mailinfo.c
index 890e3487adf65b937f9a9d1ec82d59c746bf62de..3c56f8c10801bdc93eaaac6319e477f81c096717 100644 (file)
@@ -7,12 +7,11 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#ifndef NO_ICONV
 #include <iconv.h>
-#include "cache.h"
-
-#ifdef NO_STRCASESTR
-extern char *gitstrcasestr(const char *haystack, const char *needle);
 #endif
+#include "git-compat-util.h"
+#include "cache.h"
 
 static FILE *cmitmsg, *patchfile;
 
@@ -43,13 +42,43 @@ static char *sanity_check(char *name, char *email)
        return name;
 }
 
+static int bogus_from(char *line)
+{
+       /* John Doe <johndoe> */
+       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
@@ -442,10 +471,11 @@ static int decode_b_segment(char *in, char *ot, char *ep)
 
 static void convert_to_utf8(char *line, char *charset)
 {
+#ifndef NO_ICONV
        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);
 
@@ -474,6 +504,7 @@ static void convert_to_utf8(char *line, char *charset)
                return;
        *out = 0;
        strcpy(line, outbuf);
+#endif
 }
 
 static void decode_header_bq(char *it)
@@ -680,6 +711,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);