[evolution] Bug 607520 - 'Add to Address Book' fails when address has space



commit 6db981fa566574d16f4664687d26147acde7ad80
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Jan 20 19:14:46 2010 -0500

    Bug 607520 - 'Add to Address Book' fails when address has space

 .../gui/contact-editor/e-contact-quick-add.c       |   25 ++++++++++++++++++++
 .../gui/contact-editor/e-contact-quick-add.h       |    2 +
 mail/e-mail-reader.c                               |   16 ++++++++++++-
 modules/addressbook/e-book-shell-backend.c         |    2 +-
 4 files changed, 43 insertions(+), 2 deletions(-)
---
diff --git a/addressbook/gui/contact-editor/e-contact-quick-add.c b/addressbook/gui/contact-editor/e-contact-quick-add.c
index 6525738..36bd4ed 100644
--- a/addressbook/gui/contact-editor/e-contact-quick-add.c
+++ b/addressbook/gui/contact-editor/e-contact-quick-add.c
@@ -589,6 +589,31 @@ e_contact_quick_add_free_form (const gchar *text, EContactQuickAddCallback cb, g
 }
 
 void
+e_contact_quick_add_email (const gchar *email, EContactQuickAddCallback cb, gpointer closure)
+{
+	gchar *name = NULL;
+	gchar *addr = NULL;
+	gchar *lt, *gt;
+
+	/* Handle something of the form "Foo <foo bar com>".  This is more
+	 * more forgiving than the free-form parser, allowing for unquoted
+	 * whitespace since we know the whole string is an email address. */
+
+	lt = (email != NULL) ? strchr (email, '<') : NULL;
+	gt = (lt != NULL) ? strchr (email, '>') : NULL;
+
+	if (lt != NULL && gt != NULL && (gt - lt) > 0) {
+		name = g_strndup (email, lt - email);
+		addr = g_strndup (lt + 1, gt - lt - 1);
+	}
+
+	e_contact_quick_add (name, addr, cb, closure);
+
+	g_free (name);
+	g_free (addr);
+}
+
+void
 e_contact_quick_add_vcard (const gchar *vcard, EContactQuickAddCallback cb, gpointer closure)
 {
 	QuickAdd *qa;
diff --git a/addressbook/gui/contact-editor/e-contact-quick-add.h b/addressbook/gui/contact-editor/e-contact-quick-add.h
index e58722b..a4d06ef 100644
--- a/addressbook/gui/contact-editor/e-contact-quick-add.h
+++ b/addressbook/gui/contact-editor/e-contact-quick-add.h
@@ -32,6 +32,8 @@ void e_contact_quick_add (const gchar *name, const gchar *email,
 
 void e_contact_quick_add_free_form (const gchar *text, EContactQuickAddCallback cb, gpointer closure);
 
+void e_contact_quick_add_email (const gchar *email, EContactQuickAddCallback cb, gpointer closure);
+
 void e_contact_quick_add_vcard (const gchar *vcard, EContactQuickAddCallback cb, gpointer closure);
 
 #endif /* __E_CONTACT_QUICK_ADD_H__ */
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index c94749b..c5106b6 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -105,9 +105,11 @@ action_add_to_address_book_cb (GtkAction *action,
 	EShell *shell;
 	EShellBackend *shell_backend;
 	EMFormatHTMLDisplay *html_display;
+	CamelInternetAddress *cia;
 	EWebView *web_view;
 	CamelURL *curl;
 	const gchar *uri;
+	gchar *email;
 
 	/* This action is defined in EMailDisplay. */
 
@@ -125,11 +127,23 @@ action_add_to_address_book_cb (GtkAction *action,
 	if (curl->path == NULL || *curl->path == '\0')
 		goto exit;
 
+	cia = camel_internet_address_new ();
+	if (camel_address_decode (CAMEL_ADDRESS (cia), curl->path) < 0) {
+		camel_object_unref (cia);
+		goto exit;
+	}
+
+	email = camel_address_format (CAMEL_ADDRESS (cia));
+
 	/* XXX EBookShellBackend should be listening for this
 	 *     event.  Kind of kludgey, but works for now. */
 	shell = e_shell_backend_get_shell (shell_backend);
-	e_shell_event (shell, "contact-quick-add-email", curl->path);
+	e_shell_event (shell, "contact-quick-add-email", email);
 	emu_remove_from_mail_cache_1 (curl->path);
+
+	camel_object_unref (cia);
+	g_free (email);
+
 exit:
 	camel_url_free (curl);
 }
diff --git a/modules/addressbook/e-book-shell-backend.c b/modules/addressbook/e-book-shell-backend.c
index 11ff1e3..1166cd6 100644
--- a/modules/addressbook/e-book-shell-backend.c
+++ b/modules/addressbook/e-book-shell-backend.c
@@ -387,7 +387,7 @@ book_shell_backend_quick_add_email_cb (EShell *shell,
 	/* XXX This is an ugly hack but it's the only way I could think
 	 *     of to integrate this feature with other shell modules. */
 
-	e_contact_quick_add_free_form (email, NULL, NULL);
+	e_contact_quick_add_email (email, NULL, NULL);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]