[evolution-patches] Exchange, linestatus fix.



Hi,

Sets the default linestatus mode to offline
and fixes camel authentication code to properly
handler error cases.

Please review it.

Thanks,
Arunprakash.

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-exchange/ChangeLog,v
retrieving revision 1.388
diff -u -p -r1.388 ChangeLog
--- ChangeLog	24 Aug 2005 12:06:25 -0000	1.388
+++ ChangeLog	26 Aug 2005 08:53:55 -0000
@@ -1,3 +1,22 @@
+2005-08-26  Arunprakash  <arunp novell com>
+
+	* addressbook/e-book-backend-exchange.c (e_book_backend_exchange_init):
+	Set the default mode to local.
+	* addressbook/e-book-backend-gal.c (set_mode) : Removed exchange
+	account set offline and connect calls, as they should be called
+	by appropriate listeners.
+	* calendar/e-cal-backend-exchange.c (set_mode) : Similar.
+	(init) : Set the default mode to local.
+	* camel/camel-exchange-store.c (camel_exchange_forget_password) : Newly
+	added to forget the password in case of wrong password.
+	(exchange_connect) : Updated to properly ask and forget password in
+	needed cases.
+	* mail/mail-stub-exchange.c (get_folder_online) : Flushes the status
+	channel if called in background.
+	(stub_connect) : Updated to return failure only when connection fails.
+	Removed the linestatus signal handler as it is done while connecting.
+	Also to update each folder's data in online.
+	
 2005-08-23  Arunprakash  <arunp novell com>
 
 	* calendar/e-cal-backend-exchange-calendar.c (book_resource) :
Index: addressbook/e-book-backend-exchange.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/addressbook/e-book-backend-exchange.c,v
retrieving revision 1.39
diff -u -p -r1.39 e-book-backend-exchange.c
--- addressbook/e-book-backend-exchange.c	22 Aug 2005 14:22:00 -0000	1.39
+++ addressbook/e-book-backend-exchange.c	26 Aug 2005 08:53:57 -0000
@@ -2485,6 +2485,7 @@ e_book_backend_exchange_init (EBookBacke
 	priv->cache		= NULL;
 	priv->original_uri 	= NULL;
 	priv->is_writable 	= TRUE;
+	priv->mode		= GNOME_Evolution_Addressbook_MODE_LOCAL;
 
 	priv->create_mutex      = g_mutex_new ();
 
Index: addressbook/e-book-backend-gal.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/addressbook/e-book-backend-gal.c,v
retrieving revision 1.27
diff -u -p -r1.27 e-book-backend-gal.c
--- addressbook/e-book-backend-gal.c	17 Aug 2005 06:07:32 -0000	1.27
+++ addressbook/e-book-backend-gal.c	26 Aug 2005 08:53:58 -0000
@@ -1726,26 +1726,20 @@ set_mode (EBookBackend *backend, int mod
 
 	if (e_book_backend_is_loaded (backend)) {
 		if (mode == GNOME_Evolution_Addressbook_MODE_LOCAL) {
-			if (bepriv->account) {
-			if (exchange_account_set_offline (bepriv->account)) {
-				e_book_backend_set_is_writable (backend, FALSE);
-				e_book_backend_notify_writable (backend, FALSE);
-				e_book_backend_notify_connection_status (backend, FALSE);
-			}
-			}
+			e_book_backend_set_is_writable (backend, FALSE);
+			e_book_backend_notify_writable (backend, FALSE);
+			e_book_backend_notify_connection_status (backend, FALSE);
 		} else if (mode == GNOME_Evolution_Addressbook_MODE_REMOTE) {
-			if (exchange_account_connect (bepriv->account, NULL, &result)) {
-				e_book_backend_set_is_writable (backend, FALSE);
-				e_book_backend_notify_writable (backend, FALSE);
-				e_book_backend_notify_connection_status (backend, TRUE);
+			e_book_backend_set_is_writable (backend, FALSE);
+			e_book_backend_notify_writable (backend, FALSE);
+			e_book_backend_notify_connection_status (backend, TRUE);
 
-				if (e_book_backend_is_loaded (backend)) {
-					gal_connect (be);
-					e_book_backend_notify_auth_required (backend);
+			if (e_book_backend_is_loaded (backend)) {
+				gal_connect (be);
+				e_book_backend_notify_auth_required (backend);
 
-					if (bepriv->marked_for_offline && bepriv->cache)
-						generate_cache (be);
-				}
+				if (bepriv->marked_for_offline && bepriv->cache)
+					generate_cache (be);
 			}
 		}
 	}
Index: calendar/e-cal-backend-exchange.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/calendar/e-cal-backend-exchange.c,v
retrieving revision 1.40
diff -u -p -r1.40 e-cal-backend-exchange.c
--- calendar/e-cal-backend-exchange.c	22 Aug 2005 14:22:01 -0000	1.40
+++ calendar/e-cal-backend-exchange.c	26 Aug 2005 08:53:58 -0000
@@ -1103,7 +1103,6 @@ set_mode (ECalBackend *backend, CalMode 
 			cbex->folder = exchange_account_get_folder (account, uristr);
 			/* FIXME : Test if available for read already */
 			priv->read_only = FALSE;
-			exchange_account_set_online (account);
 			priv->mode = CAL_MODE_REMOTE;
 			/* FIXME : Check if online and check if authentication
 				is needed */
@@ -1120,7 +1119,6 @@ set_mode (ECalBackend *backend, CalMode 
 			cbex->folder = exchange_account_get_folder (account, uristr);
 			priv->mode = CAL_MODE_LOCAL;
 			priv->read_only = TRUE;
-			exchange_account_set_offline (account);
 			e_cal_backend_notify_mode (backend, 
 				GNOME_Evolution_Calendar_CalListener_MODE_SET,
 				GNOME_Evolution_Calendar_MODE_LOCAL);
@@ -1658,6 +1656,8 @@ init (ECalBackendExchange *cbex)
 	cbex->priv->timezones = g_hash_table_new_full (
 		g_str_hash, g_str_equal,
 		g_free, (GDestroyNotify)icaltimezone_free);
+
+	cbex->priv->mode = CAL_MODE_LOCAL;
 
 	cbex->priv->set_lock = g_mutex_new ();
 	cbex->priv->open_lock = g_mutex_new ();
Index: camel/camel-exchange-store.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/camel/camel-exchange-store.c,v
retrieving revision 1.23
diff -u -p -r1.23 camel-exchange-store.c
--- camel/camel-exchange-store.c	22 Aug 2005 14:22:01 -0000	1.23
+++ camel/camel-exchange-store.c	26 Aug 2005 08:53:59 -0000
@@ -353,35 +353,58 @@ camel_exchange_get_password (CamelServic
 	}
 }
 
+static void
+camel_exchange_forget_password (CamelService *service, CamelException *ex)
+{
+	CamelSession *session = camel_service_get_session (service);
+
+	if (service->url->passwd) {
+		camel_session_forget_password (session, 
+					       service, "Exchange", 
+					       "password", ex);
+		g_free (service->url->passwd);
+		service->url->passwd = NULL;
+	}
+}
+
 static gboolean
 exchange_connect (CamelService *service, CamelException *ex)
 {
 	CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (service);
 	char *real_user, *socket_path;
+	gchar *password = NULL;
 	guint32 connect_status;
 
-	if (exch->stub)
+	if (exch->stub == NULL) {
+		real_user = strpbrk (service->url->user, "\\/");
+		if (real_user)
+			real_user++;
+		else
+			real_user = service->url->user;
+		socket_path = g_strdup_printf ("/tmp/.exchange-%s/%s %s",
+					       g_get_user_name (),
+					       real_user, service->url->host);
+		e_filename_make_safe (strchr (socket_path + 5, '/') + 1);
+		
+		exch->stub = camel_stub_new (socket_path, _("Evolution Exchange backend process"), ex);
+		g_free (socket_path);
+		if (!exch->stub)
+			return FALSE;
+	} else if (!camel_session_is_online (service->session)) {
 		return TRUE;
+	}
+
+	if (camel_session_is_online (service->session)) {
+		camel_exchange_get_password (service, ex);
+		if (camel_exception_is_set (ex)) {
+			return FALSE;
+		}
+		password = service->url->passwd;
+	}
 
-	real_user = strpbrk (service->url->user, "\\/");
-	if (real_user)
-		real_user++;
-	else
-		real_user = service->url->user;
-	socket_path = g_strdup_printf ("/tmp/.exchange-%s/%s %s",
-				       g_get_user_name (),
-				       real_user, service->url->host);
-	e_filename_make_safe (strchr (socket_path + 5, '/') + 1);
-	
-	exch->stub = camel_stub_new (socket_path, _("Evolution Exchange backend process"), ex);
-	g_free (socket_path);
-	if (!exch->stub)
-		return FALSE;
-	
-	camel_exchange_get_password (service, ex);
 	/* Initialize the stub connection */
 	if (!camel_stub_send (exch->stub, NULL, CAMEL_STUB_CMD_CONNECT,
-			      CAMEL_STUB_ARG_STRING, g_strdup (service->url->passwd),
+			      CAMEL_STUB_ARG_STRING, password,
 			      CAMEL_STUB_ARG_RETURN,
 			      CAMEL_STUB_ARG_UINT32, &connect_status,
 			      CAMEL_STUB_ARG_END)) {
@@ -390,6 +413,14 @@ exchange_connect (CamelService *service,
 				     "Cancelled");
 		camel_object_unref (exch->stub);
 		exch->stub = NULL;
+		return FALSE;
+	}
+
+	if (!connect_status && password != NULL) {
+		camel_exchange_forget_password (service, ex);
+		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
+				     _("Could not authenticate to server. "
+				       "(Password incorrect?)\n\n"));
 		return FALSE;
 	}
 	
Index: mail/mail-stub-exchange.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/mail/mail-stub-exchange.c,v
retrieving revision 1.27
diff -u -p -r1.27 mail-stub-exchange.c
--- mail/mail-stub-exchange.c	22 Aug 2005 14:22:01 -0000	1.27
+++ mail/mail-stub-exchange.c	26 Aug 2005 08:54:00 -0000
@@ -49,7 +49,7 @@
 static MailStubClass *parent_class = NULL;
 
 /* FIXME : Have this as part of the appropriate class in 2.5 */
-static gulong offline_listener_handler_id;
+/* static gulong offline_listener_handler_id; */
 
 typedef struct {
 	char *uid, *href;
@@ -128,9 +128,9 @@ static gboolean process_flags (gpointer 
 
 static void storage_folder_changed (EFolder *folder, gpointer user_data);
 
-static void linestatus_listener (ExchangeComponent *component,
+/* static void linestatus_listener (ExchangeComponent *component,
 						    gint linestatus,
-						    gpointer data);
+						    gpointer data); */
 static void folder_update_linestatus (gpointer key, gpointer value, gpointer data);
 static void free_folder (gpointer value);
 static void get_folder_online (MailStubExchangeFolder *mfld, gboolean background);
@@ -232,13 +232,13 @@ dispose (GObject *object)
 		mse->removed_folder_id = 0;
 	}
 
-	if (g_signal_handler_is_connected (G_OBJECT (global_exchange_component),
+/*	if (g_signal_handler_is_connected (G_OBJECT (global_exchange_component),
 					   offline_listener_handler_id)) {
 		g_signal_handler_disconnect (G_OBJECT (global_exchange_component),
 					      offline_listener_handler_id);
 		offline_listener_handler_id = 0;
 	}
-
+*/
 	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
@@ -722,6 +722,9 @@ get_folder_online (MailStubExchangeFolde
 	e_folder_exchange_subscribe (mfld->folder,
 				     E2K_CONTEXT_OBJECT_MOVED, 30,
 				     notify_cb, mfld);
+	if (background) {
+		mail_stub_push_changes (stub);
+	}
 }
 
 static void
@@ -2765,7 +2768,7 @@ stub_connect (MailStub *stub, char *pwd)
 	ExchangeAccount *account;
 	ExchangeAccountResult result;
 	E2kContext *ctx;
-	guint32 retval = 0; /* 0 is a failure case */
+	guint32 retval = 1;
 	const char *uri;
 	int mode;
 
@@ -2775,23 +2778,29 @@ stub_connect (MailStub *stub, char *pwd)
 		ctx = exchange_account_connect (account, pwd, &result);
 	}
 	
-	if (ctx) 
-		retval = 1;
-	else
+	exchange_component_is_offline (global_exchange_component, &mode);
+	
+	if (!ctx && mode == ONLINE_MODE) {
+		retval = 0;
 		goto end;
+	} else if (mode == OFFLINE_MODE) {
+		goto end;
+	}
 
-	exchange_component_is_offline (global_exchange_component, &mode);
+	mse->ctx = g_object_ref (ctx);
 
-	if (mode == ONLINE_MODE) {
-		mse->ctx = ctx;
-		g_object_ref (mse->ctx);
+	mse->mail_submission_uri = exchange_account_get_standard_uri (account, "sendmsg");
+	uri = exchange_account_get_standard_uri (account, "inbox");
+	mse->inbox = exchange_account_get_folder (account, uri);
+	uri = exchange_account_get_standard_uri (account, "deleteditems");
+	mse->deleted_items = exchange_account_get_folder (account, uri);
 
-		mse->mail_submission_uri = exchange_account_get_standard_uri (account, "sendmsg");
-		uri = exchange_account_get_standard_uri (account, "inbox");
-		mse->inbox = exchange_account_get_folder (account, uri);
-		uri = exchange_account_get_standard_uri (account, "deleteditems");
-		mse->deleted_items = exchange_account_get_folder (account, uri);
-	}
+	/* Will be used for offline->online transition to initialize things for
+	   the first time */
+	
+	g_hash_table_foreach (mse->folders_by_name,
+			      (GHFunc) folder_update_linestatus,
+			      GINT_TO_POINTER (mode));
 end:
 	mail_stub_return_data (stub, CAMEL_STUB_RETVAL_RESPONSE,
 			       CAMEL_STUB_ARG_UINT32, retval,
@@ -2800,6 +2809,7 @@ end:
 	mail_stub_return_ok (stub);
 }
 
+#if 0
 static void 
 linestatus_listener (ExchangeComponent *component,
 		     gint linestatus,
@@ -2832,6 +2842,8 @@ linestatus_listener (ExchangeComponent *
 	}
 }
 
+#endif
+
 static void
 folder_update_linestatus (gpointer key, gpointer value, gpointer data)
 {
@@ -2862,19 +2874,17 @@ mail_stub_exchange_new (ExchangeAccount 
 {
 	MailStubExchange *mse;
 	MailStub *stub;
-	int mode;
 
 	stub = g_object_new (MAIL_TYPE_STUB_EXCHANGE, NULL);
 	g_object_ref (stub);
 	mail_stub_construct (stub, cmd_fd, status_fd);
-	exchange_component_is_offline (global_exchange_component, &mode);
 
 	mse = (MailStubExchange *)stub;
 	mse->account = account;
 	
-	offline_listener_handler_id = g_signal_connect (G_OBJECT (global_exchange_component),
+	/* offline_listener_handler_id = g_signal_connect (G_OBJECT (global_exchange_component),
 							"linestatus-changed",
-							G_CALLBACK (linestatus_listener), mse);
+							G_CALLBACK (linestatus_listener), mse); */
 	return stub;
 }
 


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