# HG changeset patch # User Evan Schoenberg # Date 1258916166 0 # Node ID 8a90bd0a3b792605da55467a254efe0bba86a622 # Parent 97900b3b55ca4c148d33d5c7a184fb13e39d8202 Plucked d2a1d52b3bbf29baa53b9ddaa635d50b6332064f from im.pidgin.adium by Zac West: Fixed sending DIM messages' encoding. Fixes #9087. The encoding bytes were being written in the wrong location, so the messages were being read back as ASCII and failing conversion, ending up being empty and not being displayed. Plucked f5376d42261b8efc3d889314df9896bb10d3fe16 from im.pidgin.adium: iChat sends direct IM messages with its encoding as 0x000d, which was being forced-interpreted as ASCII. Also, added better debug logging for charset information being received. applied changes from 212bd3655451599364562cabe553c5b7a19134ae through d2a1d52b3bbf29baa53b9ddaa635d50b6332064f applied changes from d2a1d52b3bbf29baa53b9ddaa635d50b6332064f through f5376d42261b8efc3d889314df9896bb10d3fe16 diff -r 97900b3b55ca -r 8a90bd0a3b79 libpurple/protocols/oscar/odc.c --- a/libpurple/protocols/oscar/odc.c Sun Nov 22 18:38:31 2009 +0000 +++ b/libpurple/protocols/oscar/odc.c Sun Nov 22 18:56:06 2009 +0000 @@ -110,8 +110,8 @@ byte_stream_put16(&bs, 0x0000); byte_stream_put16(&bs, 0x0000); byte_stream_put32(&bs, frame->payload.len); - byte_stream_put16(&bs, 0x0000); byte_stream_put16(&bs, frame->encoding); + byte_stream_put16(&bs, 0x0000); byte_stream_put16(&bs, 0x0000); byte_stream_put16(&bs, frame->flags); byte_stream_put16(&bs, 0x0000); diff -r 97900b3b55ca -r 8a90bd0a3b79 libpurple/protocols/oscar/oscar.c --- a/libpurple/protocols/oscar/oscar.c Sun Nov 22 18:38:31 2009 +0000 +++ b/libpurple/protocols/oscar/oscar.c Sun Nov 22 18:56:06 2009 +0000 @@ -438,9 +438,7 @@ purple_plugin_oscar_decode_im_part(PurpleAccount *account, const char *sourcebn, guint16 charset, guint16 charsubset, const gchar *data, gsize datalen) { gchar *ret = NULL; - const gchar *charsetstr1, *charsetstr2; - - purple_debug_info("oscar", "Parsing IM part, charset=0x%04hx, charsubset=0x%04hx, datalen=%" G_GSIZE_FORMAT "\n", charset, charsubset, datalen); + const gchar *charsetstr1, *charsetstr2, *charsetstr3 = NULL; if ((datalen == 0) || (data == NULL)) return NULL; @@ -459,18 +457,32 @@ charsetstr1 = "ASCII"; charsetstr2 = purple_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING); } else if (charset == 0x000d) { - /* Mobile AIM client on a Nokia 3100 and an LG VX6000 */ - charsetstr1 = "ISO-8859-1"; - charsetstr2 = purple_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING); + /* iChat sending unicode over a Direct IM connection = Unicode */ + /* Mobile AIM client on a Nokia 3100 and an LG VX6000 = ISO-8859-1 */ + charsetstr1 = "UTF-16BE"; + charsetstr2 = "UTF-8"; + charsetstr3 = purple_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING); } else { /* Unknown, hope for valid UTF-8... */ charsetstr1 = "UTF-8"; charsetstr2 = purple_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING); } + + purple_debug_info("oscar", "Parsing IM part, charset=0x%04hx, charsubset=0x%04hx, datalen=%" G_GSIZE_FORMAT ", choice1=%s, choice2=%s, choise3=%s\n", + charset, charsubset, datalen, charsetstr1, charsetstr2, (charsetstr3 ? charsetstr3 : "")); ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr1, FALSE); - if (ret == NULL) - ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr2, TRUE); + if (ret == NULL) { + if (charsetstr3 != NULL) { + /* Try charsetstr2 without allowing substitutions, then fall through to charsetstr3 if needed */ + ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr2, FALSE); + if (ret == NULL) + ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr3, TRUE); + } else { + /* Try charsetstr2, allowing substitutions */ + ret = purple_plugin_oscar_convert_to_utf8(data, datalen, charsetstr2, TRUE); + } + } if (ret == NULL) { char *str, *salvage, *tmp; @@ -575,6 +587,9 @@ */ *msg = g_convert(from, -1, "UTF-16BE", "UTF-8", NULL, &msglen, &err); if (*msg != NULL) { + purple_debug_info("oscar", "Conversion from UTF-8 to UTF-16BE results in %s.\n", + *msg); + *charset = AIM_CHARSET_UNICODE; *charsubset = 0x0000; *msglen_int = msglen; @@ -4552,6 +4567,8 @@ } g_string_free(data, TRUE); + purple_debug_info("oscar", "sending direct IM %s using charset %i", msg->str, charset); + peer_odc_send_im(conn, msg->str, msg->len, charset, imflags & PURPLE_MESSAGE_AUTO_RESP); g_string_free(msg, TRUE);