Skip to content

Commit 7573193

Browse files
author
Junio C Hamano
committed
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>
1 parent d598075 commit 7573193

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

mailinfo.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ static unsigned hexval(int c)
405405
return ~0;
406406
}
407407

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)
409409
{
410410
int c;
411411
while ((c = *in++) != 0 && (in <= ep)) {
@@ -414,9 +414,11 @@ static int decode_q_segment(char *in, char *ot, char *ep)
414414
if (d == '\n' || !d)
415415
break; /* drop trailing newline */
416416
*ot++ = ((hexval(d) << 4) | hexval(*in++));
417+
continue;
417418
}
418-
else
419-
*ot++ = c;
419+
if (rfc2047 && c == '_') /* rfc2047 4.2 (2) */
420+
c = 0x20;
421+
*ot++ = c;
420422
}
421423
*ot = 0;
422424
return 0;
@@ -547,7 +549,7 @@ static void decode_header_bq(char *it)
547549
sz = decode_b_segment(cp + 3, piecebuf, ep);
548550
break;
549551
case 'q':
550-
sz = decode_q_segment(cp + 3, piecebuf, ep);
552+
sz = decode_q_segment(cp + 3, piecebuf, ep, 1);
551553
break;
552554
}
553555
if (sz < 0)
@@ -569,7 +571,7 @@ static void decode_transfer_encoding(char *line)
569571
switch (transfer_encoding) {
570572
case TE_QP:
571573
ep = line + strlen(line);
572-
decode_q_segment(line, line, ep);
574+
decode_q_segment(line, line, ep, 0);
573575
break;
574576
case TE_BASE64:
575577
ep = line + strlen(line);

0 commit comments

Comments
 (0)