pidgin: 3053d6a3: MSN Patch from Thijs (xnyhps) Alkemade w...

masca at cpw.pidgin.im masca at cpw.pidgin.im
Fri Jan 20 00:20:52 EST 2012


----------------------------------------------------------------------
Revision: 3053d6a37cc6d8774aba7607b992a4408216adcd
Parent:   60f8379d0a610538cf42e0dd9ab1436c8b9308cd
Author:   thijsalkemade at gmail.com
Date:     01/20/12 00:15:22
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/3053d6a37cc6d8774aba7607b992a4408216adcd

Changelog: 

MSN Patch from Thijs (xnyhps) Alkemade which do verify/convert to UTF-8
incoming OIM.

Fixes #14884

Changes against parent 60f8379d0a610538cf42e0dd9ab1436c8b9308cd

  patched  libpurple/protocols/msn/oim.c

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/oim.c	00d90adb900e220d1660adb62c689f4075926769
+++ libpurple/protocols/msn/oim.c	a33b539ae69ec24d7260fb3c7d21df6e477a7893
@@ -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,47 @@ 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 && !(purple_utf8_strcasecmp(charset, "UTF-8") || purple_utf8_strcasecmp(charset, "UTF8"))) {
+		clean_msg = g_convert(decode_msg, strlen(decode_msg), "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", charset, clean);
+
+			msn_oim_post_delete_msg(rdata);
+			msn_message_unref(message);
+
+			g_free(decode_msg);
+			g_free(clean);
+
+			return;
+		}
+
+		g_free(decode_msg);
+
+	} else {
+		if (!g_utf8_validate(decode_msg, -1, 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", clean);
+
+			msn_oim_post_delete_msg(rdata);
+			msn_message_unref(message);
+
+			g_free(decode_msg);
+			g_free(clean);
+
+			return;
+		}
+
+		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 +737,7 @@ msn_oim_report_to_user(MsnOimRecvData *r
 	purple_debug_info("msn", "oim Date:{%s},passport{%s}\n",
 	                  date, passport);
 
-	serv_got_im(purple_account_get_connection(rdata->oim->session->account), 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 +746,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