# HG changeset patch # User Luke Schierer # Date 1080886005 0 # Node ID 832fd9b754d0a78c1ef89434a7f034353f48de99 # Parent 1c20aa5bd38917fac5c57b41313b2c08fb05b5db [gaim-migrate @ 9304] " Here's a patch for the problem larsl_school reported on #gaim on the 13th, mostly taken from the irc plugin. Whenever an incoming im (or chat message) doesn't parse as utf-8, it will be automatically interpreted as a byte stream in a fallback character set, (defaulting to iso-8859-1), and converted to utf-8. It adds an option to the zephyr plugin, "Encoding", which is a translateable string. It still sends outgoing messages as utf-8 though. (06:57:06) larsl_school: Hello, I'm using Gaim 0.71 in school and when I get a Zephyr message containing swedish characters from the zwrite client, Gaim just displays the whole message as an empty string? (07:04:00) larsl_school: In the logs it looks like GAIM is using UTF-8, but the messages from zwrite are coded as extended ASCII. Can I make GAIM understand extended ASCII (or at least display the parts of the message that is normal ASCII)?" --Arun A Tharuvai apparently there are TWO gaim zepher users! committer: Tailor Script diff -r 1c20aa5bd389 -r 832fd9b754d0 src/protocols/zephyr/zephyr.c --- a/src/protocols/zephyr/zephyr.c Fri Apr 02 06:05:05 2004 +0000 +++ b/src/protocols/zephyr/zephyr.c Fri Apr 02 06:06:45 2004 +0000 @@ -37,6 +37,8 @@ #include +#define ZEPHYR_FALLBACK_CHARSET "ISO-8859-1" + extern Code_t ZGetLocations(ZLocations_t *, int *); extern Code_t ZSetLocation(char *); extern Code_t ZUnsetLocation(); @@ -181,6 +183,25 @@ return NULL; } +static gchar *zephyr_recv_convert(char *string, int len) +{ + gchar *utf8; + GError *err = NULL; + if (g_utf8_validate(string,len,NULL)) { + return g_strdup(string); + } else { + utf8 = g_convert(string, len, "UTF-8", + gaim_account_get_string(zgc->account, "encoding", ZEPHYR_FALLBACK_CHARSET), + NULL, NULL, &err); + if (err) { + gaim_debug(GAIM_DEBUG_ERROR, "zephyr", "recv conversion error: %s\n", err->message); + utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)")); + } + + return utf8; + } +} + /* utility macros that are useful for zephyr_to_html */ #define IS_OPENER(c) ((c == '{') || (c == '[') || (c == '(') || (c == '<')) @@ -551,7 +572,7 @@ free(user); } } else { - char *buf, *buf2; + char *buf, *buf2, *buf3; char *send_inst; char *realmptr; GaimConversation *gconv1; @@ -562,18 +583,21 @@ GaimConvImFlags flags = 0; if (len > 0) { gchar* tmpescape; - buf = g_malloc(len + 1); - g_snprintf(buf, len + 1, "%s", ptr); - g_strchomp(buf); + buf = g_malloc(len + 1); + g_snprintf(buf, len + 1, "%s", ptr); + g_strchomp(buf); tmpescape = gaim_escape_html(buf); - buf2 = zephyr_to_html(tmpescape); - g_free(buf); + buf2 = zephyr_to_html(tmpescape); + buf3 = zephyr_recv_convert(buf2,strlen(buf2)); + g_free(buf2); + g_free(buf); g_free(tmpescape); + if (!g_ascii_strcasecmp(notice.z_class, "MESSAGE") && !g_ascii_strcasecmp(notice.z_class_inst, "PERSONAL")) { if (!g_ascii_strcasecmp(notice.z_message, "Automated reply:")) flags |= GAIM_CONV_IM_AUTO_RESP; - serv_got_im(zgc, notice.z_sender, buf2, flags, time(NULL)); + serv_got_im(zgc, notice.z_sender, buf3, flags, time(NULL)); } else { zephyr_triple *zt1, *zt2; zt1 = new_triple(notice.z_class, notice.z_class_inst, @@ -610,7 +634,7 @@ send_inst = g_strdup_printf("%s %s",sendertmp,notice.z_class_inst); } serv_got_chat_in(zgc, zt2->id, send_inst, FALSE, - buf2, time(NULL)); + buf3, time(NULL)); gconv1 = gaim_find_conversation_with_account(zt2->name,zgc->account); gcc = gaim_conversation_get_chat_data(gconv1); @@ -634,7 +658,7 @@ } free_triple(zt1); } - g_free(buf2); + g_free(buf3); } } } @@ -1397,6 +1421,9 @@ option = gaim_account_option_string_new(_("Exposure"),"exposure_level",tmp?tmp:EXPOSE_REALMVIS); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,option); + option = gaim_account_option_string_new(_("Encoding"),"encoding",ZEPHYR_FALLBACK_CHARSET); + prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,option); + my_protocol = plugin; }