evolution-data-server r9774 - in trunk/addressbook: . libebook



Author: mcrha
Date: Wed Nov 19 15:14:42 2008
New Revision: 9774
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9774&view=rev

Log:
2008-11-19  Milan Crha  <mcrha redhat com>

	** Fix for bug #560681

	* libebook/e-vcard.c: (read_attribute_value), (read_attribute_params),
	(read_attribute): Support CHARSET parameter within the attribute and
	convert text to UTF-8, if necessary, based on its value.



Modified:
   trunk/addressbook/ChangeLog
   trunk/addressbook/libebook/e-vcard.c

Modified: trunk/addressbook/libebook/e-vcard.c
==============================================================================
--- trunk/addressbook/libebook/e-vcard.c	(original)
+++ trunk/addressbook/libebook/e-vcard.c	Wed Nov 19 15:14:42 2008
@@ -223,7 +223,7 @@
 }
 
 static void
-read_attribute_value (EVCardAttribute *attr, char **p, gboolean quoted_printable)
+read_attribute_value (EVCardAttribute *attr, char **p, gboolean quoted_printable, const char *charset)
 {
 	char *lp = *p;
 	GString *str;
@@ -289,6 +289,16 @@
 		}
 		else if ((*lp == ';') ||
 			 (*lp == ',' && !g_ascii_strcasecmp (attr->name, "CATEGORIES"))) {
+			if (charset) {
+				char *tmp;
+
+				tmp = g_convert (str->str, str->len, "UTF-8", charset, NULL, NULL, NULL);
+				if (tmp) {
+					g_string_assign (str, tmp);
+					g_free (tmp);
+				}
+			}
+
 			e_vcard_attribute_add_value (attr, str->str);
 			g_string_assign (str, "");
 			lp = g_utf8_next_char(lp);
@@ -299,6 +309,16 @@
 		}
 	}
 	if (str) {
+		if (charset) {
+			char *tmp;
+
+			tmp = g_convert (str->str, str->len, "UTF-8", charset, NULL, NULL, NULL);
+			if (tmp) {
+				g_string_assign (str, tmp);
+				g_free (tmp);
+			}
+		}
+
 		e_vcard_attribute_add_value (attr, str->str);
 		g_string_free (str, TRUE);
 	}
@@ -309,7 +329,7 @@
 }
 
 static void
-read_attribute_params (EVCardAttribute *attr, char **p, gboolean *quoted_printable)
+read_attribute_params (EVCardAttribute *attr, char **p, gboolean *quoted_printable, char **charset)
 {
 	char *lp;
 	GString *str;
@@ -389,6 +409,13 @@
 					*quoted_printable = TRUE;
 					e_vcard_attribute_param_free (param);
 					param = NULL;
+				} else if (param
+				    && !g_ascii_strcasecmp (param->name, "charset")
+				    && g_ascii_strcasecmp (param->values->data, "utf-8") != 0) {
+					g_free (*charset);
+					*charset = g_strdup (param->values->data);
+					e_vcard_attribute_param_free (param);
+					param = NULL;
 				}
 			}
 			else {
@@ -468,6 +495,7 @@
 	GString *str;
 	char *lp;
 	gboolean is_qp = FALSE;
+	char *charset = NULL;
 
 	/* first read in the group/name */
 	str = g_string_new ("");
@@ -533,16 +561,18 @@
 	if (*lp == ';') {
 		/* skip past the ';' */
 		lp = g_utf8_next_char(lp);
-		read_attribute_params (attr, &lp, &is_qp);
+		read_attribute_params (attr, &lp, &is_qp, &charset);
 		if (is_qp)
 			attr->encoding = EVC_ENCODING_RAW;
 	}
 	if (*lp == ':') {
 		/* skip past the ':' */
 		lp = g_utf8_next_char(lp);
-		read_attribute_value (attr, &lp, is_qp);
+		read_attribute_value (attr, &lp, is_qp, charset);
 	}
 
+	g_free (charset);
+
 	*p = lp;
 
 	if (!attr->values)



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