Me card contact is normally a OssoABookContact and not a EContact
[modest] / src / hildon2 / modest-address-book.c
index b90d7f1..b26a597 100644 (file)
@@ -671,13 +671,31 @@ select_email_addrs_for_contact(GList * email_addr_list)
        return selected_email_addr_list;
 }
 
+/* Assumes that the second argument (the user provided one) is a pure
+   email address without name */
+static gint
+compare_addresses (const gchar *address1,
+                  const gchar *mail2)
+{
+       gint retval;
+       gchar *mail1;
+
+       mail1 = modest_text_utils_get_email_address (address1);
+       retval = g_strcmp0 (mail1, mail2);
+       g_free (mail1);
+
+       return retval;
+}
+
 static EContact *
 get_contact_for_address (GList *contacts,
                         const gchar *address)
 {
        EContact *retval = NULL, *contact;
        GList *iter;
+       gchar *email;
 
+       email = modest_text_utils_get_email_address (address);
        iter = contacts;
        while (iter && !retval) {
                GList *emails = NULL;
@@ -686,7 +704,7 @@ get_contact_for_address (GList *contacts,
                emails = e_contact_get (contact, E_CONTACT_EMAIL);
                if (emails) {
                        /* Look for the email address */
-                       if (g_list_find_custom (emails, address, (GCompareFunc) g_strcmp0))
+                       if (g_list_find_custom (emails, email, (GCompareFunc) compare_addresses))
                                retval = contact;
 
                        /* Free the list */
@@ -695,6 +713,8 @@ get_contact_for_address (GList *contacts,
                }
                iter = g_list_next (iter);
        }
+       g_free (email);
+
        return retval;
 }
 
@@ -1336,5 +1356,14 @@ modest_address_book_get_my_name ()
 {
        OssoABookSelfContact *self_contact = osso_abook_self_contact_get_default ();
 
-       return osso_abook_contact_get_display_name (OSSO_ABOOK_CONTACT (self_contact));
+       /* We are not using osso_abook_contact_get_display_name
+          because that method fallbacks to another fields if the name
+          is not defined */
+       if (self_contact)
+               if (OSSO_ABOOK_IS_CONTACT (self_contact))
+                       return osso_abook_contact_get_name ((OssoABookContact*)self_contact);
+               else
+                       return e_contact_get ((EContact *) self_contact, E_CONTACT_NAME);
+       else
+               return NULL;
 }