From fdf3571635d4c34c057c7734785e8e6685036567 Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Wed, 1 Aug 2007 06:50:59 +0000 Subject: [PATCH] * src/modest-text-utils.[ch]: * New (modest_text_utils_get_email_address) function, that obtains the email address email@address from a full address Full Address . * src/maemo/modest-address-book.c: * (modest_address_book_add_address): now we add the email part of an address to the addressbook, instead of the full address (fixes NB#64733). pmo-trunk-r2881 --- src/maemo/modest-address-book.c | 6 +++++- src/modest-text-utils.c | 19 +++++++++++++++++++ src/modest-text-utils.h | 17 ++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/maemo/modest-address-book.c b/src/maemo/modest-address-book.c index 420b5a7..ac1996e 100644 --- a/src/maemo/modest-address-book.c +++ b/src/maemo/modest-address-book.c @@ -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); diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index fd737cc..6b67214 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -964,7 +964,26 @@ modest_text_utils_get_display_address (gchar *address) return address; } +gchar * +modest_text_utils_get_email_address (const gchar *full_address) +{ + const gchar *left, *right; + + if (!full_address) + return NULL; + + g_return_val_if_fail (g_utf8_validate (full_address, -1, NULL), NULL); + + left = g_strrstr_len (full_address, strlen(full_address), "<"); + if (left == NULL) + return g_strdup (full_address); + right = g_strstr_len (left, strlen(left), ">"); + if (right == NULL) + return g_strdup (full_address); + + return g_strndup (left + 1, right - left - 1); +} gint modest_text_utils_get_subject_prefix_len (const gchar *sub) diff --git a/src/modest-text-utils.h b/src/modest-text-utils.h index 21bad3f..401907f 100644 --- a/src/modest-text-utils.h +++ b/src/modest-text-utils.h @@ -186,7 +186,7 @@ size_t modest_text_utils_strftime(char *s, size_t max, const char *fmt, time_t /** - * modest_text_utils_get_display_addres: + * modest_text_utils_get_display_address: * @address: original address (UTF8 string) * * make a 'display address' from an address: @@ -202,6 +202,21 @@ size_t modest_text_utils_strftime(char *s, size_t max, const char *fmt, time_t */ gchar* modest_text_utils_get_display_address (gchar *address); +/** + * modest_text_utils_get_email_address: + * @full_address: original address (UTF8 string) + * + * make a 'foo@bar.cx' from an address: + * "Foo Bar (Bla)" --> "foo@bar.cx" + * If no "<...>" is found, then it returns the full + * strings. + * + * Returns: a newly allocated string with the copy. + * + * NULL in case of error or if address == NULL + */ +gchar* modest_text_utils_get_email_address (const gchar *email_address); + /** * modest_text_utils_get_subject_prefix_len: -- 1.7.9.5