Index: plugins/exchange-operations/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/ChangeLog,v
retrieving revision 1.86
diff -u -p -r1.86 ChangeLog
--- plugins/exchange-operations/ChangeLog	18 Jan 2006 12:55:50 -0000	1.86
+++ plugins/exchange-operations/ChangeLog	23 Jan 2006 15:12:53 -0000
@@ -1,3 +1,14 @@
+2006-01-23  Sushma Rai  <rsushma@novell.com>
+
+	* exchange-calendar.c (e_exchange_calendar_commit): Prevent leaking 
+	uri_text in case of OFFLINE mode.
+	Instead of terminating memory allocated string tmpruri and using it, 
+	tokenizing the URI and forming the path without semicolon.
+	Also, renaming the folder only in case of folder names differ. 
+	Fixes #328304.
+	
+	* exchange-contacts.c (e_exchange_contacts_commit): Similar. 
+
 2006-01-18  Sushma Rai  <rsushma@novell.com>
 
 	* exchange-contacts.c (e_exchange_contacts_pcontacts): Displaying the
Index: plugins/exchange-operations/exchange-calendar.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-calendar.c,v
retrieving revision 1.13
diff -u -p -r1.13 exchange-calendar.c
--- plugins/exchange-operations/exchange-calendar.c	6 Jan 2006 06:49:25 -0000	1.13
+++ plugins/exchange-operations/exchange-calendar.c	23 Jan 2006 15:13:16 -0000
@@ -322,7 +322,7 @@ e_exchange_calendar_commit (EPlugin *epl
 {
 	ECalConfigTargetSource *t = (ECalConfigTargetSource *) target;
 	ESource *source = t->source;
-	gchar *uri_text, *gruri, *gname, *ruri, *ftype, *path, *path_prefix, *oldpath=NULL;
+	gchar *uri_text, *gruri, *gname, *ruri, *ftype, *path = NULL, *path_prefix, *oldpath=NULL;
 	gchar *username, *authtype;
 	int prefix_len;
 	ExchangeAccount *account;
@@ -335,6 +335,7 @@ e_exchange_calendar_commit (EPlugin *epl
 		g_free (uri_text);
 		return ;
 	}	
+	g_free (uri_text);
 
 	status = exchange_is_offline (&offline_status);
 	if (offline_status == OFFLINE_MODE || status != CONFIG_LISTENER_STATUS_OK)
@@ -363,12 +364,24 @@ e_exchange_calendar_commit (EPlugin *epl
 	gname = (gchar*) e_source_peek_name (source);
 	gruri = (gchar*) e_source_peek_relative_uri (source);
 	if (calendar_src_exists) {
-		gchar *tmpruri, *tmpdelimit;
-		tmpruri = g_strdup (gruri);
-		tmpdelimit = g_strrstr (tmpruri, "/");
-		tmpdelimit[0] = '\0';
-		ruri = g_strconcat (tmpruri, "/", gname, NULL);
-		g_free (tmpruri);
+		char **tokens;
+
+		tokens = g_strsplit (gruri, ";", 3);
+		if (tokens [2]) {
+			/* sample URI: user;auth=Basic@server/;personal/Calendar */
+			ruri = g_strdup_printf ("%s;%s%s", tokens[0], tokens[1], tokens[2]);
+			path = g_build_filename ("/", ruri+(prefix_len-1), NULL);
+		}
+		else if (tokens [1] && gname) {
+			/* Will this happen ever? */
+			/* sample URI: user@server/;personal/Calendar */
+			ruri = g_strdup_printf ("%s%s", tokens[0], tokens[1]);
+			path = g_build_filename ("/", ruri+(prefix_len-1), NULL);
+		} 
+		else {
+			ruri = g_strdup (gruri);
+		}
+		g_strfreev (tokens);
 	}
 	else {
 		ruri = g_strconcat (gruri, "/", gname, NULL);
@@ -380,15 +393,17 @@ e_exchange_calendar_commit (EPlugin *epl
 		 e_source_set_property (source, "auth-type", authtype);
 	e_source_set_property (source, "auth", "1");
 
-	path = g_build_filename ("/", ruri+prefix_len, NULL);
+	if (!path)
+		path = g_build_filename ("/", ruri+prefix_len, NULL);
+
+	oldpath = g_build_filename ("/", calendar_old_source_uri+prefix_len, NULL);
 	
 	if (!calendar_src_exists) {
 		/* Create the new folder */
 		result = exchange_account_create_folder (account, path, ftype);
 	}
-	else if (gruri && strcmp (gruri, calendar_old_source_uri)) {
+	else if (gruri && strcmp (gruri, calendar_old_source_uri) && strcmp (path, oldpath)) {
 		/* Rename the folder */
-		oldpath = g_build_filename ("/", calendar_old_source_uri+prefix_len, NULL);
 		result = exchange_account_xfer_folder (account, oldpath, path, TRUE);
 		exchange_operations_update_child_esources (source, 
 							   calendar_old_source_uri, 
@@ -426,7 +441,6 @@ e_exchange_calendar_commit (EPlugin *epl
 	}
 
 done:	
-	g_free (uri_text);
 	g_free (ruri);
 	g_free (path);
 	g_free (ftype);
Index: plugins/exchange-operations/exchange-contacts.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-contacts.c,v
retrieving revision 1.13
diff -u -p -r1.13 exchange-contacts.c
--- plugins/exchange-operations/exchange-contacts.c	18 Jan 2006 12:55:50 -0000	1.13
+++ plugins/exchange-operations/exchange-contacts.c	23 Jan 2006 15:13:35 -0000
@@ -339,12 +339,23 @@ e_exchange_contacts_commit (EPlugin *epl
 	gname = (gchar*) e_source_peek_name (source);
 	gruri = (gchar*) e_source_peek_relative_uri (source);
 	if (contacts_src_exists) {
-		gchar *tmpruri, *tmpdelimit;
-		tmpruri = g_strdup (gruri);
-		tmpdelimit = g_strrstr (tmpruri, "/");
-		tmpdelimit[0] = '\0';
-		ruri = g_strconcat (tmpruri, "/", gname, NULL);
-		g_free (tmpruri);
+		char **tokens;
+
+		tokens = g_strsplit (gruri, ";", 3);
+		if (tokens [2]) {
+			/* sample URI: user;auth=Basic@server/;personal/Contacts */
+			ruri = g_strdup_printf ("%s;%s%s", tokens[0], tokens[1], tokens[2]);
+			path = g_build_filename ("/", ruri+(prefix_len-1), NULL);
+		}
+		else if (tokens [1] && gname) {
+			/* Will this happen ever? */
+			/* sample URI: user@server/;personal/Contacts */
+			ruri = g_strdup_printf ("%s%s", tokens[0], tokens[1]);
+			path = g_build_filename ("/", ruri+(prefix_len-1), NULL);
+		} else {
+			ruri = g_strdup (gruri);
+		}
+		g_strfreev (tokens);
 	}
 	else {
 		ruri = g_strconcat (gruri, "/", gname, NULL);
@@ -356,15 +367,16 @@ e_exchange_contacts_commit (EPlugin *epl
 		e_source_set_property (source, "auth-type", authtype);
 	e_source_set_property (source, "auth", "plain/password");
 
-	path = g_strdup_printf ("/%s", ruri+prefix_len);
+	if (!path)
+		path = g_build_filename ("/", ruri+prefix_len, NULL);
+	oldpath = g_build_filename ("/", contacts_old_src_uri+prefix_len, NULL);
 
 	if (!contacts_src_exists) {
 		/* Create the new folder */
 		result = exchange_account_create_folder (account, path, "contacts");
 	}
-	else if (strcmp (gruri, contacts_old_src_uri)) {
+	else if (gruri && strcmp (gruri, contacts_old_src_uri) && strcmp (path, oldpath)) {
 		/* Rename the folder */
-		oldpath = g_strdup_printf ("/%s", contacts_old_src_uri+prefix_len);
 		result = exchange_account_xfer_folder (account, oldpath, path, TRUE);
 		exchange_operations_update_child_esources (source, 
 							   contacts_old_src_uri, 
