* src/modest-text-utils.[ch]:
authorJose Dapena Paz <jdapena@igalia.com>
Wed, 1 Aug 2007 06:50:59 +0000 (06:50 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Wed, 1 Aug 2007 06:50:59 +0000 (06:50 +0000)
        * New (modest_text_utils_get_email_address) function, that
          obtains the email address email@address from a full
          address Full Address <email@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
src/modest-text-utils.c
src/modest-text-utils.h

index 420b5a7..ac1996e 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);
index fd737cc..6b67214 100644 (file)
@@ -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)
index 21bad3f..401907f 100644 (file)
@@ -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 <foo@bar.cx> (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: