* Set the proper status of the mail operation
[modest] / src / maemo / modest-address-book.c
index f97f647..be1db54 100644 (file)
@@ -586,6 +586,7 @@ add_to_address_book (const gchar* address)
        EBookQuery *query;
        GList *contacts = NULL;
        GError *err = NULL;
+       gchar *email;
        
        g_return_val_if_fail (address, FALSE);
        
@@ -593,8 +594,10 @@ add_to_address_book (const gchar* address)
                open_addressbook ();
        
        g_return_val_if_fail (book, FALSE);
+
+       email = modest_text_utils_get_email_address (address);
        
-       query = e_book_query_field_test (E_CONTACT_EMAIL, E_BOOK_QUERY_IS, address);
+       query = e_book_query_field_test (E_CONTACT_EMAIL, E_BOOK_QUERY_IS, email);
        if (!e_book_get_contacts (book, query, &contacts, &err)) {
                g_printerr ("modest: failed to get contacts: %s",
                            err ? err->message : "<unknown>");
@@ -616,12 +619,22 @@ add_to_address_book (const gchar* address)
        } else {
                /* it's not yet in the addressbook, add it now! */
                EContact *new_contact = e_contact_new ();
-               e_contact_set (new_contact, E_CONTACT_EMAIL_1, (const gpointer)address);
+               gchar *display_address;
+               display_address = g_strdup (address);
+               if (display_address) {
+                       modest_text_utils_get_display_address (display_address);
+                       if ((display_address[0] != '\0') && (strlen (display_address) != strlen (address)))
+                               e_contact_set (new_contact, E_CONTACT_FULL_NAME, (const gpointer)display_address);
+               }
+               e_contact_set (new_contact, E_CONTACT_EMAIL_1, (const gpointer)email);
+               g_free (display_address);
                commit_contact (new_contact, TRUE);
                g_debug ("%s added to address book", address);
                g_object_unref (new_contact);
        }
 
+       g_free (email);
+
        return TRUE;
 }
 
@@ -677,6 +690,7 @@ modest_address_book_check_names (ModestRecptEditor *recpt_editor, gboolean updat
                gchar *start_ptr, *end_ptr;
                gint start_pos, end_pos;
                const gchar *invalid_char_position = NULL;
+               gboolean store_address = FALSE;
 
                start_pos = (*((gint*) current_start->data)) + offset_delta;
                end_pos = (*((gint*) current_end->data)) + offset_delta;
@@ -749,13 +763,14 @@ modest_address_book_check_names (ModestRecptEditor *recpt_editor, gboolean updat
                                                                                     address_list, 
                                                                                     "");
                                g_slist_free (address_list);
+                               store_address = TRUE;
                        }
                }
 
                /* so, it seems a valid address */
                /* note: adding it the to the addressbook if it did not exist yet,
                 * and adding it to the recent_list */
-               if (result && update_addressbook)
+               if (result && update_addressbook && store_address)
                        add_to_address_book (address);
 
                g_free (address);
@@ -860,7 +875,7 @@ resolve_address (const gchar *address, GSList **resolved_addresses, gchar **cont
 
        if (resolved_contacts == NULL) {
                /* no matching contacts for the search string */
-               modest_platform_run_information_dialog (NULL, _("mcen_nc_no_matching_contacts"));
+               modest_platform_run_information_dialog (NULL, _("mcen_nc_no_matching_contacts"), FALSE);
                return FALSE;
        }