[evolution-data-server/gnome-3-6] Bug #685090 - GOA EWS module doesn't save all required values



commit 8f1a9518da373d081c9a7475c64cf58563709bd0
Author: Milan Crha <mcrha redhat com>
Date:   Fri Nov 2 10:40:07 2012 +0100

    Bug #685090 - GOA EWS module doesn't save all required values

 modules/online-accounts/goaewsclient.c           |   41 ++++++++++++++++++-
 modules/online-accounts/module-online-accounts.c |   49 +++++++++++++++++++++-
 2 files changed, 88 insertions(+), 2 deletions(-)
---
diff --git a/modules/online-accounts/goaewsclient.c b/modules/online-accounts/goaewsclient.c
index ab18a1d..e59e149 100644
--- a/modules/online-accounts/goaewsclient.c
+++ b/modules/online-accounts/goaewsclient.c
@@ -115,6 +115,30 @@ ews_autodiscover_cancelled_cb (GCancellable *cancellable,
 }
 
 static gboolean
+has_suffix_icmp (const gchar *text,
+		 const gchar *suffix)
+{
+	gint ii, tlen, slen;
+
+	g_return_val_if_fail (text != NULL, FALSE);
+	g_return_val_if_fail (suffix != NULL, FALSE);
+
+	tlen = strlen (text);
+	slen = strlen (suffix);
+
+	if (!*text || !*suffix || tlen < slen)
+		return FALSE;
+
+	for (ii = 0; ii < slen; ii++) {
+		if (g_ascii_tolower (text[tlen - ii - 1]) != 
+		    g_ascii_tolower (suffix[slen - ii - 1]))
+			break;
+	}
+
+	return ii == slen;
+}
+
+static gboolean
 ews_autodiscover_parse_protocol (xmlNode *node,
                                  AutodiscoverData *data)
 {
@@ -131,8 +155,23 @@ ews_autodiscover_parse_protocol (xmlNode *node,
 			got_as_url = TRUE;
 
 		} else if (ews_check_node (node, "OABUrl")) {
+			const gchar *oab_url;
+
 			content = xmlNodeGetContent (node);
-			data->oab_url = g_strdup ((gchar *) content);
+			oab_url = (const char *) content;
+
+			if (!has_suffix_icmp (oab_url, "oab.xml")) {
+				gchar *tmp;
+
+				if (g_str_has_suffix (oab_url, "/"))
+					tmp = g_strconcat (oab_url, "oab.xml", NULL);
+				else
+					tmp = g_strconcat (oab_url, "/", "oab.xml", NULL);
+
+				data->oab_url = tmp; /* takes ownership */
+			} else {
+				data->oab_url = g_strdup (oab_url);
+			}
 			xmlFree (content);
 			got_oab_url = TRUE;
 		}
diff --git a/modules/online-accounts/module-online-accounts.c b/modules/online-accounts/module-online-accounts.c
index 27ea615..7a48124 100644
--- a/modules/online-accounts/module-online-accounts.c
+++ b/modules/online-accounts/module-online-accounts.c
@@ -22,6 +22,7 @@
 #include <config.h>
 #include <goa/goa.h>
 #include <gnome-keyring.h>
+#include <libsoup/soup.h>
 
 #include <libebackend/libebackend.h>
 
@@ -168,12 +169,33 @@ online_accounts_new_source (EOnlineAccounts *extension)
 	return source;
 }
 
+#ifdef HAVE_GOA_PASSWORD_BASED
+static void
+replace_host (gchar **url,
+	      const gchar *host)
+{
+	SoupURI *uri;
+
+	uri = soup_uri_new (*url);
+	if (!uri)
+		return;
+
+	soup_uri_set_host (uri, host);
+
+	g_free (*url);
+	*url = soup_uri_to_string (uri, FALSE);
+
+	soup_uri_free (uri);
+}
+#endif /* HAVE_GOA_PASSWORD_BASED */
+
 static void
 online_accounts_config_exchange (EOnlineAccounts *extension,
                                  ESource *source,
                                  GoaObject *goa_object)
 {
 #ifdef HAVE_GOA_PASSWORD_BASED
+	GoaExchange *goa_exchange;
 	ESourceExtension *source_extension;
 	const gchar *extension_name;
 	gchar *as_url = NULL;
@@ -181,7 +203,8 @@ online_accounts_config_exchange (EOnlineAccounts *extension,
 	gpointer class;
 	GError *error = NULL;
 
-	if (goa_object_peek_exchange (goa_object) == NULL)
+	goa_exchange = goa_object_peek_exchange (goa_object);
+	if (goa_exchange == NULL)
 		return;
 
 	/* This should force the ESourceCamelEws type to be registered.
@@ -230,11 +253,35 @@ online_accounts_config_exchange (EOnlineAccounts *extension,
 
 	/* This will be NULL if Evolution-EWS is not installed. */
 	if (source_extension != NULL) {
+		GoaAccount *goa_account;
+		gchar *host, *user, *email;
+
+		goa_account = goa_object_peek_account (goa_object);
+		host = goa_exchange_dup_host (goa_exchange);
+		user = goa_account_dup_identity (goa_account);
+		email = goa_account_dup_presentation_identity (goa_account);
+
+		if (host && *host) {
+			replace_host (&as_url, host);
+			replace_host (&oab_url, host);
+		}
+
 		g_object_set (
 			source_extension,
 			"hosturl", as_url,
 			"oaburl", oab_url,
+			"email", email,
+			NULL);
+
+		g_object_set (e_source_camel_get_settings (E_SOURCE_CAMEL (source_extension)),
+			"host", host,
+			"user", user,
+			"email", email,
 			NULL);
+
+		g_free (host);
+		g_free (user);
+		g_free (email);
 	} else {
 		g_critical (
 			"%s: Failed to create [%s] extension",



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