[evolution-mapi] Bug #635078 - Do not write unicode markers in UTF16 strings



commit 67f0f43fe42b714d36508c8bafe26fda366cc8ca
Author: Milan Crha <mcrha redhat com>
Date:   Tue Nov 23 12:58:05 2010 +0100

    Bug #635078 - Do not write unicode markers in UTF16 strings

 src/camel/camel-mapi-utils.c                   |    6 +++++-
 src/libexchangemapi/exchange-mapi-connection.c |    7 ++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/src/camel/camel-mapi-utils.c b/src/camel/camel-mapi-utils.c
index 4d6a2dd..8018ef2 100644
--- a/src/camel/camel-mapi-utils.c
+++ b/src/camel/camel-mapi-utils.c
@@ -175,7 +175,11 @@ mail_item_set_body_stream (MailItem *item, CamelStream *body, MailItemPartType p
 		in_unicode = g_convert ((const gchar *)stream->value->data, stream->value->len, "UTF-16", "UTF-8", NULL, &written, NULL);
 		if (in_unicode && written > 0) {
 			g_byte_array_set_size (stream->value, 0);
-			g_byte_array_append (stream->value, (const guint8 *) in_unicode, written);
+			/* skip Unicode marker, if there */
+			if (written >= 2 && (const guchar) in_unicode[0] == 0xFF && (const guchar) in_unicode[1] == 0xFE)
+				g_byte_array_append (stream->value, (const guint8 *) in_unicode + 2, written - 2);
+			else
+				g_byte_array_append (stream->value, (const guint8 *) in_unicode, written);
 
 			/* null-terminated unicode string */
 			g_byte_array_append (stream->value, (const guint8 *)"", 1);
diff --git a/src/libexchangemapi/exchange-mapi-connection.c b/src/libexchangemapi/exchange-mapi-connection.c
index 09527e5..c285365 100644
--- a/src/libexchangemapi/exchange-mapi-connection.c
+++ b/src/libexchangemapi/exchange-mapi-connection.c
@@ -484,7 +484,12 @@ set_stream_value (ExchangeMAPIStream *stream, const uint32_t *cpid, const guint8
 		gsize written = 0;
 		gchar *in_utf8;
 
-		in_utf8 = g_convert ((const gchar *) buf_data, buf_len, "UTF-8", "UTF-16", NULL, &written, NULL);
+		/* skip Unicode marker, if there */
+		if (buf_len >= 2 && buf_data[0] == 0xFF && buf_data[1] == 0xFE)
+			in_utf8 = g_convert ((const gchar *) buf_data + 2, buf_len - 2, "UTF-8", "UTF-16", NULL, &written, NULL);
+		else
+			in_utf8 = g_convert ((const gchar *) buf_data, buf_len, "UTF-8", "UTF-16", NULL, &written, NULL);
+
 		if (in_utf8 && written > 0) {
 			stream->value = g_byte_array_sized_new (written + 1);
 			g_byte_array_append (stream->value, (const guint8 *) in_utf8, written);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]