* Fixes NB#77103, the message is not sent if the user does not select any recipient...
[modest] / src / maemo / modest-address-book.c
index 420b5a7..03e29d6 100644 (file)
@@ -130,6 +130,7 @@ modest_address_book_add_address (const gchar *address)
 {
        OssoABookAccount *account = NULL;
        GtkWidget *dialog = NULL;
+       gchar *email_address = NULL;
 
        contact_model = osso_abook_contact_model_new ();
        if (!open_addressbook ()) {
@@ -139,8 +140,11 @@ modest_address_book_add_address (const gchar *address)
                }
                return;
        }
+
+       email_address = modest_text_utils_get_email_address (address);
        
-       account = osso_abook_account_get (EVC_EMAIL, NULL, address);
+       account = osso_abook_account_get (EVC_EMAIL, NULL, email_address);
+       g_free (email_address);
        if (account)
        {
                dialog = osso_abook_add_to_contacts_dialog_new (contact_model, account);
@@ -166,12 +170,9 @@ modest_address_book_select_addresses (ModestRecptEditor *recpt_editor)
        GSList *email_addrs_per_contact = NULL;
        gchar *econtact_id;
        gboolean focus_recpt_editor = FALSE;
-       GtkWidget *toplevel;
 
        g_return_if_fail (MODEST_IS_RECPT_EDITOR (recpt_editor));
 
-       toplevel = gtk_widget_get_toplevel (GTK_WIDGET (recpt_editor));
-
        if (!open_addressbook ()) {
                if (contact_model) {
                        g_object_unref (contact_model);
@@ -629,9 +630,14 @@ show_check_names_banner (gpointer data)
 {
        GtkWidget **banner = (GtkWidget **) data;
 
+       /* We're outside the main lock */
+       gdk_threads_enter ();
+
        *banner = hildon_banner_show_animation (NULL, NULL, _("mail_ib_checking_names"));
        g_object_ref (G_OBJECT (*banner));
 
+       gdk_threads_leave ();
+
        return FALSE;
 }
 
@@ -662,7 +668,12 @@ modest_address_book_check_names (ModestRecptEditor *recpt_editor, gboolean updat
                        gtk_widget_destroy (banner);
                        g_object_unref (G_OBJECT(banner));
                }
-               return TRUE;
+               if (last_length != 0) {
+                       hildon_banner_show_information (NULL, NULL, _("mcen_nc_no_matching_contacts"));
+                       return FALSE;
+               } else {
+                       return TRUE;
+               }
        }
 
        current_start = start_indexes;
@@ -724,7 +735,30 @@ modest_address_book_check_names (ModestRecptEditor *recpt_editor, gboolean updat
                                hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
                                result = FALSE;
                        }
-               } 
+               } else {
+                       GSList *tags, *node;
+                       gboolean has_recipient = FALSE;
+
+                       tags = gtk_text_iter_get_tags (&start_iter);
+                       for (node = tags; node != NULL; node = g_slist_next (node)) {
+                               GtkTextTag *tag = GTK_TEXT_TAG (node->data);
+                               if (g_object_get_data (G_OBJECT (tag), "recipient-tag-id") != NULL) {
+                                       has_recipient = TRUE;
+                                       break;
+                               }
+                       }
+                       g_slist_free (tags);
+                       if (!has_recipient) {
+                               GSList * address_list = NULL;
+
+                               address_list = g_slist_prepend (address_list, address);
+                               modest_recpt_editor_replace_with_resolved_recipient (recpt_editor,
+                                                                                    &start_iter, &end_iter,
+                                                                                    address_list, 
+                                                                                    "");
+                               g_slist_free (address_list);
+                       }
+               }
 
                /* so, it seems a valid address */
                /* note: adding it the to the addressbook if it did not exist yet,
@@ -750,7 +784,6 @@ modest_address_book_check_names (ModestRecptEditor *recpt_editor, gboolean updat
                gtk_widget_destroy (banner);
                g_object_unref (G_OBJECT (banner));
        }
-       modest_recpt_editor_grab_focus (recpt_editor);
 
        g_slist_foreach (start_indexes, (GFunc) g_free, NULL);
        g_slist_foreach (end_indexes, (GFunc) g_free, NULL);
@@ -846,17 +879,21 @@ resolve_address (const gchar *address, GSList **resolved_addresses, gchar **cont
        
        /* get the resolved contacts (can be no contact) */
        if (resolved_contacts) {
+               gboolean found;
                EContact *contact = (EContact *) resolved_contacts->data;
 
                *resolved_addresses = get_recipients_for_given_contact (contact);
                if (*resolved_addresses) {
                        *contact_id = g_strdup (e_contact_get_const (contact, E_CONTACT_UID));
+                       found = TRUE;
+               } else {
+                       found = FALSE;
                }
 
                g_list_foreach (resolved_contacts, (GFunc)unref_gobject, NULL);
                g_list_free (resolved_contacts);
 
-               return TRUE;
+               return found;
        } else {
                /* cancelled dialog to select more than one contact or
                 * selected no contact */