[evolution-ews] Bug 765398 - Online GAL contacts can have incorrect email address



commit 6da30fc8b876b261f1da7a8735b43ec18f824312
Author: Milan Crha <mcrha redhat com>
Date:   Wed Apr 27 18:56:07 2016 +0200

    Bug 765398 - Online GAL contacts can have incorrect email address

 src/addressbook/e-book-backend-ews.c |    9 ++++++-
 src/server/e-ews-item.c              |   41 ++++++++++++++++++++++++++++++++++
 src/server/e-ews-item.h              |    2 +
 3 files changed, 51 insertions(+), 1 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index 61880d8..b4154ee 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -591,8 +591,10 @@ set_email_address (EContact *contact,
        const gchar *ea;
 
        ea = e_ews_item_get_email_address (item, item_field);
-       if (ea && g_str_has_prefix (ea, "SMTP:"))
+       if (ea && g_ascii_strncasecmp (ea, "SMTP:", 5) == 0)
                ea = ea + 5;
+       else
+               ea = NULL;
 
        if (ea && *ea)
                e_contact_set (contact, field, ea);
@@ -1252,6 +1254,7 @@ static const struct field_element_mapping {
        { E_CONTACT_SPOUSE, ELEMENT_TYPE_SIMPLE, "Profession", e_ews_item_get_profession},
        { E_CONTACT_SPOUSE, ELEMENT_TYPE_SIMPLE, "SpouseName", e_ews_item_get_spouse_name},
        { E_CONTACT_FAMILY_NAME, ELEMENT_TYPE_SIMPLE, "Surname", e_ews_item_get_surname},
+       { E_CONTACT_GIVEN_NAME, ELEMENT_TYPE_SIMPLE, "GivenName", e_ews_item_get_givenname},
        { E_CONTACT_BIRTH_DATE, ELEMENT_TYPE_COMPLEX, "WeddingAnniversary", NULL,  
ebews_populate_anniversary, ebews_set_anniversary, ebews_set_anniversary_changes },
        { E_CONTACT_PHOTO, ELEMENT_TYPE_COMPLEX, "Photo", NULL,  ebews_populate_photo, ebews_set_photo, 
ebews_set_photo_changes },
 
@@ -3434,6 +3437,10 @@ e_book_backend_ews_start_view (EBookBackend *backend,
                        e_contact_set (contact, E_CONTACT_FULL_NAME, mb->name);
 
                str = e_contact_get_const (contact, E_CONTACT_EMAIL_1);
+               if ((!str || !*str) && contact_item && e_ews_item_get_item_type (contact_item) == 
E_EWS_ITEM_TYPE_CONTACT)
+                       ebews_populate_emails (ebews, contact, contact_item, NULL, NULL);
+
+               str = e_contact_get_const (contact, E_CONTACT_EMAIL_1);
                if (!str || !*str)
                        e_contact_set (contact, E_CONTACT_EMAIL_1, mb->email);
 
diff --git a/src/server/e-ews-item.c b/src/server/e-ews-item.c
index 9ad25ce..f73865d 100644
--- a/src/server/e-ews-item.c
+++ b/src/server/e-ews-item.c
@@ -62,6 +62,8 @@ struct _EEwsContactFields {
        gchar *spouse_name;
        gchar *culture;
        gchar *surname;
+       gchar *givenname;
+       gchar *middlename;
        gchar *notes;
 };
 
@@ -345,6 +347,8 @@ ews_free_contact_fields (struct _EEwsContactFields *con_fields)
                g_free (con_fields->spouse_name);
                g_free (con_fields->culture);
                g_free (con_fields->surname);
+               g_free (con_fields->givenname);
+               g_free (con_fields->middlename);
                g_free (con_fields->notes);
                g_free (con_fields);
        }
@@ -797,6 +801,10 @@ parse_contact_field (EEwsItem *item,
                priv->contact_fields->spouse_name = e_soap_parameter_get_string_value (subparam);
        } else if (!g_ascii_strcasecmp (name, "Surname")) {
                priv->contact_fields->surname = e_soap_parameter_get_string_value (subparam);
+       } else if (!g_ascii_strcasecmp (name, "GivenName")) {
+               priv->contact_fields->givenname = e_soap_parameter_get_string_value (subparam);
+       } else if (!g_ascii_strcasecmp (name, "MiddleName")) {
+               priv->contact_fields->middlename = e_soap_parameter_get_string_value (subparam);
        } else if (!g_ascii_strcasecmp (name, "WeddingAnniversary")) {
                value = e_soap_parameter_get_string_value (subparam);
                priv->contact_fields->wedding_anniversary = ews_item_parse_date (value);
@@ -1859,6 +1867,21 @@ e_ews_item_get_complete_name (EEwsItem *item)
        g_return_val_if_fail (E_IS_EWS_ITEM (item), NULL);
        g_return_val_if_fail (item->priv->contact_fields != NULL, NULL);
 
+       if (!item->priv->contact_fields->complete_name && (
+           item->priv->contact_fields->surname ||
+           item->priv->contact_fields->middlename ||
+           item->priv->contact_fields->givenname)) {
+               EwsCompleteName *cn;
+
+               cn = g_new0 (EwsCompleteName, 1);
+
+               cn->first_name = g_strdup (item->priv->contact_fields->givenname);
+               cn->middle_name = g_strdup (item->priv->contact_fields->middlename);
+               cn->last_name = g_strdup (item->priv->contact_fields->surname);
+
+               item->priv->contact_fields->complete_name = cn;
+       }
+
        return (const EwsCompleteName *) item->priv->contact_fields->complete_name;
 }
 
@@ -2057,6 +2080,24 @@ e_ews_item_get_surname (EEwsItem *item)
 }
 
 const gchar *
+e_ews_item_get_givenname (EEwsItem *item)
+{
+       g_return_val_if_fail (E_IS_EWS_ITEM (item), NULL);
+       g_return_val_if_fail (item->priv->contact_fields != NULL, NULL);
+
+       return item->priv->contact_fields->givenname;
+}
+
+const gchar *
+e_ews_item_get_middlename (EEwsItem *item)
+{
+       g_return_val_if_fail (E_IS_EWS_ITEM (item), NULL);
+       g_return_val_if_fail (item->priv->contact_fields != NULL, NULL);
+
+       return item->priv->contact_fields->middlename;
+}
+
+const gchar *
 e_ews_item_get_notes (EEwsItem *item)
 {
        g_return_val_if_fail (E_IS_EWS_ITEM (item), NULL);
diff --git a/src/server/e-ews-item.h b/src/server/e-ews-item.h
index 304d542..03b43f3 100644
--- a/src/server/e-ews-item.h
+++ b/src/server/e-ews-item.h
@@ -323,6 +323,8 @@ const gchar *       e_ews_item_get_profession       (EEwsItem *item);
 const gchar *  e_ews_item_get_spouse_name      (EEwsItem *item);
 const gchar *  e_ews_item_get_culture          (EEwsItem *item);
 const gchar *  e_ews_item_get_surname          (EEwsItem *item);
+const gchar *  e_ews_item_get_givenname        (EEwsItem *item);
+const gchar *  e_ews_item_get_middlename       (EEwsItem *item);
 const gchar *  e_ews_item_get_notes            (EEwsItem *item);
 
 /*Task fields*/


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