+
+static gboolean /* make this public? */
+add_to_address_book (const gchar* address)
+{
+ EBookQuery *query;
+ GList *contacts = NULL;
+ GError *err = NULL;
+ gchar *email;
+
+ g_return_val_if_fail (address, FALSE);
+
+ if (!book)
+ 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, email);
+ if (!e_book_get_contacts (book, query, &contacts, &err)) {
+ g_printerr ("modest: failed to get contacts: %s",
+ err ? err->message : "<unknown>");
+ if (err)
+ g_error_free (err);
+ return FALSE;
+ }
+ e_book_query_unref (query);
+
+ /* we need to 'commit' it, even if we already found the email
+ * address in the addressbook; thus, it will show up in the 'recent list' */
+ if (contacts) {
+ g_debug ("%s already in the address book", address);
+ commit_contact ((EContact*)contacts->data, FALSE);
+
+ g_list_foreach (contacts, (GFunc)unref_gobject, NULL);
+ g_list_free (contacts);
+
+ } else {
+ /* it's not yet in the addressbook, add it now! */
+ EContact *new_contact = e_contact_new ();
+ 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;
+}
+
+static gboolean
+show_check_names_banner (gpointer userdata)
+{
+ GtkWidget **banner = (GtkWidget **) userdata;
+
+ gdk_threads_enter ();
+ *banner = modest_platform_animation_banner (NULL, NULL, _("mail_ib_checking_names"));
+ gdk_threads_leave ();
+
+ return FALSE;
+}
+
+static void
+hide_check_names_banner (GtkWidget **banner, guint banner_timeout)
+{
+ if (*banner != NULL) {
+ gtk_widget_destroy (*banner);
+ *banner = NULL;
+ } else {
+ g_source_remove (banner_timeout);
+ }
+
+}
+