diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index 07c1000..33a920b 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -316,6 +316,20 @@ typedef enum {
 				   DONE as soon as we receive continuation */
 } CamelIMAPXIdleState;
 
+static const gchar *
+idle_state_name (CamelIMAPXIdleState state)
+{
+	#define maybe(x) if (state == x) return #x;
+	maybe (IMAPX_IDLE_OFF);
+	maybe (IMAPX_IDLE_PENDING);
+	maybe (IMAPX_IDLE_ISSUED);
+	maybe (IMAPX_IDLE_STARTED);
+	maybe (IMAPX_IDLE_CANCEL);
+	#undef maybe
+
+	return "???";
+}
+
 #define IMAPX_IDLE_DWELL_TIME	2 /* Number of seconds to remain in PENDING
 				     state waiting for other commands to be
 				     queued, before actually sending IDLE */
@@ -3048,18 +3062,22 @@ imapx_continuation (CamelIMAPXServer *is,
 		c (is->tagprefix, "Got continuation response for IDLE \n");
 		g_rec_mutex_lock (&is->priv->idle_lock);
 		/* We might have actually sent the DONE already! */
-		if (is->priv->idle_state == IMAPX_IDLE_ISSUED)
+		if (is->priv->idle_state == IMAPX_IDLE_ISSUED) {
+			printf ("   %s: idle-state: %s->%s\n", __FUNCTION__, idle_state_name (is->priv->idle_state), idle_state_name (IMAPX_IDLE_STARTED)); fflush (stdout);
 			is->priv->idle_state = IMAPX_IDLE_STARTED;
-		else if (is->priv->idle_state == IMAPX_IDLE_CANCEL) {
+		} else if (is->priv->idle_state == IMAPX_IDLE_CANCEL) {
 			/* IDLE got cancelled after we sent the command, while
 			 * we were waiting for this continuation. Send DONE
 			 * immediately. */
 			if (!imapx_command_idle_stop (is, error)) {
+				printf ("   %s: Failed to call imapx_command_idle_stop() at idle-state: %s\n", __FUNCTION__, idle_state_name (is->priv->idle_state)); fflush (stdout);
 				g_rec_mutex_unlock (&is->priv->idle_lock);
 				return FALSE;
 			}
+			printf ("   %s: idle-state: %s->%s\n", __FUNCTION__, idle_state_name (is->priv->idle_state), idle_state_name (IMAPX_IDLE_OFF)); fflush (stdout);
 			is->priv->idle_state = IMAPX_IDLE_OFF;
 		} else {
+			printf ("   %s: idle-state: %s in a wrong state here\n", __FUNCTION__, idle_state_name (is->priv->idle_state)); fflush (stdout);
 			c (
 				is->tagprefix, "idle starts in wrong state %d\n",
 				is->priv->idle_state);
@@ -3541,6 +3559,7 @@ imapx_command_idle_done (CamelIMAPXServer *is,
 	}
 
 	g_rec_mutex_lock (&is->priv->idle_lock);
+	printf ("   %s: idle-state: %s->%s\n", __FUNCTION__, idle_state_name (is->priv->idle_state), idle_state_name (IMAPX_IDLE_OFF)); fflush (stdout);
 	is->priv->idle_state = IMAPX_IDLE_OFF;
 	g_rec_mutex_unlock (&is->priv->idle_lock);
 
@@ -3575,12 +3594,14 @@ imapx_job_idle_start (CamelIMAPXJob *job,
 	g_rec_mutex_lock (&is->priv->idle_lock);
 	/* Don't issue it if the idle was cancelled already */
 	if (is->priv->idle_state == IMAPX_IDLE_PENDING) {
+		printf ("   %s: idle-state: %s->%s\n", __FUNCTION__, idle_state_name (is->priv->idle_state), idle_state_name (IMAPX_IDLE_ISSUED)); fflush (stdout);
 		is->priv->idle_state = IMAPX_IDLE_ISSUED;
 
 		if (camel_imapx_command_queue_is_empty (is->active)) {
 			imapx_command_start (is, ic);
 		} else {
 			c (is->tagprefix, "finally cancelling IDLE, other command was quicker\n");
+			printf ("      %s: but then turned off idle-state: %s\n", __FUNCTION__, idle_state_name (IMAPX_IDLE_OFF)); fflush (stdout);
 			is->priv->idle_state = IMAPX_IDLE_OFF;
 			imapx_unregister_job (is, job);
 		}
@@ -3679,8 +3700,10 @@ imapx_call_idle (gpointer data)
 	g_rec_mutex_lock (&is->priv->idle_lock);
 	g_source_unref (is->priv->idle_pending);
 	is->priv->idle_pending = NULL;
+	printf ("   %s: idle-state: %s (in locked)\n", __FUNCTION__, idle_state_name (is->priv->idle_state)); fflush (stdout);
 	g_rec_mutex_unlock (&is->priv->idle_lock);
 
+	printf ("      %s: idle-state: %s (in unlocked) !pending exits\n", __FUNCTION__, idle_state_name (is->priv->idle_state)); fflush (stdout);
 	if (is->priv->idle_state != IMAPX_IDLE_PENDING)
 		goto exit;
 
@@ -3786,8 +3809,10 @@ imapx_stop_idle (CamelIMAPXServer *is,
 
 	g_rec_mutex_lock (&is->priv->idle_lock);
 
+	printf ("   %s: idle-state: %s\n", __FUNCTION__, idle_state_name (is->priv->idle_state)); fflush (stdout);
 	switch (is->priv->idle_state) {
 		case IMAPX_IDLE_ISSUED:
+			printf ("      %s: idle-state: %s->%s\n", __FUNCTION__, idle_state_name (is->priv->idle_state), idle_state_name (IMAPX_IDLE_CANCEL)); fflush (stdout);
 			is->priv->idle_state = IMAPX_IDLE_CANCEL;
 			/* fall through */
 
@@ -3797,18 +3822,22 @@ imapx_stop_idle (CamelIMAPXServer *is,
 
 		case IMAPX_IDLE_STARTED:
 			if (imapx_command_idle_stop (is, error)) {
+				printf ("      %s: idle-state: %s; idle_stop succeeded\n", __FUNCTION__, idle_state_name (is->priv->idle_state)); fflush (stdout);
 				result = IMAPX_IDLE_STOP_SUCCESS;
 			} else {
+				printf ("      %s: idle-state: %s; idle_stop failed\n", __FUNCTION__, idle_state_name (is->priv->idle_state)); fflush (stdout);
 				result = IMAPX_IDLE_STOP_ERROR;
 				goto exit;
 			}
-			/* fall through */
+			break;
 
 		case IMAPX_IDLE_PENDING:
+			printf ("      %s: idle-state: %s->%s\n", __FUNCTION__, idle_state_name (is->priv->idle_state), idle_state_name (IMAPX_IDLE_OFF)); fflush (stdout);
 			is->priv->idle_state = IMAPX_IDLE_OFF;
-			/* fall through */
+			break;
 
 		case IMAPX_IDLE_OFF:
+			printf ("      %s: idle-state: %s do nothing\n", __FUNCTION__, idle_state_name (is->priv->idle_state)); fflush (stdout);
 			break;
 	}
 
@@ -3826,7 +3855,14 @@ imapx_start_idle (CamelIMAPXServer *is)
 
 	g_rec_mutex_lock (&is->priv->idle_lock);
 
-	g_return_if_fail (is->priv->idle_state == IMAPX_IDLE_OFF);
+	printf ("   %s: idle-state: %s (!off means go away)\n", __FUNCTION__, idle_state_name (is->priv->idle_state)); fflush (stdout);
+	if (is->priv->idle_state != IMAPX_IDLE_OFF) {
+		g_warn_if_fail (is->priv->idle_state == IMAPX_IDLE_OFF);
+		g_rec_mutex_unlock (&is->priv->idle_lock);
+		return;
+	}
+
+	printf ("      %s: idle-state: %s->%s\n", __FUNCTION__, idle_state_name (is->priv->idle_state), idle_state_name (IMAPX_IDLE_PENDING)); fflush (stdout);
 	is->priv->idle_state = IMAPX_IDLE_PENDING;
 
 	if (is->priv->idle_thread == NULL) {
@@ -3860,6 +3896,7 @@ imapx_in_idle (CamelIMAPXServer *is)
 	if (is->priv->idle_thread != NULL)
 		in_idle = (is->priv->idle_state > IMAPX_IDLE_OFF);
 
+	printf ("   %s: idle-state:%s res:%d\n", __FUNCTION__, idle_state_name (is->priv->idle_state), in_idle); fflush (stdout);
 	g_rec_mutex_unlock (&is->priv->idle_lock);
 
 	return in_idle;
