Fix pack-index issue on 64-bit platforms a bit more portably.
[git.git] / mailinfo.c
index 0265a29..b276519 100644 (file)
@@ -7,7 +7,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#ifndef NO_ICONV
 #include <iconv.h>
+#endif
 #include "git-compat-util.h"
 #include "cache.h"
 
@@ -403,7 +405,7 @@ static unsigned hexval(int c)
        return ~0;
 }
 
-static int decode_q_segment(char *in, char *ot, char *ep)
+static int decode_q_segment(char *in, char *ot, char *ep, int rfc2047)
 {
        int c;
        while ((c = *in++) != 0 && (in <= ep)) {
@@ -412,9 +414,11 @@ static int decode_q_segment(char *in, char *ot, char *ep)
                        if (d == '\n' || !d)
                                break; /* drop trailing newline */
                        *ot++ = ((hexval(d) << 4) | hexval(*in++));
+                       continue;
                }
-               else
-                       *ot++ = c;
+               if (rfc2047 && c == '_') /* rfc2047 4.2 (2) */
+                       c = 0x20;
+               *ot++ = c;
        }
        *ot = 0;
        return 0;
@@ -469,6 +473,7 @@ 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 */
@@ -501,6 +506,7 @@ static void convert_to_utf8(char *line, char *charset)
                return;
        *out = 0;
        strcpy(line, outbuf);
+#endif
 }
 
 static void decode_header_bq(char *it)
@@ -543,7 +549,7 @@ static void decode_header_bq(char *it)
                        sz = decode_b_segment(cp + 3, piecebuf, ep);
                        break;
                case 'q':
-                       sz = decode_q_segment(cp + 3, piecebuf, ep);
+                       sz = decode_q_segment(cp + 3, piecebuf, ep, 1);
                        break;
                }
                if (sz < 0)
@@ -565,7 +571,7 @@ static void decode_transfer_encoding(char *line)
        switch (transfer_encoding) {
        case TE_QP:
                ep = line + strlen(line);
-               decode_q_segment(line, line, ep);
+               decode_q_segment(line, line, ep, 0);
                break;
        case TE_BASE64:
                ep = line + strlen(line);
@@ -707,6 +713,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);