--- sylpheed-0.8.8/src/quoted-printable.c.qpfix Thu Dec 12 07:19:18 2002 +++ sylpheed-0.8.8/src/quoted-printable.c Thu Jan 23 16:37:07 2003 @@ -99,6 +99,28 @@ return len; } +/** + * Check if the character can be represented directly in a Q-encoded word. + * + * @param c Tested character + * + * @returns 1 if the character can be represented directly, 0 if it must be + * hex-encoded. + * + * @warning The argument is evaluated multiple times. + * + * @note This macro uses the most restrictive set of allowed characters + * (described in RFC 2047, section 5, (3)), so the word encoded + * according to these rules should be usable in all contexts where + * an encoded word may appear. + */ +#define IS_QP_SAFE_CHAR(c) \ + ( ((c) >= 'A' && (c) <= 'Z') || \ + ((c) >= 'a' && (c) <= 'z') || \ + ((c) >= '0' && (c) <= '9') || \ + ((c) == '!') || ((c) == '*') || ((c) == '+') || \ + ((c) == '-') || ((c) == '/') ) + void qp_q_encode(gchar *out, const guchar *in) { const guchar *inp = in; @@ -107,13 +129,13 @@ while (*inp != '\0') { if (*inp == 0x20) *outp++ = '_'; - else if (*inp == '=' || *inp == '?' || *inp == '_' || - *inp < 32 || *inp > 127 || isspace(*inp)) { + else if (IS_QP_SAFE_CHAR(*inp)) + *outp++ = *inp; + else { *outp++ = '='; get_hex_str(outp, *inp); outp += 2; - } else - *outp++ = *inp; + } inp++; }