[sylpheed:37158] vCard nickname

Kent Friis leeloored at gmx.com
Tue Nov 29 07:35:08 JST 2022


Resending because it appears to have been lost the first time.

I've moved my contacts to a vCard file for easier syncing with other
software and devices, and noticed that I could no longer search by nick
names.

This patch (on top of 3.7) adds nickname search for vCards:

--- src/vcard.h.orig	2022-10-28 22:25:03.602103426 +0200
+++ src/vcard.h	2022-10-28 22:25:10.361982197 +0200
@@ -39,6 +39,7 @@
 #define	VCARD_NAME         "vcard"
 
 #define	VCARD_TAG_FULLNAME "fn"
+#define VCARD_TAG_NICKNAME "nickname"
 #define VCARD_TAG_NAME     "n"
 #define	VCARD_TAG_EMAIL    "email"
 #define VCARD_TAG_UID      "uid"
--- src/vcard.c.orig	2022-10-28 22:25:06.114058377 +0200
+++ src/vcard.c	2022-10-28 22:25:56.592153339 +0200
@@ -252,15 +252,16 @@
 	g_strstrip(buf);
 	cardFile->bufptr = end + 1;
 
-	/* Return a copy of buffer */	
+	/* Return a copy of buffer */
 	return g_strdup( buf );
 }
 
 /*
 * Free linked lists of character strings.
 */
-static void vcard_free_lists( GSList *listName, GSList *listAddr, GSList *listRem, GSList* listID ) {
+static void vcard_free_lists( GSList *listName, GSList *listNick, GSList *listAddr, GSList *listRem, GSList* listID ) {
 	mgu_free_list( listName );
+	mgu_free_list( listNick );
 	mgu_free_list( listAddr );
 	mgu_free_list( listRem );
 	mgu_free_list( listID );
@@ -368,10 +369,11 @@
 /*
 * Build an address list entry and append to list of address items.
 */
-static void vcard_build_items( VCardFile *cardFile, GSList *listName, GSList *listAddr, GSList *listRem,
+static void vcard_build_items( VCardFile *cardFile, GSList *listName, GSList *listNick, GSList *listAddr, GSList *listRem,
 				GSList *listID )
 {
 	GSList *nodeName = listName;
+	GSList *nodeNick = listNick;
 	GSList *nodeID = listID;
 	gchar *str;
 	while( nodeName ) {
@@ -379,6 +381,9 @@
 		GSList *nodeRemarks = listRem;
 		ItemPerson *person = addritem_create_item_person();
 		addritem_person_set_common_name( person, nodeName->data );
+		if( nodeNick ) {
+			addritem_person_set_nick_name( person, nodeNick->data );
+		}
 		while( nodeAddress ) {
 			str = nodeAddress->data;
 			if( *str != '\0' ) {
@@ -467,7 +472,7 @@
 */
 static void vcard_read_file( VCardFile *cardFile ) {
 	gchar *tagtemp = NULL, *tagname = NULL, *tagvalue = NULL, *tagtype = NULL;
-	GSList *listName = NULL, *listAddress = NULL, *listRemarks = NULL, *listID = NULL;
+	GSList *listName = NULL, *listNick = NULL, *listAddress = NULL, *listRemarks = NULL, *listID = NULL;
 	/* GSList *listQP = NULL; */
 
 	for( ;; ) {
@@ -515,13 +520,17 @@
 		if( g_ascii_strcasecmp( tagname, VCARD_TAG_START ) == 0 &&
 			g_ascii_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {
 			/* fprintf( stdout, "start card\n" ); */
-			vcard_free_lists( listName, listAddress, listRemarks, listID );
-			listName = listAddress = listRemarks = listID = NULL;
+			vcard_free_lists( listName, listNick, listAddress, listRemarks, listID );
+			listName = listNick = listAddress = listRemarks = listID = NULL;
 		}
 		if( g_ascii_strcasecmp( tagname, VCARD_TAG_FULLNAME ) == 0 ) {
 			/* fprintf( stdout, "- full name: %s\n", tagvalue ); */
 			listName = g_slist_append( listName, g_strdup( tagvalue ) );
 		}
+		if( g_ascii_strcasecmp( tagname, VCARD_TAG_NICKNAME ) == 0 ) {
+			/* fprintf( stdout, "- nickname: %s\n", tagvalue ); */
+			listNick = g_slist_append( listNick, g_strdup( tagvalue ) );
+		}
 		if( g_ascii_strcasecmp( tagname, VCARD_TAG_EMAIL ) == 0 ) {
 			/* fprintf( stdout, "- address: %s\n", tagvalue ); */
 			listAddress = g_slist_append( listAddress, g_strdup( tagvalue ) );
@@ -536,9 +545,9 @@
 			/* vCard is complete */
 			/* fprintf( stdout, "end card\n--\n" ); */
 			/* vcard_dump_lists( listName, listAddress, listRemarks, listID, stdout ); */
-			vcard_build_items( cardFile, listName, listAddress, listRemarks, listID );
-			vcard_free_lists( listName, listAddress, listRemarks, listID );
-			listName = listAddress = listRemarks = listID = NULL;
+			vcard_build_items( cardFile, listName, listNick, listAddress, listRemarks, listID );
+			vcard_free_lists( listName, listNick, listAddress, listRemarks, listID );
+			listName = listNick = listAddress = listRemarks = listID = NULL;
 		}
 
 		g_free( tagname );
@@ -549,8 +558,8 @@
 	}
 
 	/* Free lists */
-	vcard_free_lists( listName, listAddress, listRemarks, listID );
-	listName = listAddress = listRemarks = listID = NULL;
+	vcard_free_lists( listName, listNick, listAddress, listRemarks, listID );
+	listName = listNick, listAddress = listRemarks = listID = NULL;
 }
 
 /* ============================================================================================ */


More information about the Sylpheed mailing list