[evolution-ews] Bug #686227 - EX addresses are returned for deleted mailboxes



commit f29c5a821aece53a34758614e57a36cd7da4a179
Author: Milan Crha <mcrha redhat com>
Date:   Wed Apr 24 11:15:21 2013 +0200

    Bug #686227 - EX addresses are returned for deleted mailboxes

 src/calendar/e-cal-backend-ews.c |   52 ++++++++-----------------------------
 src/camel/camel-ews-utils.c      |   16 ++---------
 src/server/e-ews-item.c          |   18 +++++++++++++
 src/server/e-ews-item.h          |    4 +++
 4 files changed, 37 insertions(+), 53 deletions(-)
---
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index 50444e5..d2b3bf0 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -3130,8 +3130,7 @@ ews_get_attachments (ECalBackendEws *cbews,
 
 static void
 add_item_to_cache (ECalBackendEws *cbews,
-                   EEwsItem *item,
-                   GHashTable *ex_to_smtp)
+                   EEwsItem *item)
 {
        ECalBackendEwsPrivate *priv;
        ETimezoneCache *timezone_cache;
@@ -3340,41 +3339,24 @@ add_item_to_cache (ECalBackendEws *cbews,
                /* Attendees */
                for (l = e_ews_item_get_attendees (item); l != NULL; l = g_slist_next (l)) {
                        icalparameter *param, *cu_type;
-                       gchar *mailtoname, *email = NULL;
+                       gchar *mailtoname;
+                       const gchar *email = NULL;
                        EwsAttendee *attendee = (EwsAttendee *) l->data;
 
                        if (!attendee->mailbox)
                                continue;
 
-                       if (g_strcmp0 (attendee->mailbox->routing_type, "EX") == 0) {
-                               email = g_hash_table_lookup (ex_to_smtp, attendee->mailbox->email);
-                               if (email) {
-                                       email = g_strdup (email);
-                               } else {
-                                       e_ews_connection_ex_to_smtp_sync (
-                                               priv->cnc, EWS_PRIORITY_MEDIUM,
-                                               attendee->mailbox->name, attendee->mailbox->email, &email,
-                                               NULL, NULL);
-
-                                       /* do not scare users with EX addresses */
-                                       if (!email)
-                                               email = g_strdup ("");
-
-                                       /* cache value for reuse, because ResolveNames is slow */
-                                       g_hash_table_insert (ex_to_smtp, g_strdup (attendee->mailbox->email), 
g_strdup (email));
-                               }
-                       }
+                       if (g_strcmp0 (attendee->mailbox->routing_type, "EX") == 0)
+                               email = e_ews_item_util_strip_ex_address (attendee->mailbox->email);
 
                        /*remove organizer for attendees list*/
                        if (g_ascii_strcasecmp (org_email_address, email ? email : attendee->mailbox->email) 
== 0) {
-                               g_free (email);
                                continue;
                        }
 
                        mailtoname = g_strdup_printf ("mailto:%s";, email ? email : attendee->mailbox->email);
                        icalprop = icalproperty_new_attendee (mailtoname);
                        g_free (mailtoname);
-                       g_free (email);
 
                        param = icalparameter_new_cn (attendee->mailbox->name);
                        icalproperty_add_parameter (icalprop, param);
@@ -3543,8 +3525,7 @@ static void
 ews_cal_sync_get_items_sync (ECalBackendEws *cbews,
                              const GSList *item_ids,
                              const gchar *default_props,
-                             const gchar *additional_props,
-                             GHashTable *ex_to_smtp)
+                             const gchar *additional_props)
 {
        ECalBackendEwsPrivate *priv;
        GSList *items = NULL, *l;
@@ -3586,8 +3567,7 @@ ews_cal_sync_get_items_sync (ECalBackendEws *cbews,
                        ews_cal_sync_get_items_sync (
                                cbews, modified_occurrences,
                                "IdOnly",
-                               "item:Attachments item:HasAttachments item:MimeContent calendar:TimeZone 
calendar:UID calendar:Resources calendar:ModifiedOccurrences calendar:RequiredAttendees 
calendar:OptionalAttendees",
-                               ex_to_smtp);
+                               "item:Attachments item:HasAttachments item:MimeContent calendar:TimeZone 
calendar:UID calendar:Resources calendar:ModifiedOccurrences calendar:RequiredAttendees 
calendar:OptionalAttendees");
                }
        }
 
@@ -3599,7 +3579,7 @@ ews_cal_sync_get_items_sync (ECalBackendEws *cbews,
                        continue;
 
                if (e_ews_item_get_item_type (item) != E_EWS_ITEM_TYPE_ERROR) {
-                       add_item_to_cache (cbews, item, ex_to_smtp);
+                       add_item_to_cache (cbews, item);
                        ews_get_attachments (cbews, item);
                }
 
@@ -3615,8 +3595,7 @@ cal_backend_ews_process_folder_items (ECalBackendEws *cbews,
                                       const gchar *sync_state,
                                       GSList *items_created,
                                       GSList *items_updated,
-                                      GSList *items_deleted,
-                                      GHashTable *ex_to_smtp)
+                                      GSList *items_deleted)
 {
        ECalBackendEwsPrivate *priv;
        GSList *l[2], *m, *cal_item_ids = NULL, *task_memo_item_ids = NULL;
@@ -3660,8 +3639,7 @@ cal_backend_ews_process_folder_items (ECalBackendEws *cbews,
                        cbews,
                        cal_item_ids,
                        "IdOnly",
-                       "item:Attachments item:HasAttachments item:MimeContent calendar:TimeZone calendar:UID 
calendar:Resources calendar:ModifiedOccurrences calendar:RequiredAttendees calendar:OptionalAttendees",
-                       ex_to_smtp);
+                       "item:Attachments item:HasAttachments item:MimeContent calendar:TimeZone calendar:UID 
calendar:Resources calendar:ModifiedOccurrences calendar:RequiredAttendees calendar:OptionalAttendees");
        }
 
        if (task_memo_item_ids) {
@@ -3669,8 +3647,7 @@ cal_backend_ews_process_folder_items (ECalBackendEws *cbews,
                        cbews,
                        task_memo_item_ids,
                        "AllProperties",
-                       NULL,
-                       ex_to_smtp);
+                       NULL);
        }
 
        g_slist_free (cal_item_ids);
@@ -3713,13 +3690,11 @@ ews_start_sync_thread (gpointer data)
        gboolean includes_last_item;
        gchar *old_sync_state = NULL;
        gchar *new_sync_state = NULL;
-       GHashTable *ex_to_smtp;
        GError *error = NULL;
 
        cbews = (ECalBackendEws *) data;
        priv = cbews->priv;
 
-       ex_to_smtp = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
        old_sync_state = g_strdup (e_cal_backend_store_get_key_value (priv->store, SYNC_KEY));
        do {
                includes_last_item = TRUE;
@@ -3758,8 +3733,7 @@ ews_start_sync_thread (gpointer data)
                if (error == NULL) {
                        cal_backend_ews_process_folder_items (
                                cbews, new_sync_state,
-                               items_created, items_updated, items_deleted,
-                               ex_to_smtp);
+                               items_created, items_updated, items_deleted);
 
                        g_slist_free_full (items_created, (GDestroyNotify) g_object_unref);
                        g_slist_free_full (items_updated, (GDestroyNotify) g_object_unref);
@@ -3785,8 +3759,6 @@ ews_start_sync_thread (gpointer data)
 
        ews_refreshing_dec (cbews);
 
-       g_hash_table_destroy (ex_to_smtp);
-
        g_slist_free_full (items_created, (GDestroyNotify) g_object_unref);
        g_slist_free_full (items_updated, (GDestroyNotify) g_object_unref);
        g_slist_free_full (items_deleted, (GDestroyNotify) g_free);
diff --git a/src/camel/camel-ews-utils.c b/src/camel/camel-ews-utils.c
index 52854e2..c326538 100644
--- a/src/camel/camel-ews-utils.c
+++ b/src/camel/camel-ews-utils.c
@@ -499,18 +499,10 @@ form_email_string_from_mb (EEwsConnection *cnc,
 {
        if (mb) {
                GString *str;
-               gchar *email = NULL;
+               const gchar *email = NULL;
 
-               if (g_strcmp0 (mb->routing_type, "EX") == 0) {
-                       e_ews_connection_ex_to_smtp_sync (
-                               cnc, EWS_PRIORITY_MEDIUM,
-                               mb->name, mb->email, &email,
-                               cancellable, NULL);
-
-                       /* do not scare users with EX addresses */
-                       if (!email)
-                               email = g_strdup ("");
-               }
+               if (g_strcmp0 (mb->routing_type, "EX") == 0)
+                       email = e_ews_item_util_strip_ex_address (mb->email);
 
                str = g_string_new ("");
                if (mb->name && mb->name[0]) {
@@ -524,8 +516,6 @@ form_email_string_from_mb (EEwsConnection *cnc,
                        g_string_append (str, ">");
                }
 
-               g_free (email);
-
                return camel_pstring_add (g_string_free (str, FALSE), TRUE);
        } else
               return camel_pstring_strdup ("");
diff --git a/src/server/e-ews-item.c b/src/server/e-ews-item.c
index e681e52..5f30b56 100644
--- a/src/server/e-ews-item.c
+++ b/src/server/e-ews-item.c
@@ -2358,3 +2358,21 @@ e_ews_permissions_free (GSList *permissions)
 {
        g_slist_free_full (permissions, (GDestroyNotify) e_ews_permission_free);
 }
+
+/* strips ex_address by its LDAP-like part, returning position in ex_address where
+   common name begins; returns whole ex_address, if not found */
+const gchar *
+e_ews_item_util_strip_ex_address (const gchar *ex_address)
+{
+       const gchar *ptr;
+
+       if (!ex_address)
+               return ex_address;
+
+       ptr = strrchr (ex_address, '/');
+       if (ptr && g_ascii_strncasecmp (ptr, "/cn=", 4) == 0) {
+               return ptr + 4;
+       }
+
+       return ex_address;
+}
diff --git a/src/server/e-ews-item.h b/src/server/e-ews-item.h
index f87429e..c92f001 100644
--- a/src/server/e-ews-item.h
+++ b/src/server/e-ews-item.h
@@ -280,6 +280,10 @@ GSList *   e_ews_permissions_from_soap_param
                                                (ESoapParameter *param);
 void           e_ews_permissions_free (GSList *permissions);
 
+/* Utility functions */
+const gchar *  e_ews_item_util_strip_ex_address
+                                               (const gchar *ex_address);
+
 G_END_DECLS
 
 #endif


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