Index: camel/providers/imap/camel-imap-store.c
===================================================================
--- camel/providers/imap/camel-imap-store.c	(revision 10100)
+++ camel/providers/imap/camel-imap-store.c	(working copy)
@@ -3033,14 +3033,16 @@ camel_imap_store_readline (CamelImapStor
 	}
 
 	if (nread <= 0) {
-		if (errno == EINTR)
+		if (errno == EINTR) {
 			camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, _("Operation cancelled"));
-		else
+		} else {
 			camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
 					      _("Server unexpectedly disconnected: %s"),
 					      g_strerror (errno));
 		
-		camel_service_disconnect (CAMEL_SERVICE (store), FALSE, NULL);
+			camel_service_disconnect (CAMEL_SERVICE (store), FALSE, NULL);
+		}
+
 		g_byte_array_free (ba, TRUE);
 		return -1;
 	}
Index: camel/providers/imap/ChangeLog
===================================================================
--- camel/providers/imap/ChangeLog	(revision 10100)
+++ camel/providers/imap/ChangeLog	(working copy)
@@ -1,3 +1,12 @@
+2009-02-26  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #573240
+
+	* camel-imap-store.c: (camel_imap_store_readline):
+	* camel-imap-command.c: (imap_command_start),
+	(camel_imap_command_continuation), (imap_read_untagged):
+	Do not disconnect on user canceled.
+
 2009-02-12  Milan Crha  <mcrha@redhat.com>
 
 	** Fix for bug #534938
Index: camel/providers/imap/camel-imap-command.c
===================================================================
--- camel/providers/imap/camel-imap-command.c	(revision 10100)
+++ camel/providers/imap/camel-imap-command.c	(working copy)
@@ -232,8 +232,9 @@ imap_command_start (CamelImapStore *stor
 		else
 			camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
 					     g_strerror (errno));
-		
-		camel_service_disconnect (CAMEL_SERVICE (store), FALSE, NULL);
+
+		if (g_str_has_prefix (cmd, "LOGIN"))
+			camel_service_disconnect (CAMEL_SERVICE (store), FALSE, NULL);
 		return FALSE;
 	}
 	
@@ -275,13 +276,14 @@ camel_imap_command_continuation (CamelIm
 
 	if (camel_stream_write (store->ostream, cmd, cmdlen) == -1 ||
 	    camel_stream_write (store->ostream, "\r\n", 2) == -1) {
-		if (errno == EINTR)
+		if (errno == EINTR) {
 			camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
 					     _("Operation cancelled"));
-		else
+		} else {
 			camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
 					     g_strerror (errno));
-		camel_service_disconnect (CAMEL_SERVICE (store), FALSE, NULL);
+			camel_service_disconnect (CAMEL_SERVICE (store), FALSE, NULL);
+		}
 		CAMEL_SERVICE_REC_UNLOCK (store, connect_lock);
 		return NULL;
 	}
@@ -489,13 +491,15 @@ imap_read_untagged (CamelImapStore *stor
 		
 		do {
 			if ((n = camel_stream_read (store->istream, str->str + nread + 1, length - nread)) == -1) {
-				if (errno == EINTR)
+				if (errno == EINTR) {
 					camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
 							     _("Operation cancelled"));
-				else
+				} else {
 					camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
 							     g_strerror (errno));
-				camel_service_disconnect (CAMEL_SERVICE (store), FALSE, NULL);
+					camel_service_disconnect (CAMEL_SERVICE (store), FALSE, NULL);
+				}
+
 				g_string_free (str, TRUE);
 				goto lose;
 			}
