mailinfo: decode underscore used in "Q" encoding properly.
Quoted-Printable (RFC 2045) and the "Q" encoding (RFC 2047) are subtly different; the latter is used on the mail header and an underscore needs to be decoded to 0x20. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Apr 21, 2006 at 00:06 UTC
757319309ac26d136d6f21a40c81fb53073c5dc9
1 file changed
+7
-5
mailinfo.c
+7
-5
@@ -405,7 +405,7 @@ static unsigned hexval(int c)
405
return ~0;
406
}
407
408
-static int decode_q_segment(char *in, char *ot, char *ep)
408
+static int decode_q_segment(char *in, char *ot, char *ep, int rfc2047)
409
{
410
int c;
411
while ((c = *in++) != 0 && (in <= ep)) {
@@ -414,9 +414,11 @@ static int decode_q_segment(char *in, char *ot, char *ep)
414
if (d == '\n' || !d)
415
break; /* drop trailing newline */
416
*ot++ = ((hexval(d) << 4) | hexval(*in++));
417
+ continue;
418
}
418
- else
419
- *ot++ = c;
419
+ if (rfc2047 && c == '_') /* rfc2047 4.2 (2) */
420
+ c = 0x20;
421
+ *ot++ = c;
422
}
423
*ot = 0;
424
return 0;
@@ -547,7 +549,7 @@ static void decode_header_bq(char *it)
549
sz = decode_b_segment(cp + 3, piecebuf, ep);
550
break;
551
case 'q':
550
- sz = decode_q_segment(cp + 3, piecebuf, ep);
552
+ sz = decode_q_segment(cp + 3, piecebuf, ep, 1);
553
break;
554
}
555
if (sz < 0)
@@ -569,7 +571,7 @@ static void decode_transfer_encoding(char *line)
571
switch (transfer_encoding) {
572
case TE_QP:
573
ep = line + strlen(line);
572
- decode_q_segment(line, line, ep);
574
+ decode_q_segment(line, line, ep, 0);
575
break;
576
case TE_BASE64:
577
ep = line + strlen(line);