@matheusbsbs / matheus-bagliano / commits / b75bf2c3f0
Fork 0

mailinfo: assume input is latin-1 on the header as we do for the body

When the input mbox does not identify what encoding it is in, and already have RFC2047 stripped away, we cannot tell what encoding the header text is in. For body text, when the message does not say what charset it is in, we fall back to assume latin-1 input when converting to utf8. This should be done consistently to the header as well. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jul 5, 2006 at 14:17 UTC b75bf2c3f08b70a3e4850867290a8c215d2c1abf
1 file changed +24 -8
builtin-mailinfo.c
+24 -8
@@ -348,7 +348,7 @@ static void cleanup_space(char *buf)
348 }
349 }
350
351 -static void decode_header_bq(char *it);
351 +static void decode_header(char *it);
352 typedef int (*header_fn_t)(char *);
353 struct header_def {
354 const char *name;
@@ -371,7 +371,7 @@ static void check_header(char *line, struct header_def *header)
371 /* Unwrap inline B and Q encoding, and optionally
372 * normalize the meta information to utf8.
373 */
374 - decode_header_bq(line + len + 2);
374 + decode_header(line + len + 2);
375 header[i].func(line + len + 2);
376 break;
377 }
@@ -566,16 +566,19 @@ static void convert_to_utf8(char *line, char *charset)
566 #endif
567 }
568
569 -static void decode_header_bq(char *it)
569 +static int decode_header_bq(char *it)
570 {
571 char *in, *out, *ep, *cp, *sp;
572 char outbuf[1000];
573 + int rfc2047 = 0;
574
575 in = it;
576 out = outbuf;
577 while ((ep = strstr(in, "=?")) != NULL) {
578 int sz, encoding;
579 char charset_q[256], piecebuf[256];
580 + rfc2047 = 1;
581 +
582 if (in != ep) {
583 sz = ep - in;
584 memcpy(out, in, sz);
@@ -589,19 +592,19 @@ static void decode_header_bq(char *it)
592 ep += 2;
593 cp = strchr(ep, '?');
594 if (!cp)
592 - return; /* no munging */
595 + return rfc2047; /* no munging */
596 for (sp = ep; sp < cp; sp++)
597 charset_q[sp - ep] = tolower(*sp);
598 charset_q[cp - ep] = 0;
599 encoding = cp[1];
600 if (!encoding || cp[2] != '?')
598 - return; /* no munging */
601 + return rfc2047; /* no munging */
602 ep = strstr(cp + 3, "?=");
603 if (!ep)
601 - return; /* no munging */
604 + return rfc2047; /* no munging */
605 switch (tolower(encoding)) {
606 default:
604 - return; /* no munging */
607 + return rfc2047; /* no munging */
608 case 'b':
609 sz = decode_b_segment(cp + 3, piecebuf, ep);
610 break;
@@ -610,7 +613,7 @@ static void decode_header_bq(char *it)
613 break;
614 }
615 if (sz < 0)
613 - return;
616 + return rfc2047;
617 if (metainfo_charset)
618 convert_to_utf8(piecebuf, charset_q);
619 strcpy(out, piecebuf);
@@ -619,6 +622,19 @@ static void decode_header_bq(char *it)
622 }
623 strcpy(out, in);
624 strcpy(it, outbuf);
625 + return rfc2047;
626 +}
627 +
628 +static void decode_header(char *it)
629 +{
630 +
631 + if (decode_header_bq(it))
632 + return;
633 + /* otherwise "it" is a straight copy of the input.
634 + * This can be binary guck but there is no charset specified.
635 + */
636 + if (metainfo_charset)
637 + convert_to_utf8(it, "");
638 }
639
640 static void decode_transfer_encoding(char *line)