[evolution-patches] Patch for 43790 [Contacts : LDIF Importer improvement]



Hi  Toshok,
I just met some problem with ldif importer and draw up this patch, please help to have a look.

Cheers
-Sean
Index: addressbook/backend/ebook/evolution-ldif-importer.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/backend/ebook/evolution-ldif-importer.c,v
retrieving revision 1.12
diff -u -r1.12 evolution-ldif-importer.c
--- addressbook/backend/ebook/evolution-ldif-importer.c	2 Apr 2003 16:34:32 -0000	1.12
+++ addressbook/backend/ebook/evolution-ldif-importer.c	28 May 2003 08:14:49 -0000
@@ -45,33 +45,55 @@
 static struct {
 	char *ldif_attribute;
 	ECardSimpleField simple_field;
-#define FLAG_ADDRESS 0x01
+#define FLAG_ADDRESS_WORK 0x01
+#define FLAG_ADDRESS_HOME 0x02
 	int flags;
 }
 ldif_fields[] = {
 	{ "cn", E_CARD_SIMPLE_FIELD_FULL_NAME },
 	{ "mail", E_CARD_SIMPLE_FIELD_EMAIL },
+	{ "mozillasecondemail", E_CARD_SIMPLE_FIELD_EMAIL_2 },
 #if 0
 	{ "givenname", E_CARD_SIMPLE_FIELD_GIVEN_NAME },
 #endif
 	{ "sn", E_CARD_SIMPLE_FIELD_FAMILY_NAME },
 	{ "xmozillanickname", E_CARD_SIMPLE_FIELD_NICKNAME },
 	{ "o", E_CARD_SIMPLE_FIELD_ORG },
+	{ "homepostaladdress", 0, FLAG_ADDRESS_HOME },
+	{ "mozillahomepostaladdress2", 0, FLAG_ADDRESS_HOME },
+	{ "mozillahomelocalityname", 0, FLAG_ADDRESS_HOME },
+	{ "mozillahomestate", 0, FLAG_ADDRESS_HOME },
+	{ "mozillahomepostalcode", 0, FLAG_ADDRESS_HOME },
+	{ "mozillahomecountryname", 0, FLAG_ADDRESS_HOME },
+	{ "postaladdress", 0, FLAG_ADDRESS_WORK },
+	{ "mozillapostaladdress2", 0, FLAG_ADDRESS_WORK },
+#if 0
 	{ "locality", 0, FLAG_ADDRESS},
-	{ "st", 0, FLAG_ADDRESS },
+#endif
+	{ "l", 0, FLAG_ADDRESS_WORK},
+	{ "st", 0, FLAG_ADDRESS_WORK },
+#if 0
 	{ "streetaddress", 0, FLAG_ADDRESS },
+#endif 
 	{ "title", E_CARD_SIMPLE_FIELD_TITLE },
-	{ "postalcode", 0, FLAG_ADDRESS },
+	{ "postalcode", 0, FLAG_ADDRESS_WORK },
+#if 0
 	{ "countryname", 0, FLAG_ADDRESS },
+#endif
+	{ "c", 0, FLAG_ADDRESS_WORK },
 	{ "telephonenumber", E_CARD_SIMPLE_FIELD_PHONE_BUSINESS},
 	{ "homephone", E_CARD_SIMPLE_FIELD_PHONE_HOME },
 	{ "facsimiletelephonenumber", E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_FAX },
 	{ "ou", E_CARD_SIMPLE_FIELD_ORG_UNIT },
+#if 0
 	{ "pagerphone", E_CARD_SIMPLE_FIELD_PHONE_PAGER },
 	{ "cellphone", E_CARD_SIMPLE_FIELD_PHONE_MOBILE },
+#endif
+	{ "pager", E_CARD_SIMPLE_FIELD_PHONE_PAGER },
+	{ "mobile", E_CARD_SIMPLE_FIELD_PHONE_MOBILE },
 	{ "homeurl", E_CARD_SIMPLE_FIELD_URL },
 	{ "description", E_CARD_SIMPLE_FIELD_NOTE },
-	{ "xmozillausehtmlmail", E_CARD_SIMPLE_FIELD_WANTS_HTML }
+	{ "xmozillausehtmlmail", E_CARD_SIMPLE_FIELD_WANTS_HTML },
 };
 static int num_ldif_fields = sizeof(ldif_fields) / sizeof (ldif_fields[0]);
 
@@ -196,7 +218,7 @@
 }
 
 static gboolean
-parseLine( ECardSimple *simple, ECardDeliveryAddress *address, char **buf )
+parseLine( ECardSimple *simple, ECardDeliveryAddress *address_work, ECardDeliveryAddress *address_home, char **buf )
 {
 	char *ptr;
 	char *colon, *value;
@@ -241,17 +263,39 @@
 		field_handled = FALSE;
 		for (i = 0; i < num_ldif_fields; i ++) {
 			if (!g_ascii_strcasecmp (ptr, ldif_fields[i].ldif_attribute)) {
-				if (ldif_fields[i].flags & FLAG_ADDRESS) {
-					if (!g_ascii_strcasecmp (ptr, "locality"))
-						address->city = g_strdup (ldif_value->str);
+				if (ldif_fields[i].flags & FLAG_ADDRESS_WORK) {
+					if (!g_ascii_strcasecmp (ptr, "postaladdress"))
+						address_work->po = g_strdup (ldif_value->str);
+					else if (!g_ascii_strcasecmp (ptr, "mozillapostaladdress2"))
+						address_work->ext = g_strdup (ldif_value->str);
+					else if (!g_ascii_strcasecmp (ptr, "locality"))
+						address_work->city = g_strdup (ldif_value->str);
+					else if (!g_ascii_strcasecmp (ptr, "l"))
+						address_work->city = g_strdup (ldif_value->str);
 					else if (!g_ascii_strcasecmp (ptr, "countryname"))
-						address->country = g_strdup (ldif_value->str);
+						address_work->country = g_strdup (ldif_value->str);
+					else if (!g_ascii_strcasecmp (ptr, "c"))
+						address_work->country = g_strdup (ldif_value->str);
 					else if (!g_ascii_strcasecmp (ptr, "postalcode"))
-						address->code = g_strdup (ldif_value->str);
+						address_work->code = g_strdup (ldif_value->str);
 					else if (!g_ascii_strcasecmp (ptr, "st"))
-						address->region = g_strdup (ldif_value->str);
+						address_work->region = g_strdup (ldif_value->str);
 					else if (!g_ascii_strcasecmp (ptr, "streetaddress"))
-						address->street = g_strdup (ldif_value->str);
+						address_work->street = g_strdup (ldif_value->str);
+				}
+				else if (ldif_fields[i].flags & FLAG_ADDRESS_HOME) {
+					if (!g_ascii_strcasecmp (ptr, "homepostaladdress"))
+						address_home->po = g_strdup (ldif_value->str);
+					else if (!g_ascii_strcasecmp (ptr, "mozillahomepostaladdress2"))
+						address_home->ext = g_strdup (ldif_value->str);
+					else if (!g_ascii_strcasecmp (ptr, "mozillahomelocalityname"))
+						address_home->city = g_strdup (ldif_value->str);
+					else if (!g_ascii_strcasecmp (ptr, "mozillahomestate"))
+						address_home->region = g_strdup (ldif_value->str);
+					else if (!g_ascii_strcasecmp (ptr, "mozillahomecountryname"))
+						address_home->country = g_strdup (ldif_value->str);
+					else if (!g_ascii_strcasecmp (ptr, "mozillahomepostalcode"))
+						address_home->code = g_strdup (ldif_value->str);
 				}
 				else {
 					e_card_simple_set (simple, ldif_fields[i].simple_field, ldif_value->str);
@@ -299,7 +343,8 @@
 	ECard *card;
 	ECardAddrLabel *label;
 	ECardSimple *simple;
-	ECardDeliveryAddress *address;
+	ECardDeliveryAddress *address_work;
+	ECardDeliveryAddress *address_home;
 	GString *str;
 	char line[1024];
 	char *buf;
@@ -322,24 +367,39 @@
 	/* now parse that entry */
 	card = e_card_new ("");
 	simple = e_card_simple_new (card);
-	address = e_card_delivery_address_new ();
+	address_work = e_card_delivery_address_new ();
+	address_home = e_card_delivery_address_new ();
 
 	buf = str->str;
 	while (buf) {
-		if (!parseLine (simple, address, &buf)) {
+		if (!parseLine (simple, address_work, address_home, &buf)) {
 			/* parsing error */
 			g_object_unref (simple);
-			e_card_delivery_address_unref (address);
+			e_card_delivery_address_unref (address_work);
+			e_card_delivery_address_unref (address_home);
 			return NULL;
 		}
 	}
 
 
 	/* fill in the address */
-	address->flags = E_CARD_ADDR_HOME;
+	address_work->flags = E_CARD_ADDR_WORK;
+
+	label = e_card_delivery_address_to_label (address_work);
+	e_card_delivery_address_unref (address_work);
+
+	e_card_simple_set_address (simple, E_CARD_SIMPLE_ADDRESS_ID_BUSINESS, label);
+
+	e_card_address_label_unref (label);
+
+/*	
+	e_card_simple_sync_card (simple);
+ */
+
+	address_home->flags = E_CARD_ADDR_HOME;
 
-	label = e_card_delivery_address_to_label (address);
-	e_card_delivery_address_unref (address);
+	label = e_card_delivery_address_to_label (address_home);
+	e_card_delivery_address_unref (address_home);
 
 	e_card_simple_set_address (simple, E_CARD_SIMPLE_ADDRESS_ID_HOME, label);
 


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