Ticket #3033 (closed defect: fixed)
messages received from ICQ transport (WINDOW-1251 codepage) is not correctly encoded to UTF-8
| Reported by: | Lucky | Owned by: | asterix |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | xmpppy | Version: | 0.11.1 |
| Severity: | normal | Keywords: | encoding |
| Cc: | OS: |
Description
English is not my native language. Sorry for my English. I'm using Gajim for ICQ transport. My friends use ICQ clients (ICQ, QIP, Miranda, ...) with WINDOWS-1251 codepage. Sending a messages from Gajim to ICQ clients is work. But receiving a messages from ICQ clients is not work. Gajim think that i use ASCII codepage, and Gajim encode incoming messages from ASCII to UTF-8.
Some servers is working, for example - jabber.ru (server is too busy). This can be fixed in jabber client.
Please add an option "Codepage" to the Configuration Dialog, where i can select WINDOWS-1251 codepage; or add environment variable "GAJIM_CODEPAGE".
I don't know Python programming language, but i know Java. I was fixed this problem in JBother client (Jabber client in Java) by patching Smack library (Jabber Java library for JBother).
Fixed org.jivesoftware.smack.packet.Message class - org/jivesoftware/smack/packet/Message.java:
...
public String getBody() {
// my code begin
String codepage = null;
try {
// "SMACK_CODEPAGE" is environment variable, set to "WINDOWS-1251" for me
codepage = System.getenv("SMACK_CODEPAGE");
} catch (Exception ex) {}
if (codepage != null)
{
char[] buf = new char[body.length]; // body is message body, char = 2 bytes (useful for UNICODE)
body.getChars(0, body.length(), buf, 0);
try
{
mesgBody = ""; // new message body
for (int i = 0; i < buf.length; i++)
{
if ((buf[i] & 0xff00) == 0) // high byte = 0 -> not unicode
{
byte[] ch = new byte[1]; // 1-byte char
ch[0] = (byte) buf[i];
mesgBody = mesgBody + new String(ch, codepage); // encode from 'codepage' to UTF-8
} else mesgBody = mesgBody + buf[i]; // unicode
}
} catch (Exception ex) { mesgBody = body; }
body = mesgBody;
}
// my code end
return body; }
...
