diff --git a/mbuni/ChangeLog b/mbuni/ChangeLog index 43ff4d3..deb3bba 100644 --- a/mbuni/ChangeLog +++ b/mbuni/ChangeLog @@ -1,3 +1,5 @@ +2011-05-05 P. A. Bagyenda + * Further fixes for RFC 2047 2011-05-04 P. A. Bagyenda * Fixed parsing of encoded-string-value that contains RFC 2047 text (e.g. To, Cc, Bcc fields) 2011-03-28 P. A. Bagyenda diff --git a/mbuni/mmlib/mms_msg.c b/mbuni/mmlib/mms_msg.c index d339170..b63c50b 100644 --- a/mbuni/mmlib/mms_msg.c +++ b/mbuni/mmlib/mms_msg.c @@ -259,45 +259,42 @@ static Octstr *decode_encoded_string_value(int ret, ParseContext *context, unsig int val; int ret2; Octstr *res = NULL; + long charset = UTF8_MIB_VAL; ret2 = (ret < 0) ? wsp_field_value(context, &val) : ret; if (ret2 == WSP_FIELD_VALUE_DATA) { /* expect charset text. */ - long charset; /* Get it and ignore it. */ - Octstr *xs; wsp_secondary_field_value(context, &charset); - xs = parse_get_nul_string(context); - + res = parse_get_nul_string(context); + if (ret < 0) { parse_skip_to_limit(context); parse_pop_limit(context); } - - res = pack_rfc2047_text(xs, charset); - octstr_destroy(xs); } else if (ret2 != WSP_FIELD_VALUE_NUL_STRING) { mms_warning(0, "mms_msg", NULL, "Faulty header value for %s! [ret=%d,ret2=%d]\n", hname,ret,ret2); res = octstr_imm(""); } else { /* String may be RFC 2047 encoded */ int mib = UTF8_MIB_VAL; - Octstr *xs = parse_get_nul_string(context); + Octstr *xs = parse_get_nul_string(context); res = parse_rfc2047_text(xs, &mib); octstr_destroy(xs); - - if (mib != UTF8_MIB_VAL && mib != US_ASCII_MIB_VAL) { /* Convert to UTF-8 */ - const char *charset = mibenum_to_charset(mib); - Octstr *xcharset = octstr_imm(charset); - Octstr *out = NULL; - - if (charset_to_utf8(res, &out, xcharset) > 0 && out) { - octstr_destroy(res); - res = out; - } else - octstr_destroy(out); - out = NULL; - } + charset = mib; /* Copy it over */ } + + if (charset != UTF8_MIB_VAL && charset != US_ASCII_MIB_VAL) { /* Force to UTF-8 */ + const char *_charset = mibenum_to_charset(charset); + Octstr *xcharset = _charset ? octstr_imm(_charset) : NULL; + Octstr *out = NULL; + + if (xcharset != NULL && charset_to_utf8(res, &out, xcharset) > 0 && out) { + octstr_destroy(res); + res = out; + } else + octstr_destroy(out); + } + return res; }