Skip to content

Commit

Permalink
mailinfo: decode underscore used in "Q" encoding properly.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Apr 21, 2006
1 parent d598075 commit 7573193
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions mailinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,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)) {
Expand All @@ -414,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;
Expand Down Expand Up @@ -547,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)
Expand All @@ -569,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);
Expand Down

0 comments on commit 7573193

Please sign in to comment.