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



commit c81d3a885bb3e2937a82e3cc12cfa23f89d65f71
Author: Milan Crha <mcrha redhat com>
Date:   Fri Nov 2 10:39:26 2012 +0100

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

 modules/gnome-online-accounts/goaewsclient.c       |   41 ++++++++++++++++-
 .../module-gnome-online-accounts.c                 |   49 +++++++++++++++++++-
 2 files changed, 88 insertions(+), 2 deletions(-)
---
diff --git a/modules/gnome-online-accounts/goaewsclient.c b/modules/gnome-online-accounts/goaewsclient.c
index ab18a1d..e59e149 100644
--- a/modules/gnome-online-accounts/goaewsclient.c
+++ b/modules/gnome-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/gnome-online-accounts/module-gnome-online-accounts.c b/modules/gnome-online-accounts/module-gnome-online-accounts.c
index feb564a..45e91a3 100644
--- a/modules/gnome-online-accounts/module-gnome-online-accounts.c
+++ b/modules/gnome-online-accounts/module-gnome-online-accounts.c
@@ -22,6 +22,7 @@
 #include <config.h>
 #include <goa/goa.h>
 #include <libsecret/secret.h>
+#include <libsoup/soup.h>
 
 #include <libebackend/libebackend.h>
 
@@ -172,12 +173,33 @@ gnome_online_accounts_new_source (EGnomeOnlineAccounts *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
 gnome_online_accounts_config_exchange (EGnomeOnlineAccounts *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;
@@ -185,7 +207,8 @@ gnome_online_accounts_config_exchange (EGnomeOnlineAccounts *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.
@@ -234,11 +257,35 @@ gnome_online_accounts_config_exchange (EGnomeOnlineAccounts *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]