From 9346175a64f01dcafbe492cad838c5d8dda99c20 Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Thu, 8 Nov 2012 17:13:07 +0900 Subject: [PATCH] Fixing e_book_backend_sexp_match_contact() for emails and phone numbers This patch fixes the match function to match any phone number or email found in a given vcard, not only the restrictive list of phone number and email types defined in the EContactField enumeration. --- addressbook/libedata-book/e-book-backend-sexp.c | 33 ++++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/addressbook/libedata-book/e-book-backend-sexp.c b/addressbook/libedata-book/e-book-backend-sexp.c index 5f2c090..c8d58f6 100644 --- a/addressbook/libedata-book/e-book-backend-sexp.c +++ b/addressbook/libedata-book/e-book-backend-sexp.c @@ -61,8 +61,7 @@ compare_im (EContact *contact, } } - g_list_foreach (aims, (GFunc) g_free, NULL); - g_list_free (aims); + e_contact_attr_list_free (aims); return found_it; } @@ -154,16 +153,23 @@ compare_email (EContact *contact, gchar * (*compare) (const gchar *, const gchar *)) { - gint i; + gboolean rv = FALSE; + GList *list, *l; + + list = e_contact_get (contact, E_CONTACT_EMAIL); - for (i = E_CONTACT_EMAIL_1; i <= E_CONTACT_EMAIL_4; i++) { - const gchar *email = e_contact_get_const (contact, i); + for (l = list; l; l = l->next) { + const gchar *email = l->data; - if (email && compare (email, str)) - return TRUE; + rv = email && compare (email, str); + + if (rv) + break; } - return FALSE; + e_contact_attr_list_free (list); + + return rv; } static gboolean @@ -172,19 +178,22 @@ compare_phone (EContact *contact, gchar * (*compare) (const gchar *, const gchar *)) { - gint i; + GList *list, *l; gboolean rv = FALSE; - for (i = E_CONTACT_FIRST_PHONE_ID; i <= E_CONTACT_LAST_PHONE_ID; i++) { - gchar *phone = e_contact_get (contact, i); + list = e_contact_get (contact, E_CONTACT_TEL); + + for (l = list; l; l = l->next) { + const gchar *phone = l->data; rv = phone && compare (phone, str); - g_free (phone); if (rv) break; } + e_contact_attr_list_free (list); + return rv; } -- 2.7.4