From f81ac5eab1ca45fb885911447f8f2e93ada1d86d Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Wed, 30 Oct 2013 20:44:19 -0400 Subject: [PATCH] Fix some space calculation/whitespace handling bugs. --- sbr/encode_rfc2047.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sbr/encode_rfc2047.c b/sbr/encode_rfc2047.c index 3bd22ac3..40bee578 100644 --- a/sbr/encode_rfc2047.c +++ b/sbr/encode_rfc2047.c @@ -35,7 +35,7 @@ static char *address_headers[] = { * Macros we use for parsing headers */ -#define is_fws(c) (c == '\t' || c == ' ') +#define is_fws(c) (c == '\t' || c == ' ' || c == '\n') #define qpspecial(c) (c < ' ' || c == '=' || c == '?' || c == '_') @@ -180,6 +180,8 @@ field_encode_quoted(const char *name, char **value, const char *charset, * */ + int tokenlen; + outlen += 9 + charsetlen + ascii + 3 * encoded; /* @@ -209,8 +211,9 @@ field_encode_quoted(const char *name, char **value, const char *charset, *q++ = *p++; } - q += snprintf(q, outlen - (q - output), "=?%s?Q?", charset); - column = prefixlen; + tokenlen = snprintf(q, outlen - (q - output), "=?%s?Q?", charset); + q += tokenlen; + column = prefixlen + tokenlen; newline = 0; } @@ -229,7 +232,7 @@ field_encode_quoted(const char *name, char **value, const char *charset, } else { snprintf(q, outlen - (q - output), "=%02X", *((unsigned char *) p)); q += 3; - column += 3; + column += 2; /* column already incremented by 1 above */ encoded--; } -- 2.56.0