pidgin.2.x.y: 18f2f94b: Pluck fixes for OIM charset conversion.

qulogic at pidgin.im qulogic at pidgin.im
Mon Feb 6 18:15:52 EST 2012


----------------------------------------------------------------------
Revision: 18f2f94b625542348af0049e0132a83a1c58aef6
Parent:   45b32bd976a53321655f7569fa217c60e8c9b965
Author:   qulogic at pidgin.im
Date:     02/06/12 17:42:32
Branch:   im.pidgin.pidgin.2.x.y
URL: http://d.pidgin.im/viewmtn/revision/info/18f2f94b625542348af0049e0132a83a1c58aef6

Changelog: 

Pluck fixes for OIM charset conversion.

*** Plucked rev 3053d6a37cc6d8774aba7607b992a4408216adcd (thijsalkemade at gmail.com):
MSN Patch from Thijs (xnyhps) Alkemade which do verify/convert to UTF-8
incoming OIM.

Fixes #14884

*** Plucked rev ecabfaee8a1ca02e18ebadbb41cdcce19e78bc2e (masca at cpw.pidgin.im):
Apply second patch from xnyhps this time to show the message salvaged to user.

Refs #14884

*** Plucked rev b1b8c222ab921963f43e83502b6c6e2e4489a8c4 (qulogic at pidgin.im):
Add newlines to debug messages, and word-wrap lines.

*** Plucked rev fdb56683f2b5f88f7b388aaef6c53c810d19e374 (qulogic at pidgin.im):
We know the length of decode_msg here.

*** Plucked rev f12c9f6a6c31bcd3512f162209285a88a86595ff (qulogic at pidgin.im):
This extra if-level can be dropped.

Changes against parent 45b32bd976a53321655f7569fa217c60e8c9b965

  patched  libpurple/protocols/msn/oim.c

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/oim.c	2a81eabd7aa57fccd6708da34d6b477abd06a967
+++ libpurple/protocols/msn/oim.c	8ea1823a55e70a81a8b2a976fd3b5d5232d74cfb
@@ -606,11 +606,12 @@ msn_oim_report_to_user(MsnOimRecvData *r
 	const char *date;
 	const char *from;
 	const char *boundary;
-	char *decode_msg = NULL;
+	char *decode_msg = NULL, *clean_msg = NULL;
 	gsize body_len;
 	char **tokens;
 	char *passport = NULL;
 	time_t stamp;
+	const char *charset = NULL;
 
 	message = msn_message_new(MSN_MSG_UNKNOWN);
 
@@ -638,6 +639,8 @@ msn_oim_report_to_user(MsnOimRecvData *r
 			type = msn_message_get_content_type(multipart);
 			if (type && !strcmp(type, "text/plain")) {
 				decode_msg = (char *)purple_base64_decode(multipart->body, &body_len);
+				charset = msn_message_get_charset(multipart);
+
 				msn_message_unref(multipart);
 				break;
 			}
@@ -654,8 +657,48 @@ msn_oim_report_to_user(MsnOimRecvData *r
 		}
 	} else {
 		decode_msg = (char *)purple_base64_decode(message->body, &body_len);
+		charset = msn_message_get_charset(message);
 	}
 
+	if (charset && !((strncasecmp(charset, "UTF-8", 5) == 0) || (strncasecmp(charset, "UTF8", 4) == 0))) {
+		clean_msg = g_convert(decode_msg, body_len, "UTF-8", charset, NULL, NULL, NULL);
+
+		if (!clean_msg) {
+			char *clean = purple_utf8_salvage(decode_msg);
+
+			purple_debug_error("msn", "Failed to convert charset from %s to UTF-8 for OIM message: %s\n", charset, clean);
+
+			clean_msg = g_strdup_printf(_("%s (There was an error receiving this message. "
+			                              "Converting the encoding from %s to UTF-8 failed.)"),
+			                            clean, charset);
+			g_free(clean);
+		}
+
+		g_free(decode_msg);
+
+	} else if (!g_utf8_validate(decode_msg, body_len, NULL)) {
+		char *clean = purple_utf8_salvage(decode_msg);
+
+		purple_debug_error("msn", "Received an OIM message that is not UTF-8,"
+		                          " and no encoding specified: %s\n", clean);
+
+		if (charset) {
+			clean_msg = g_strdup_printf(_("%s (There was an error receiving this message."
+			                              " The charset was %s, but it was not valid UTF-8.)"),
+			                            clean, charset);
+		} else {
+			clean_msg = g_strdup_printf(_("%s (There was an error receiving this message."
+			                              " The charset was missing, but it was not valid UTF-8.)"),
+			                            clean);
+		}
+
+		g_free(clean);
+		g_free(decode_msg);
+
+	} else {
+		clean_msg = decode_msg;
+	}
+
 	from = msn_message_get_header_value(message, "X-OIM-originatingSource");
 
 	/* Match number to user's mobile number, FROM is a phone number
@@ -695,7 +738,7 @@ msn_oim_report_to_user(MsnOimRecvData *r
 	purple_debug_info("msn", "oim Date:{%s},passport{%s}\n",
 	                  date, passport);
 
-	serv_got_im(rdata->oim->session->account->gc, passport, decode_msg, 0,
+	serv_got_im(purple_account_get_connection(rdata->oim->session->account), passport, clean_msg, 0,
 	            stamp);
 
 	/*Now get the oim message ID from the oim_list.
@@ -704,7 +747,7 @@ msn_oim_report_to_user(MsnOimRecvData *r
 	msn_oim_post_delete_msg(rdata);
 
 	g_free(passport);
-	g_free(decode_msg);
+	g_free(clean_msg);
 	msn_message_unref(message);
 }
 


More information about the Commits mailing list