[evolution-ews/gnome-3-4] Bug #679305 - EX addresses not decoded in folder summary
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews/gnome-3-4] Bug #679305 - EX addresses not decoded in folder summary
- Date: Wed, 4 Jul 2012 11:02:46 +0000 (UTC)
commit 7d6d159a3fc9b8b888096247a0fc17dc64fd3da7
Author: Milan Crha <mcrha redhat com>
Date: Wed Jul 4 13:02:28 2012 +0200
Bug #679305 - EX addresses not decoded in folder summary
src/calendar/e-cal-backend-ews.c | 6 ++-
src/camel/camel-ews-utils.c | 6 ++-
src/server/e-ews-connection.c | 144 +++++++++++++++++++++++---------------
src/server/e-ews-connection.h | 1 +
src/server/e-ews-item.c | 2 +-
5 files changed, 99 insertions(+), 60 deletions(-)
---
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index 740e6db..9d165d2 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -3079,8 +3079,12 @@ add_item_to_cache (ECalBackendEws *cbews,
if (g_strcmp0 (attendee->mailbox->mb_type, "EX") == 0) {
e_ews_connection_ex_to_smtp_sync (
cnc, EWS_PRIORITY_MEDIUM,
- attendee->mailbox->email, &email,
+ attendee->mailbox->name, attendee->mailbox->email, &email,
NULL, NULL);
+
+ /* do not scare users with EX addresses */
+ if (!email)
+ email = g_strdup ("");
}
/*remove organizer for attendees list*/
diff --git a/src/camel/camel-ews-utils.c b/src/camel/camel-ews-utils.c
index f889e84..4fb1842 100644
--- a/src/camel/camel-ews-utils.c
+++ b/src/camel/camel-ews-utils.c
@@ -804,8 +804,12 @@ form_email_string_from_mb (EEwsConnection *cnc,
if (g_strcmp0 (mb->mb_type, "EX") == 0) {
e_ews_connection_ex_to_smtp_sync (
cnc, EWS_PRIORITY_MEDIUM,
- mb->email, &email,
+ mb->name, mb->email, &email,
cancellable, NULL);
+
+ /* do not scare users with EX addresses */
+ if (!email)
+ email = g_strdup ("");
}
str = g_string_new ("");
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index 9a673a5..e628377 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -3748,9 +3748,91 @@ e_ews_connection_move_folder (EEwsConnection *cnc,
return result;
}
+static void
+ews_connection_resolve_by_name (EEwsConnection *cnc,
+ gint pri,
+ const gchar *usename,
+ gboolean is_user_name,
+ gchar **smtp_address,
+ GCancellable *cancellable)
+{
+ GSList *mailboxes = NULL;
+ GSList *contacts = NULL;
+ gboolean includes_last_item = FALSE;
+ GSList *miter;
+ gint len;
+
+ g_return_if_fail (cnc != NULL);
+ g_return_if_fail (usename != NULL);
+ g_return_if_fail (smtp_address != NULL);
+
+ if (!*usename)
+ return;
+
+ len = strlen (usename);
+ mailboxes = NULL;
+ contacts = NULL;
+
+ /* use the first error, not the guess-part error */
+ e_ews_connection_resolve_names (
+ cnc, pri, usename,
+ EWS_SEARCH_AD_CONTACTS, NULL, TRUE, &mailboxes, &contacts,
+ &includes_last_item, cancellable, NULL);
+
+ for (miter = mailboxes; miter; miter = miter->next) {
+ const EwsMailbox *mailbox = miter->data;
+ if (mailbox->email && *mailbox->email && g_strcmp0 (mailbox->mb_type, "EX") != 0
+ && ((!is_user_name && g_str_has_prefix (mailbox->email, usename) && mailbox->email[len] == '@') ||
+ (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;
+ gboolean found = FALSE;
+
+ 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)))) {
+ found = TRUE;
+ break;
+ }
+ }
+
+ g_list_free (emails);
+
+ if (found) {
+ gint ii;
+
+ for (ii = 0; ii < g_hash_table_size (resolved->email_addresses); ii++) {
+ gchar *key, *value;
+
+ key = g_strdup_printf ("EmailAddress%d", ii + 1);
+ value = g_hash_table_lookup (resolved->email_addresses, key);
+ g_free (key);
+
+ if (value && g_str_has_prefix (value, "SMTP:")) {
+ /* pick the first available SMTP address */
+ *smtp_address = g_strdup (value + 5);
+ break;
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ g_slist_free_full (mailboxes, (GDestroyNotify) e_ews_mailbox_free);
+ g_slist_free_full (contacts, (GDestroyNotify) e_ews_free_resolve_contact);
+}
+
gboolean
e_ews_connection_ex_to_smtp_sync (EEwsConnection *cnc,
gint pri,
+ const gchar *name,
const gchar *ex_address,
gchar **smtp_address,
GCancellable *cancellable,
@@ -3804,67 +3886,15 @@ e_ews_connection_ex_to_smtp_sync (EEwsConnection *cnc,
usename = strrchr (ex_address, '/');
if (usename && g_ascii_strncasecmp (usename, "/cn=", 4) == 0) {
- GSList *miter;
- gint len;
-
usename += 4;
- len = strlen (usename);
- mailboxes = NULL;
- contacts = NULL;
-
- /* use the first error, not the guess-part error */
- e_ews_connection_resolve_names (
- cnc, pri, usename,
- EWS_SEARCH_AD_CONTACTS, NULL, TRUE, &mailboxes, &contacts,
- &includes_last_item, cancellable, NULL);
/* try to guess from common name of the EX address */
- for (miter = mailboxes; miter; miter = miter->next) {
- const EwsMailbox *mailbox = miter->data;
- if (mailbox->email && *mailbox->email && g_strcmp0 (mailbox->mb_type, "EX") != 0
- && g_str_has_prefix (mailbox->email, usename) && mailbox->email[len] == '@') {
- *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;
- gboolean found = FALSE;
-
- for (iter = emails; iter && !found; iter = iter->next) {
- const gchar *it_email = iter->data;
-
- if (it_email && g_str_has_prefix (it_email, "SMTP:")
- && g_str_has_prefix (it_email, usename) && it_email[len] == '@') {
- found = TRUE;
- break;
- }
- }
-
- g_list_free (emails);
-
- if (found) {
- gint ii;
-
- for (ii = 0; ii < g_hash_table_size (resolved->email_addresses); ii++) {
- gchar *key, *value;
-
- key = g_strdup_printf ("EmailAddress%d", ii + 1);
- value = g_hash_table_lookup (resolved->email_addresses, key);
- g_free (key);
-
- if (value && g_str_has_prefix (value, "SMTP:")) {
- /* pick the first available SMTP address */
- *smtp_address = g_strdup (value + 5);
- break;
- }
- }
- break;
- }
- }
- }
+ ews_connection_resolve_by_name (cnc, pri, usename, FALSE, smtp_address, cancellable);
+ }
- g_slist_free_full (mailboxes, (GDestroyNotify) e_ews_mailbox_free);
- g_slist_free_full (contacts, (GDestroyNotify) e_ews_free_resolve_contact);
+ if (!*smtp_address && name && *name) {
+ /* try to guess from mailbox name */
+ ews_connection_resolve_by_name (cnc, pri, name, TRUE, smtp_address, cancellable);
}
}
diff --git a/src/server/e-ews-connection.h b/src/server/e-ews-connection.h
index f47b460..bff0fb2 100644
--- a/src/server/e-ews-connection.h
+++ b/src/server/e-ews-connection.h
@@ -488,6 +488,7 @@ gboolean e_ews_connection_resolve_names (EEwsConnection *cnc,
gboolean e_ews_connection_ex_to_smtp_sync
(EEwsConnection *cnc,
gint pri,
+ const gchar *name,
const gchar *ex_address,
gchar **smtp_address,
GCancellable *cancellable,
diff --git a/src/server/e-ews-item.c b/src/server/e-ews-item.c
index 5940fa1..e2478b1 100644
--- a/src/server/e-ews-item.c
+++ b/src/server/e-ews-item.c
@@ -1394,7 +1394,7 @@ e_ews_item_mailbox_from_soap_param (ESoapParameter *param)
if (subparam)
mb->mb_type = e_soap_parameter_get_string_value (subparam);
- if (!mb->email) {
+ if (!mb->email && !mb->name) {
e_ews_mailbox_free (mb);
mb = NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]