[evolution-patches] exchange : patch for #314746



Hi,

This is the patch for exchange code in evolution-exchange and e-d-s.
Please review it.

Thanks
-- Sarfraaz
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-exchange/ChangeLog,v
retrieving revision 1.395.2.7
diff -u -p -u -p -r1.395.2.7 ChangeLog
--- ChangeLog	21 Sep 2005 05:49:32 -0000	1.395.2.7
+++ ChangeLog	27 Sep 2005 12:43:43 -0000
@@ -1,3 +1,18 @@
+2005-09-27  Sarfraaz Ahmed <asarfraaz novell com>
+
+	* camel/camel-exchange-store.c (make_folder_info): Strip the semicolon
+	from the uri. And also create the folder path properly.
+	* storage/exchange-component.c (impl_upgradeFromVersion)
+	(config_listener_account_created): Create the account_filename 
+	separately now.
+	(exchange_component_get_account_for_uri): Synchronise the rescan tree 
+	with a lock
+	* storage/exchange-config-listener.c (update_foreign_uri)
+	(migrate_foreign_hierarchy)(ex_set_relative_uri) : Added new
+	(migrate_account_esource) : Update the new relative uri.
+	(exchange_config_listener_migrate_esources) : Take care of foreign uri
+	as well.
+
 2005-09-21  Sarfraaz Ahmed <asarfraaz novell com>
 
 	* calendar/e-cal-backend-exchange-calendar.c (create_object): Fix a
Index: camel/camel-exchange-store.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/camel/camel-exchange-store.c,v
retrieving revision 1.25.2.1
diff -u -p -u -p -r1.25.2.1 camel-exchange-store.c
--- camel/camel-exchange-store.c	8 Sep 2005 11:12:57 -0000	1.25.2.1
+++ camel/camel-exchange-store.c	27 Sep 2005 12:43:43 -0000
@@ -613,18 +613,28 @@ make_folder_info (CamelExchangeStore *ex
 	d(printf ("make folder info : %s flags : %d\n", name, flags));
 	CamelFolderInfo *info;
 	const char *path;
+	gchar **components;
+	char *new_uri;
 
 	path = strstr (uri, "://");
 	if (!path)
 		return NULL;
-	path = strchr (path + 3, '/');
+	path = strstr (path + 3, "/;");
 	if (!path)
 		return NULL;
 
+	components = g_strsplit (uri, "/;", 2);
+	if (components[0] && components[1])
+		new_uri = g_strdup_printf ("%s/%s", components[0], components[1]);
+	else
+		new_uri = g_strdup (uri);
+	g_strfreev (components);
+
+	printf ("new_uri is : %s\n", new_uri);
 	info = g_new0 (CamelFolderInfo, 1);
 	info->name = name;
-	info->uri = uri;
-	info->full_name = g_strdup (path + 1);
+	info->uri = new_uri;
+	info->full_name = g_strdup (path + 2);
 	info->unread = unread_count;
 
 	if (flags & CAMEL_STUB_FOLDER_NOSELECT)
Index: storage/exchange-component.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/storage/exchange-component.c,v
retrieving revision 1.17
diff -u -p -u -p -r1.17 exchange-component.c
--- storage/exchange-component.c	22 Aug 2005 14:22:02 -0000	1.17
+++ storage/exchange-component.c	27 Sep 2005 12:43:43 -0000
@@ -46,6 +46,7 @@
 #define PARENT_TYPE bonobo_object_get_type ()
 static BonoboObjectClass *parent_class = NULL;
 static gboolean idle_do_interactive (gpointer user_data);
+static void e_filename_make_safe (gchar *string);
 static void exchange_component_update_accounts (ExchangeComponent *component,
 							gboolean status);
 static void ex_migrate_esources (ExchangeComponent *component,
@@ -69,6 +70,8 @@ struct ExchangeComponentPrivate {
 
 	GSList *views;
 
+	GMutex *comp_lock;
+
 	GNOME_Evolution_Listener evo_listener;
 };
 
@@ -162,20 +165,26 @@ impl_upgradeFromVersion (PortableServer_
 {
 	ExchangeComponent *component = EXCHANGE_COMPONENT (bonobo_object_from_servant (servant));
 	ExchangeAccount *account;
-	const gchar *base_directory=NULL;
+	gchar *base_directory=NULL;
+	char *account_filename;
 
 	d(printf("upgradeFromVersion %d %d %d\n", major, minor, revision));
 
 	account = exchange_component_get_account_for_uri (component, NULL);
 	if (account) {
+		/*
 		base_directory = g_build_filename (g_get_home_dir (),
 						   ".evolution",
 						   "exchange",
 						   account->account_filename,
 						   NULL);
+		*/
+		base_directory = g_strdup (account->storage_dir);
+		e_filename_make_safe (base_directory);
+		account_filename = strrchr (base_directory, '/') + 1;
 
 		exchange_migrate(major, minor, revision, 
-				 base_directory, account->account_filename);
+				 base_directory, account_filename);
 				 	
 		ex_migrate_esources (component, major, minor, revision);			
 	}
@@ -310,6 +319,30 @@ exchange_component_update_accounts (Exch
 	}
 }
 
+/* SURF : Picked this from gal/util/e-util.c */
+/* This only makes a filename safe for usage as a filename.  It still may have shell meta-characters in it. */
+static void
+e_filename_make_safe (gchar *string)
+{
+	gchar *p, *ts;
+	gunichar c;
+	
+	g_return_if_fail (string != NULL);
+	p = string;
+
+	while(p && *p) {
+		c = g_utf8_get_char (p);
+		ts = p;
+		p = g_utf8_next_char (p);
+		if (!g_unichar_isprint(c) || ( c < 0xff && strchr (" /'\"`&();|<>$%{}!", c&0xff ))) {
+			while (ts<p) 	
+				*ts++ = '_';
+		}
+	}
+}
+
+
+
 static void
 new_connection (MailStubListener *listener, int cmd_fd, int status_fd,
 		ExchangeComponentAccount *baccount)
@@ -348,14 +381,17 @@ config_listener_account_created (Exchang
 	ExchangeComponent *component = user_data;
 	ExchangeComponentPrivate *priv = component->priv;
 	ExchangeComponentAccount *baccount;
-	char *path;
+	char *path, *account_filename;
 
 	baccount = g_new0 (ExchangeComponentAccount, 1);
 	baccount->account = g_object_ref (account);
 
+	account_filename = strrchr (account->storage_dir, '/') + 1;
+	e_filename_make_safe (account_filename);
+	
 	path = g_strdup_printf ("/tmp/.exchange-%s/%s",
 				g_get_user_name (),
-				account->account_filename);
+				account_filename);
 	baccount->msl = mail_stub_listener_new (path);
 	g_signal_connect (baccount->msl, "new_connection",
 			  G_CALLBACK (new_connection), baccount);
@@ -442,6 +478,8 @@ exchange_component_init (ExchangeCompone
 	priv = component->priv = g_new0 (ExchangeComponentPrivate, 1);
 
        	priv->config_listener = exchange_config_listener_new ();
+	priv->comp_lock = g_mutex_new ();
+
 	g_signal_connect (priv->config_listener, "exchange_account_created",
 			  G_CALLBACK (config_listener_account_created),
 			  component);
@@ -476,7 +514,9 @@ exchange_component_get_account_for_uri (
 		if (exchange_account_get_folder (baccount->account, uri)) {
 			return baccount->account;
 		} else {
+			g_mutex_lock (priv->comp_lock);
 			exchange_account_rescan_tree (baccount->account);
+			g_mutex_unlock (priv->comp_lock);
 			if (exchange_account_get_folder (baccount->account, uri))
 				return baccount->account;
 		}
Index: storage/exchange-config-listener.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/storage/exchange-config-listener.c,v
retrieving revision 1.30
diff -u -p -u -p -r1.30 exchange-config-listener.c
--- storage/exchange-config-listener.c	22 Aug 2005 15:24:14 -0000	1.30
+++ storage/exchange-config-listener.c	27 Sep 2005 12:43:43 -0000
@@ -39,12 +39,18 @@
 #include <libedataserver/e-source.h>
 #include <libedataserver/e-source-list.h>
 #include <libedataserver/e-source-group.h>
+#include <libedataserver/e-xml-hash-utils.h>
 
 #include <camel/camel-url.h>
 
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 
+
 struct _ExchangeConfigListenerPrivate {
 	GConfClient *gconf;
 	guint idle_id;
@@ -185,6 +191,102 @@ is_active_exchange_account (EAccount *ac
 }
 
 static void 
+update_foreign_uri (const char *path, const char *account_uri)
+{
+	char *file_path, *phy_uri, *foreign_uri, *new_phy_uri;
+	struct stat file_stat;
+	GHashTable *old_props = NULL;
+	xmlDoc *old_doc, *new_doc = NULL;
+
+	if (!path)
+		return;
+
+	file_path = g_build_filename (path, "hierarchy.xml", NULL);
+	if (stat (file_path, &file_stat) < 0)
+		goto cleanup;
+
+	old_doc = xmlParseFile (file_path);
+	if (!old_doc)
+		goto cleanup;
+
+	old_props = e_xml_to_hash (old_doc, E_XML_HASH_TYPE_PROPERTY);
+	xmlFreeDoc (old_doc);
+
+	phy_uri = g_hash_table_lookup (old_props, "physical_uri_prefix");
+	if (!phy_uri)
+		goto cleanup;
+
+	foreign_uri = strstr (phy_uri, "://");
+	if (!foreign_uri)
+		goto cleanup;
+	foreign_uri = strchr (foreign_uri + 3, '/');
+	if (!foreign_uri)
+		goto cleanup;
+
+	if ((foreign_uri + 1) && (*(foreign_uri + 1) == ';'))
+		goto cleanup;
+
+	new_phy_uri = g_strdup_printf ("exchange://%s/;%s", account_uri, foreign_uri + 1);
+	g_hash_table_steal (old_props, "physical_uri_prefix");
+	g_hash_table_insert (old_props, (char *)g_strdup ("physical_uri_prefix"), new_phy_uri);
+
+	new_doc = e_xml_from_hash (old_props, E_XML_HASH_TYPE_PROPERTY, "foreign-hierarchy");
+	xmlSaveFile (file_path, new_doc);
+
+	xmlFreeDoc (new_doc);
+	g_free (new_phy_uri);
+cleanup:
+	g_free (file_path);
+	g_hash_table_destroy (old_props);
+	return;
+}
+
+static void
+migrate_foreign_hierarchy (ExchangeAccount *account)
+{
+	DIR *d;
+	struct dirent *dentry;
+	char *dir;
+
+	d = opendir (account->storage_dir);
+	if (d) {
+		while ((dentry = readdir (d))) {
+			if (!strchr (dentry->d_name, '@'))
+				continue;
+			dir = g_strdup_printf ("%s/%s", account->storage_dir, 
+							dentry->d_name);
+			printf ("account filename : %s\n", account->account_filename);
+			update_foreign_uri (dir, account->account_filename);
+			g_free (dir);
+		}
+		closedir (d);
+	}
+}
+
+static void
+ex_set_relative_uri (ESource *source, const char *url)
+{
+	const char *rel_uri = e_source_peek_relative_uri (source);
+	char *folder_name;
+	char *new_rel_uri;
+
+	if (!rel_uri)
+		return;
+
+	printf ("rrrrrrrrrel uri : %s\n", rel_uri);
+	folder_name = strchr (rel_uri, '/');
+	if (!folder_name)
+		return;
+
+	if ((folder_name + 1) && *(folder_name + 1) == ';') 
+		return;
+
+	new_rel_uri = g_strdup_printf ("%s;%s", url, folder_name + 1);
+	printf ("new uri : %s\n", new_rel_uri);
+	e_source_set_relative_uri (source, new_rel_uri);
+}
+
+static void 
 migrate_account_esource (EAccount *account, 
 		        FolderType folder_type)
 {
@@ -196,13 +298,16 @@ migrate_account_esource (EAccount *accou
 	const char *user_name, *authtype;
 	GConfClient *client;
 	ESourceList *source_list = NULL;
-	E2kUri *e2kuri;
+	CamelURL *camel_url;
+	char *url_string;
 
-	e2kuri = e2k_uri_new (account->source->url);
-	if (!e2kuri)
+	camel_url = camel_url_new (account->source->url, NULL);
+	if (!camel_url)
 		return;
-	user_name = e2kuri->user;
-	authtype = e2kuri->authmech;
+	user_name = camel_url->user;
+	authtype  = camel_url->authmech;
+	url_string = camel_url_to_string (camel_url, CAMEL_URL_HIDE_PASSWORD | CAMEL_URL_HIDE_PARAMS);
+	printf ("camel url string : %s\n", url_string);
 
 	if (!user_name) 
 		return;
@@ -234,6 +339,8 @@ migrate_account_esource (EAccount *accou
 			for( ; sources != NULL; sources = g_slist_next (sources)) {
 				source = E_SOURCE (sources->data);
 
+				ex_set_relative_uri (source, url_string + strlen ("exchange://"));
+				printf ("modified esource for : %s\n", url_string);
 				e_source_set_property (source, "username", user_name);
 				e_source_set_property (source, "auth-domain", "Exchange");
 				if (authtype)
@@ -254,12 +361,14 @@ void
 exchange_config_listener_migrate_esources (ExchangeConfigListener *config_listener)
 {
 	g_return_if_fail (config_listener != NULL);
+	printf ("migrate esources\n");
 
 	EAccount *account = config_listener->priv->configured_account;
 
 	migrate_account_esource (account, EXCHANGE_CALENDAR_FOLDER);
 	migrate_account_esource (account, EXCHANGE_TASKS_FOLDER);
 	migrate_account_esource (account, EXCHANGE_CONTACTS_FOLDER);
+	migrate_foreign_hierarchy (config_listener->priv->exchange_account);
 }
 
 static void
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/exchange/ChangeLog,v
retrieving revision 1.29.2.2
diff -u -p -u -p -r1.29.2.2 ChangeLog
--- ChangeLog	23 Sep 2005 10:59:35 -0000	1.29.2.2
+++ ChangeLog	27 Sep 2005 12:54:43 -0000
@@ -1,3 +1,16 @@
+2005-08-26  Sarfraaz Ahmed <asarfraaz novell com>
+
+        * lib/e2k-autoconfig.c (e2k_validate_user) : Fix the password key to
+        be consistent with the camel key.
+        * storage/e-folder-exchange.c (sanitize_path) : Strips the ';' in the
+        path.
+        * storage/exchange-account.c (get_hierarchy_for)
+        (setup_account_hierarchies) : Fix the physical uri to delimit the
+        folder path from the uri with a ';'
+        (exchange_account_new) : Fix the uri authority to be same as the camel
+        uri which would be later used in all components for creating the
+        password key.
+
 2005-09-05  Praveen Kumar  <kpraveen novell com>
 
         ** Fixes bug 314588.
Index: lib/e2k-autoconfig.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/exchange/lib/e2k-autoconfig.c,v
retrieving revision 1.4
diff -u -p -u -p -r1.4 e2k-autoconfig.c
--- lib/e2k-autoconfig.c	31 Aug 2005 04:26:08 -0000	1.4
+++ lib/e2k-autoconfig.c	27 Sep 2005 12:54:44 -0000
@@ -1568,6 +1568,7 @@ e2k_validate_user (const char *owa_url, 
 	char *key, *password, *prompt;
 
 	key = g_strdup_printf ("%s//%s %s", "exchange:", user, owa_url); /* FIXME */
+		
 	password = e_passwords_get_password ("Exchange", key);
 	if (!password) {
 		prompt = g_strdup_printf (_("Enter password for %s"), user);
@@ -1587,8 +1588,11 @@ e2k_validate_user (const char *owa_url, 
 
 				*remember_password = remember;
 				g_free (key);
-				key = g_strdup_printf ("%s//%s %s", 
-						       "exchange:", user, exchange_params->host);
+				if (exchange_params->is_ntlm)
+					key = g_strdup_printf ("exchange://%s;auth=NTLM %s/", 
+								       user, exchange_params->host);
+				else
+					key = g_strdup_printf ("exchange://%s %s/", user, exchange_params->host);
 				e_passwords_add_password (key, password);
 				e_passwords_remember_password ("Exchange", key);
 			}
Index: storage/e-folder-exchange.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/exchange/storage/e-folder-exchange.c,v
retrieving revision 1.6
diff -u -p -u -p -r1.6 e-folder-exchange.c
--- storage/e-folder-exchange.c	31 Aug 2005 04:26:09 -0000	1.6
+++ storage/e-folder-exchange.c	27 Sep 2005 12:54:44 -0000
@@ -45,7 +45,7 @@ struct _EFolderExchangePrivate {
 	ExchangeHierarchy *hier;
 	char *internal_uri, *permanent_uri;
 	char *outlook_class, *storage_dir;
-	const char *path;
+	char *path;
 	long long int folder_size;
 	gboolean has_subfolders;
 };
@@ -98,6 +98,7 @@ finalize (GObject *object)
 	g_free (folder->priv->permanent_uri);
 	g_free (folder->priv->outlook_class);
 	g_free (folder->priv->storage_dir);
+	g_free (folder->priv->path);
 	g_free (folder->priv);
 
 	G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -147,6 +148,26 @@ e_mkdir_hier(const char *path, mode_t mo
 	return 0;
 }
 
+static char *
+sanitize_path (const char *path)
+{
+	gchar **comps;
+	char *new_path = NULL;
+
+	if (!path)
+		return;
+
+	comps = g_strsplit (path, ";", 2);
+	if (comps[1])
+		new_path = g_strdup_printf ("%s%s", comps[0], comps[1]);
+	else if (comps[0])
+		new_path = g_strdup (comps[0]);
+
+	g_strfreev (comps);
+	return new_path;	
+}
+
+
 /**
  * e_folder_exchange_new:
  * @hier: the #ExchangeHierarchy containing the new folder
@@ -181,7 +202,7 @@ e_folder_exchange_new (ExchangeHierarchy
 	efe->priv->hier = hier;
 	g_object_ref (hier);
 	efe->priv->internal_uri = g_strdup (internal_uri);
-	efe->priv->path = e2k_uri_path (e_folder_get_physical_uri (ef));
+	efe->priv->path = sanitize_path (e2k_uri_path (e_folder_get_physical_uri (ef)));
 	efe->priv->outlook_class = g_strdup (outlook_class);
 
 	/* Add ESources */
Index: storage/exchange-account.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/exchange/storage/exchange-account.c,v
retrieving revision 1.16
diff -u -p -u -p -r1.16 exchange-account.c
--- storage/exchange-account.c	31 Aug 2005 04:26:09 -0000	1.16
+++ storage/exchange-account.c	27 Sep 2005 12:54:44 -0000
@@ -370,6 +370,7 @@ hierarchy_new_folder (ExchangeHierarchy 
 		g_hash_table_insert (account->priv->folders,
 				     key,
 				     folder);
+		printf ("added path : %s\n", key);
 		table_updated = 1;
 	}
 
@@ -388,6 +389,7 @@ hierarchy_new_folder (ExchangeHierarchy 
 		g_hash_table_insert (account->priv->folders,
 				     key,
 				     folder);
+		printf ("added phy path : %s\n", key);
 		table_updated = 1;
 	}
 
@@ -400,6 +402,7 @@ hierarchy_new_folder (ExchangeHierarchy 
 		g_hash_table_insert (account->priv->folders,
 				     key,
 				     folder);
+		printf ("added int path : %s\n", key);
 		table_updated = 1;
 	}
 
@@ -624,7 +627,7 @@ get_hierarchy_for (ExchangeAccount *acco
 					  entry->display_name);
 	source = g_strdup_printf ("exchange://%s %s/", entry->mailbox,
 				  account->exchange_server);
-	physical_uri_prefix = g_strdup_printf ("exchange://%s/%s",
+	physical_uri_prefix = g_strdup_printf ("exchange://%s/;%s",
 					       account->priv->uri_authority,
 					       entry->email);
 	internal_uri_prefix = exchange_account_get_foreign_uri (account, entry,
@@ -1261,7 +1264,7 @@ setup_account_hierarchies (ExchangeAccou
 		return FALSE;
 
 	/* Set up Personal Folders hierarchy */
-	phys_uri_prefix = g_strdup_printf ("exchange://%s/personal",
+	phys_uri_prefix = g_strdup_printf ("exchange://%s/;personal",
 					   account->priv->uri_authority);
 	hier = exchange_hierarchy_webdav_new (account,
 					      EXCHANGE_HIERARCHY_PERSONAL,
@@ -1277,7 +1280,7 @@ setup_account_hierarchies (ExchangeAccou
 	personal_hier = hier;
 
 	/* Favorite Public Folders */
-	phys_uri_prefix = g_strdup_printf ("exchange://%s/favorites",
+	phys_uri_prefix = g_strdup_printf ("exchange://%s/;favorites",
 					   account->priv->uri_authority);
 	hier = exchange_hierarchy_favorites_new (account,
 						 _("Favorite Public Folders"),
@@ -1292,7 +1295,7 @@ setup_account_hierarchies (ExchangeAccou
 	account->priv->favorites_hierarchy = hier;
 
 	/* Public Folders */
-	phys_uri_prefix = g_strdup_printf ("exchange://%s/public",
+	phys_uri_prefix = g_strdup_printf ("exchange://%s/;public",
 					   account->priv->uri_authority);
 	hier = exchange_hierarchy_webdav_new (account,
 					      EXCHANGE_HIERARCHY_PUBLIC,
@@ -2024,7 +2027,7 @@ ExchangeAccount *
 exchange_account_new (EAccountList *account_list, EAccount *adata)
 {
 	ExchangeAccount *account;
-	char *enc_user, *mailbox;
+	char *enc_user, *mailbox, *old_uri_authority;
 	const char *param, *proto="http", *owa_path, *pf_server, *owa_url; 
 	const char *passwd_exp_warn_period, *offline_sync;
 	E2kUri *uri;
@@ -2047,8 +2050,8 @@ exchange_account_new (EAccountList *acco
 	account->storage_dir = g_strdup_printf ("%s/.evolution/exchange/%s %s",
 						g_get_home_dir (),
 						uri->user, uri->host);
-	account->account_filename = strrchr (account->storage_dir, '/') + 1;
-	e_filename_make_safe (account->account_filename);
+	/*account->account_filename = strrchr (account->storage_dir, '/') + 1;
+	e_filename_make_safe (account->account_filename); */
 
 	/* Identity info */
 	account->priv->identity_name = g_strdup (adata->id->name);
@@ -2056,16 +2059,24 @@ exchange_account_new (EAccountList *acco
 
 	/* URI, etc, info */
 	enc_user = e2k_uri_encode (uri->user, FALSE, "@/;:");
-	account->priv->uri_authority = g_strdup_printf ("%s %s", enc_user,
+	old_uri_authority = g_strdup_printf ("%s %s", enc_user,
 							uri->host);
+	if (uri->authmech)
+		account->priv->uri_authority = g_strdup_printf ("%s;auth=%s %s", enc_user,
+								uri->authmech, uri->host);
+	else
+		account->priv->uri_authority = g_strdup_printf ("%s %s", enc_user,
+								uri->host);
 	g_free (enc_user);
 
+	account->account_filename = account->priv->uri_authority;
+
 	account->priv->source_uri = g_strdup_printf ("exchange://%s/", account->priv->uri_authority);
 
 	/* Backword compatibility; FIXME, we should just migrate the
 	 * password from this to source_uri.
 	 */
-	account->priv->password_key = g_strdup_printf ("exchange://%s", account->priv->uri_authority);
+	account->priv->password_key = g_strdup_printf ("exchange://%s", old_uri_authority);
 
 	account->priv->username = g_strdup (uri->user);
 	if (uri->domain)


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