[evolution-ews] Bug 763430 - Show additional GAL Attributes in Contacts



commit ad0decd87543ff4c7e93f1e94a3e2ccf4b109ff0
Author: Milan Crha <mcrha redhat com>
Date:   Fri Mar 11 09:24:40 2016 +0100

    Bug 763430 - Show additional GAL Attributes in Contacts

 src/addressbook/e-book-backend-ews.c |   49 ++++++++++++----------------
 src/server/e-ews-connection.c        |   41 ++++++++++++++---------
 src/server/e-ews-connection.h        |    1 -
 src/server/e-ews-item.c              |   58 +++++++++++++---------------------
 src/server/e-ews-item.h              |   10 +-----
 5 files changed, 70 insertions(+), 89 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index c63234b..2eeb16e 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -401,10 +401,13 @@ get_photo (EBookBackendEws *ebews,
        const EwsId *id;
        gsize len;
 
+       id = e_ews_item_get_id (item);
+       if (!id)
+               return NULL;
+
        add_props = e_ews_additional_props_new ();
        add_props->field_uri = g_strdup ("item:Attachments");
 
-       id = e_ews_item_get_id (item);
        contact_item_ids = g_slist_prepend (contact_item_ids, g_strdup (id->id));
        if (!e_ews_connection_get_items_sync (
                        ebews->priv->cnc,
@@ -588,6 +591,9 @@ 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:"))
+               ea = ea + 5;
+
        if (ea && *ea)
                e_contact_set (contact, field, ea);
 }
@@ -3371,47 +3377,34 @@ e_book_backend_ews_start_view (EBookBackend *backend,
 
        for (l = mailboxes, c = contacts; l != NULL; l = g_slist_next (l), c = c ? g_slist_next (c) : NULL) {
                EwsMailbox *mb = l->data;
-               EwsResolveContact *rc = c ? c->data : NULL;
-               EContact *contact;
+               EEwsItem *contact_item = c ? c->data : NULL;
+               EContact *contact = NULL;
+               const gchar *str;
 
-               contact = e_contact_new ();
+               if (contact_item && e_ews_item_get_item_type (contact_item) == E_EWS_ITEM_TYPE_CONTACT)
+                       contact = ebews_get_contact_info (ebews, contact_item, cancellable, NULL);
+
+               if (!contact)
+                       contact = e_contact_new ();
 
                /* We do not get an id from the server, so just using email_id as uid for now */
                e_contact_set (contact, E_CONTACT_UID, mb->email);
 
-               if (rc && rc->display_name && *rc->display_name)
-                       e_contact_set (contact, E_CONTACT_FULL_NAME, rc->display_name);
-               else
+               str = e_contact_get_const (contact, E_CONTACT_FULL_NAME);
+               if (!str || !*str)
                        e_contact_set (contact, E_CONTACT_FULL_NAME, mb->name);
 
-               if (rc && g_hash_table_size (rc->email_addresses) > 0) {
-                       GList *emails = g_hash_table_get_values (rc->email_addresses), *iter;
-                       GList *use_emails = NULL;
-
-                       for (iter = emails; iter; iter = iter->next) {
-                               if (iter->data && g_str_has_prefix (iter->data, "SMTP:"))
-                                       use_emails = g_list_prepend (use_emails, ((gchar *) iter->data) + 5);
-                       }
-
-                       if (!use_emails)
-                               use_emails = g_list_prepend (use_emails, mb->email);
-
-                       e_contact_set (contact, E_CONTACT_EMAIL, use_emails);
-
-                       g_list_free (use_emails);
-                       g_list_free (emails);
-               } else
+               str = e_contact_get_const (contact, E_CONTACT_EMAIL_1);
+               if (!str || !*str)
                        e_contact_set (contact, E_CONTACT_EMAIL_1, mb->email);
 
                e_data_book_view_notify_update (book_view, contact);
 
-               e_ews_mailbox_free (mb);
-               e_ews_free_resolve_contact (rc);
                g_object_unref (contact);
        }
 
-       g_slist_free (mailboxes);
-       g_slist_free (contacts);
+       g_slist_free_full (mailboxes, (GDestroyNotify) e_ews_mailbox_free);
+       g_slist_free_full (contacts, g_object_unref);
  out:
        e_data_book_view_notify_complete (book_view, error);
        g_clear_error (&error);
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index 2a7884e..76befcf 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -1259,15 +1259,15 @@ ews_handle_resolution_set_param (ESoapParameter *subparam,
                node = e_soap_parameter_get_first_child_by_name (subparam, "Mailbox");
                mb = e_ews_item_mailbox_from_soap_param (node);
                if (mb) {
-                       EwsResolveContact *rc;
+                       EEwsItem *contact_item;
 
                        mailboxes = g_slist_prepend (mailboxes, mb);
 
                        /* 'mailboxes' and 'contact_items' match 1:1, but if the contact information
                         * wasn't found, then NULL is stored in the corresponding position */
                        node = e_soap_parameter_get_first_child_by_name (subparam, "Contact");
-                       rc = e_ews_item_resolve_contact_from_soap_param (node);
-                       contact_items = g_slist_prepend (contact_items, rc);
+                       contact_item = e_ews_item_new_from_soap_parameter (node);
+                       contact_items = g_slist_prepend (contact_items, contact_item);
                }
        }
 
@@ -5189,7 +5189,7 @@ e_ews_connection_resolve_names_finish (EEwsConnection *cnc,
        if (contact_items)
                *contact_items = async_data->items_created;
        else
-               g_slist_free_full (async_data->items_created, e_ews_free_resolve_contact);
+               g_slist_free_full (async_data->items_created, g_object_unref);
        *mailboxes = async_data->items;
 
        return TRUE;
@@ -5273,17 +5273,24 @@ ews_connection_resolve_by_name (EEwsConnection *cnc,
                    (is_user_name && g_str_equal (usename, mailbox->name)))) {
                        *smtp_address = g_strdup (mailbox->email);
                        break;
-               } else if (contacts && !contacts->next && contacts->data) {
-                       const EwsResolveContact *resolved = contacts->data;
-                       GList *emails = g_hash_table_get_values (resolved->email_addresses), *iter;
+               } else if (contacts && !contacts->next && contacts->data &&
+                          e_ews_item_get_item_type (contacts->data) == E_EWS_ITEM_TYPE_CONTACT) {
+                       EEwsItem *contact_item = contacts->data;
+                       GHashTable *addresses_hash = e_ews_item_get_email_addresses (contact_item);
+                       GList *emails = addresses_hash ? g_hash_table_get_values (addresses_hash) : NULL, 
*iter;
+                       const gchar *display_name;
                        gboolean found = FALSE;
 
+                       display_name = e_ews_item_get_display_name (contact_item);
+                       if (!display_name || !*display_name)
+                               display_name = e_ews_item_get_fileas (contact_item);
+
                        for (iter = emails; iter && !found; iter = iter->next) {
                                const gchar *it_email = iter->data;
 
                                if (it_email && g_str_has_prefix (it_email, "SMTP:")
                                    && ((!is_user_name && g_str_has_prefix (it_email, usename) && 
it_email[len] == '@') ||
-                                   (is_user_name && g_str_equal (usename, resolved->display_name)))) {
+                                   (is_user_name && display_name && g_str_equal (usename, display_name)))) {
                                        found = TRUE;
                                        break;
                                }
@@ -5294,11 +5301,11 @@ ews_connection_resolve_by_name (EEwsConnection *cnc,
                        if (found) {
                                gint ii;
 
-                               for (ii = 0; ii < g_hash_table_size (resolved->email_addresses); ii++) {
+                               for (ii = 0; ii < g_hash_table_size (addresses_hash); ii++) {
                                        gchar *key, *value;
 
                                        key = g_strdup_printf ("EmailAddress%d", ii + 1);
-                                       value = g_hash_table_lookup (resolved->email_addresses, key);
+                                       value = g_hash_table_lookup (addresses_hash, key);
                                        g_free (key);
 
                                        if (value && g_str_has_prefix (value, "SMTP:")) {
@@ -5313,7 +5320,7 @@ ews_connection_resolve_by_name (EEwsConnection *cnc,
        }
 
        g_slist_free_full (mailboxes, (GDestroyNotify) e_ews_mailbox_free);
-       g_slist_free_full (contacts, (GDestroyNotify) e_ews_free_resolve_contact);
+       g_slist_free_full (contacts, g_object_unref);
 }
 
 gboolean
@@ -5345,15 +5352,17 @@ e_ews_connection_ex_to_smtp_sync (EEwsConnection *cnc,
                const EwsMailbox *mailbox = mailboxes->data;
                if (mailbox->email && *mailbox->email && g_strcmp0 (mailbox->routing_type, "EX") != 0) {
                        *smtp_address = g_strdup (mailbox->email);
-               } else if (contacts && !contacts->next && contacts->data) {
-                       const EwsResolveContact *resolved = contacts->data;
+               } else if (contacts && !contacts->next && contacts->data &&
+                          e_ews_item_get_item_type (contacts->data) == E_EWS_ITEM_TYPE_CONTACT) {
+                       EEwsItem *contact_item = contacts->data;
+                       GHashTable *addresses = e_ews_item_get_email_addresses (contact_item);
                        gint ii;
 
-                       for (ii = 0; ii < g_hash_table_size (resolved->email_addresses); ii++) {
+                       for (ii = 0; ii < (addresses ? g_hash_table_size (addresses) : 0); ii++) {
                                gchar *key, *value;
 
                                key = g_strdup_printf ("EmailAddress%d", ii + 1);
-                               value = g_hash_table_lookup (resolved->email_addresses, key);
+                               value = g_hash_table_lookup (addresses, key);
                                g_free (key);
 
                                if (value && g_str_has_prefix (value, "SMTP:")) {
@@ -5366,7 +5375,7 @@ e_ews_connection_ex_to_smtp_sync (EEwsConnection *cnc,
        }
 
        g_slist_free_full (mailboxes, (GDestroyNotify) e_ews_mailbox_free);
-       g_slist_free_full (contacts, (GDestroyNotify) e_ews_free_resolve_contact);
+       g_slist_free_full (contacts, g_object_unref);
 
        if (!*smtp_address) {
                const gchar *usename;
diff --git a/src/server/e-ews-connection.h b/src/server/e-ews-connection.h
index 31dc788..c759856 100644
--- a/src/server/e-ews-connection.h
+++ b/src/server/e-ews-connection.h
@@ -85,7 +85,6 @@ typedef enum {
        EWS_SEARCH_AD_CONTACTS,
        EWS_SEARCH_CONTACTS,
        EWS_SEARCH_CONTACTS_AD
-
 } EwsContactsSearchScope;
 
 typedef enum {
diff --git a/src/server/e-ews-item.c b/src/server/e-ews-item.c
index 8cd137a..f09553f 100644
--- a/src/server/e-ews-item.c
+++ b/src/server/e-ews-item.c
@@ -38,6 +38,7 @@ G_DEFINE_TYPE (EEwsItem, e_ews_item, G_TYPE_OBJECT)
 
 struct _EEwsContactFields {
        gchar *fileas;
+       gchar *display_name;
        EwsCompleteName *complete_name;
 
        GHashTable *email_addresses;
@@ -327,6 +328,7 @@ ews_free_contact_fields (struct _EEwsContactFields *con_fields)
                if (con_fields->im_addresses)
                        g_hash_table_destroy (con_fields->im_addresses);
 
+               g_free (con_fields->display_name);
                g_free (con_fields->fileas);
                g_free (con_fields->company_name);
                g_free (con_fields->department);
@@ -749,6 +751,8 @@ parse_contact_field (EEwsItem *item,
 
        if (!g_ascii_strcasecmp (name, "Culture")) {
                priv->contact_fields->culture = e_soap_parameter_get_string_value (subparam);
+       } else if (!g_ascii_strcasecmp (name, "DisplayName")) {
+               priv->contact_fields->display_name = e_soap_parameter_get_string_value (subparam);
        } else if (!g_ascii_strcasecmp (name, "FileAs")) {
                priv->contact_fields->fileas = e_soap_parameter_get_string_value (subparam);
        } else if (!g_ascii_strcasecmp (name, "CompleteName")) {
@@ -1843,6 +1847,24 @@ e_ews_item_get_complete_name (EEwsItem *item)
        return (const EwsCompleteName *) item->priv->contact_fields->complete_name;
 }
 
+const gchar *
+e_ews_item_get_display_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);
+
+       return item->priv->contact_fields->display_name;
+}
+
+GHashTable *
+e_ews_item_get_email_addresses (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->email_addresses;
+}
+
 /**
  * e_ews_item_get_email_address 
  * @item: 
@@ -2197,42 +2219,6 @@ e_ews_item_get_contact_photo_id (EEwsItem *item)
        return item->priv->contact_photo_id;
 }
 
-EwsResolveContact *
-e_ews_item_resolve_contact_from_soap_param (ESoapParameter *param)
-{
-       ESoapParameter *subparam;
-       EwsResolveContact *rc;
-
-       if (!param)
-               return NULL;
-
-       rc = g_new0 (EwsResolveContact, 1);
-       rc->email_addresses = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
-
-       subparam = e_soap_parameter_get_first_child_by_name (param, "DisplayName");
-       if (subparam)
-               rc->display_name = e_soap_parameter_get_string_value (subparam);
-
-       subparam = e_soap_parameter_get_first_child_by_name (param, "EmailAddresses");
-       if (subparam)
-               parse_entries (rc->email_addresses, subparam, (EwsGetValFunc) 
e_soap_parameter_get_string_value);
-
-       return rc;
-}
-
-void
-e_ews_free_resolve_contact (gpointer rc)
-{
-       EwsResolveContact *resc = rc;
-
-       if (!resc)
-               return;
-
-       g_free (resc->display_name);
-       g_hash_table_unref (resc->email_addresses);
-       g_free (resc);
-}
-
 /* free returned pointer with e_ews_permission_free() */
 EEwsPermission *
 e_ews_permission_new (EEwsPermissionUserType user_type,
diff --git a/src/server/e-ews-item.h b/src/server/e-ews-item.h
index a7c2948..725ffc6 100644
--- a/src/server/e-ews-item.h
+++ b/src/server/e-ews-item.h
@@ -84,11 +84,6 @@ typedef struct {
 } EwsMailbox;
 
 typedef struct {
-       gchar *display_name;
-       GHashTable *email_addresses;
-} EwsResolveContact;
-
-typedef struct {
        EwsMailbox *mailbox;
        gchar *attendeetype;
        gchar *responsetype;
@@ -217,9 +212,6 @@ EwsMailbox *
                e_ews_item_mailbox_from_soap_param
                                                (ESoapParameter *param);
 void           e_ews_mailbox_free              (EwsMailbox *mailbox);
-EwsResolveContact *
-               e_ews_item_resolve_contact_from_soap_param (ESoapParameter *param);
-void           e_ews_free_resolve_contact      (/*EwsResolveContact * */ gpointer rc);
 
 const GSList * e_ews_item_get_modified_occurrences
                                                (EEwsItem *item);
@@ -307,6 +299,8 @@ void                e_ews_attachment_info_set_uri   (EEwsAttachmentInfo *info,
 const gchar *  e_ews_item_get_fileas           (EEwsItem *item);
 const EwsCompleteName *
                e_ews_item_get_complete_name    (EEwsItem *item);
+const gchar *  e_ews_item_get_display_name     (EEwsItem *item);
+GHashTable *   e_ews_item_get_email_addresses  (EEwsItem *item);
 const gchar *  e_ews_item_get_email_address    (EEwsItem *item, const gchar *type);
 const EwsAddress *
                e_ews_item_get_physical_address (EEwsItem *item, const gchar *type);


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