Index: camel/providers/imap/camel-imap-store.c
===================================================================
--- camel/providers/imap/camel-imap-store.c	(revision 10198)
+++ camel/providers/imap/camel-imap-store.c	(working copy)
@@ -1546,7 +1546,7 @@ imap_disconnect (CamelService *service, 
 	CamelImapStore *store = CAMEL_IMAP_STORE (service);
 
 	
-	if (CAMEL_OFFLINE_STORE (store)->state == CAMEL_OFFLINE_STORE_NETWORK_AVAIL && clean) {
+	if (store->connected && clean && CAMEL_OFFLINE_STORE (store)->state == CAMEL_OFFLINE_STORE_NETWORK_AVAIL) {
 		CamelImapResponse *response;
 
 		response = camel_imap_command (store, NULL, NULL, "LOGOUT");
Index: camel/providers/imap/ChangeLog
===================================================================
--- camel/providers/imap/ChangeLog	(revision 10198)
+++ camel/providers/imap/ChangeLog	(working copy)
@@ -1,3 +1,14 @@
+2009-04-07  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #573240
+
+	* camel-imap-store.c: (imap_disconnect):
+	Do not 'LOGOUT' when not connected.
+	* camel-imap-command.c: (imap_command_start):
+	Reconnect if necessary.
+	* camel-imap-command.c: (camel_imap_command_continuation):
+	Never reconnect.
+
 2009-03-09  Matthew Barnes  <mbarnes@redhat.com>
 
 	* camel-imap-summary.c (camel_imap_summary_new):
Index: camel/providers/imap/camel-imap-command.c
===================================================================
--- camel/providers/imap/camel-imap-command.c	(revision 10198)
+++ camel/providers/imap/camel-imap-command.c	(working copy)
@@ -179,6 +179,9 @@ imap_command_start (CamelImapStore *stor
 {
 	ssize_t nwritten;
 
+	if (!camel_imap_store_connected (store, ex))
+		return FALSE;
+
 	if (!store->ostream) {
 		camel_exception_set (ex, CAMEL_EXCEPTION_STORE_INVALID, _("No output stream"));
 		return FALSE;
@@ -260,17 +263,14 @@ CamelImapResponse *
 camel_imap_command_continuation (CamelImapStore *store, const char *cmd,
 				 size_t cmdlen, CamelException *ex)
 {
-	if (!camel_imap_store_connected (store, ex))
-		return NULL;
-
 	if (!store->ostream) {
 		camel_exception_set (ex, CAMEL_EXCEPTION_STORE_INVALID, _("No output stream"));
-		return FALSE;
+		return NULL;
 	}
 
 	if (!store->istream) {
 		camel_exception_set (ex, CAMEL_EXCEPTION_STORE_INVALID, _("No input stream"));
-		return FALSE;
+		return NULL;
 	}
 
 	if (camel_stream_write (store->ostream, cmd, cmdlen) == -1 ||
