[Commits] vcard-utils.c 1.3 1.4

miras at claws-mail.org miras at claws-mail.org
Tue Aug 7 19:52:35 CEST 2012


Update of /home/claws-mail/contacts/libversit
In directory srv:/tmp/cvs-serv19823/libversit

Modified Files:
	vcard-utils.c 
Log Message:
2012-08-07 [mir]	0.6.0cvs88

	* libversit/vcard-utils.c
	    Fix parsing of attribute N (VCNameProp)

Index: vcard-utils.c
===================================================================
RCS file: /home/claws-mail/contacts/libversit/vcard-utils.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- vcard-utils.c	3 Jul 2012 00:15:15 -0000	1.3
+++ vcard-utils.c	7 Aug 2012 17:52:33 -0000	1.4
@@ -332,6 +332,7 @@
 	void* value;
 	const gchar* type;
 	gchar* version;
+	const gchar* name = NULL;
 
 	cm_return_val_if_fail(plugin != NULL, NULL);
 	cm_return_val_if_fail(vcard != NULL, NULL);
@@ -348,67 +349,92 @@
 	initPropIterator(&iter,vcard);
 	while (moreIteration(&iter)) {
 		VObject* prop = nextVObject(&iter);
-		gchar* attrib = vcard2native(prop, version, type);
-		if (strcmp(attrib, "last-name") == 0) {
-			value = vcard_value(prop);
-			if (value) {
-				if (family) {
-					gchar* tmp = g_strdup(family);
-					g_free(family);
-					family = g_strconcat(tmp, " ", value, NULL);
-					g_free(tmp);
-				}
-				else
+		name = vObjectName(prop);
+		if (strcmp(VCNameProp, name) == 0) {
+			/* composite name property */
+			VObjectIterator name_iter;
+			initPropIterator(&name_iter, prop);
+			while (moreIteration(&name_iter)) {
+				VObject *prop = nextVObject(&name_iter);
+				gchar* attrib = vcard2native(prop, version, type);
+				value = vcard_value(prop);
+				if (strcmp(attrib, "last-name") == 0 && value) {
+					/* maybe more later */
+					debug_print("adding: family -> %s\n", value);
 					family = g_strdup(value);
+				}
+				else {
+					if (value) {
+						debug_print("adding: %s -> %s\n", attrib, value);
+						swap_data(contact->data, attrib, value);
+					}
+				}
+				g_free(attrib);
 				g_free(value);
 			}
 		}
-		else if (strcmp(attrib, "addn") == 0) {
-			value = vcard_value(prop);
-			if (value) {
-				if (family) {
-					gchar* tmp = g_strdup(family);
-					g_free(family);
-					family = g_strconcat(value, " ", tmp, NULL);
-					g_free(tmp);
+		else {
+			gchar* attrib = vcard2native(prop, version, type);
+			if (strcmp(attrib, "last-name") == 0) {
+				value = vcard_value(prop);
+				if (value) {
+					if (family) {
+						gchar* tmp = g_strdup(family);
+						g_free(family);
+						family = g_strconcat(tmp, " ", value, NULL);
+						g_free(tmp);
+					}
+					else
+						family = g_strdup(value);
+					g_free(value);
 				}
-				else
-					family = g_strdup(value);
-				g_free(value);
 			}
-		}
-		else if (strcmp(attrib, "email") == 0) {
-			value = vcard_value(prop);
-			if (value) {
-				Email* e = g_new0(Email, 1);
-				e->email = g_strdup(value);
-				if (debug_get_mode())
-					email_dump(e, stderr);
-				contact->emails = g_slist_append(contact->emails, e);
-				g_free(value);
+			else if (strcmp(attrib, "addn") == 0) {
+				value = vcard_value(prop);
+				if (value) {
+					if (family) {
+						gchar* tmp = g_strdup(family);
+						g_free(family);
+						family = g_strconcat(value, " ", tmp, NULL);
+						g_free(tmp);
+					}
+					else
+						family = g_strdup(value);
+					g_free(value);
+				}
 			}
-		}
-		else if (strcmp(attrib, "image") == 0) {
-			value = vcard_value(prop);
-			if (value) {
-				/* Remove whitespace from badly formated string */
-				strip_whitespace((gchar **) &value);
-				debug_print("adding: %s -> %s\n", attrib, value);
-				swap_data(contact->data, attrib, value);
-				g_free(value);
+			else if (strcmp(attrib, "email") == 0) {
+				value = vcard_value(prop);
+				if (value) {
+					Email* e = g_new0(Email, 1);
+					e->email = g_strdup(value);
+					if (debug_get_mode())
+						email_dump(e, stderr);
+					contact->emails = g_slist_append(contact->emails, e);
+					g_free(value);
+				}
 			}
-		}
-		else {
-			value = vcard_value(prop);
-			if (value) {
-				debug_print("adding: %s -> %s\n", attrib, value);
-				swap_data(contact->data, attrib, value);
-				g_free(value);
+			else if (strcmp(attrib, "image") == 0) {
+				value = vcard_value(prop);
+				if (value) {
+					/* Remove whitespace from badly formated string */
+					strip_whitespace((gchar **) &value);
+					debug_print("adding: %s -> %s\n", attrib, value);
+					swap_data(contact->data, attrib, value);
+					g_free(value);
+				}
+			}
+			else {
+				value = vcard_value(prop);
+				if (value) {
+					debug_print("adding: %s -> %s\n", attrib, value);
+					swap_data(contact->data, attrib, value);
+					g_free(value);
+				}
 			}
+			g_free(attrib);
 		}
-		g_free(attrib);
 	}
-	
 	if (family) {
 		debug_print("adding: last-name -> %s\n", family);
 		swap_data(contact->data, "last-name", family);
@@ -1233,4 +1259,4 @@
 Contact* vcard_ptr2contact(Plugin* plugin, const gchar* vcard, gint len, gchar** error) {
 	VObject* o = Parse_MIME(vcard, len);
 	return vcard2contact(o, plugin, error);
-}
\ No newline at end of file
+}



More information about the Commits mailing list