]> diplodocus.org Git - nmh/commitdiff
Fix some space calculation/whitespace handling bugs.
authorKen Hornstein <kenh@pobox.com>
Thu, 31 Oct 2013 00:44:19 +0000 (20:44 -0400)
committerKen Hornstein <kenh@pobox.com>
Thu, 31 Oct 2013 00:44:19 +0000 (20:44 -0400)
sbr/encode_rfc2047.c

index 3bd22ac38ce7f8cb6868c707ba4e93485c7d63c0..40bee57897c43c57fd5e865202c66f4991191256 100644 (file)
@@ -35,7 +35,7 @@ static char *address_headers[] = {
  * Macros we use for parsing 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 == '_')
 
 
 #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;
 
            /*
            outlen += 9 + charsetlen + ascii + 3 * encoded;
 
            /*
@@ -209,8 +211,9 @@ field_encode_quoted(const char *name, char **value, const char *charset,
                    *q++ = *p++;
            }
 
                    *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;
        }
 
            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;
        } else {
            snprintf(q, outlen - (q - output), "=%02X", *((unsigned char *) p));
            q += 3;
-           column += 3;
+           column += 2;        /* column already incremented by 1 above */
            encoded--;
        }
 
            encoded--;
        }