diff --git a/camel/providers/imapx/camel-imapx-folder.h b/camel/providers/imapx/camel-imapx-folder.h
index 31318c9..c28b5b1 100644
--- a/camel/providers/imapx/camel-imapx-folder.h
+++ b/camel/providers/imapx/camel-imapx-folder.h
@@ -60,7 +60,9 @@ struct _CamelIMAPXFolder {
 	guint32 exists_on_server;
 	guint32 unread_on_server;
 	guint32 modseq_on_server;
+	guint32 uidnext_on_server;
 
+	guint32 last_known_uidnext;
 	guint32 last_known_modseq; /* When we last fetched flags */
 
 	/* hash table of UIDs to ignore as recent when updating folder */
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index b36eb16..5f0987f 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -32,8 +32,8 @@
 #include <ws2tcpip.h>
 #endif
 
-#define c(x)
-#define e(x)
+#define c(x) x
+#define e(x) x
 
 #define CFS_CLASS(x) ((CamelFolderSummaryClass *)((CamelObject *)x)->klass)
 
@@ -1102,6 +1102,10 @@ imapx_untagged(CamelIMAPXServer *imap, CamelException *ex)
 		if (imap->select_folder) {
 			gchar *uid = NULL;
 			CamelMessageInfo *mi;
+			CamelIMAPXFolder *ifolder = (CamelIMAPXFolder *)imap->select_folder;
+
+			if (ifolder->exists_on_server)
+				ifolder->exists_on_server--;
 
 			uid = camel_folder_summary_uid_from_index (imap->select_folder->summary, expunge - 1);
 			if (!uid)
@@ -1426,6 +1430,9 @@ imapx_untagged(CamelIMAPXServer *imap, CamelException *ex)
 		case IMAPX_PERMANENTFLAGS:
 			imap->permanentflags = sinfo->u.permanentflags;
 			break;
+		case IMAPX_UIDNEXT:
+			imap->uidnext = sinfo->u.uidnext;
+			break;
 		case IMAPX_ALERT:
 			c(printf("ALERT!: %s\n", sinfo->text));
 			break;
@@ -3339,6 +3346,8 @@ imapx_job_fetch_new_messages_start (CamelIMAPXServer *is, CamelIMAPXJob *job)
 	total = camel_folder_summary_count (folder->summary);
 	diff = ifolder->exists_on_server - total;
 
+	ifolder->last_known_uidnext = ifolder->uidnext_on_server;
+
 	if (total > 0)
 		uid = camel_folder_summary_uid_from_index (folder->summary, total - 1);
 	else
@@ -3350,7 +3359,7 @@ imapx_job_fetch_new_messages_start (CamelIMAPXServer *is, CamelIMAPXJob *job)
 
 	if (diff > BATCH_FETCH_COUNT) {
 		ic = camel_imapx_command_new ("FETCH", full_name,
-				     "FETCH %s:* (UID FLAGS)", uid);
+				     "UID FETCH %s:* (UID FLAGS)", uid);
 		imapx_uidset_init(&job->u.refresh_info.uidset, BATCH_FETCH_COUNT, 0);
 		job->u.refresh_info.infos = g_array_new (0, 0, sizeof(struct _refresh_info));
 		ic->pri = job->pri;
@@ -3375,73 +3384,86 @@ imapx_job_refresh_info_start (CamelIMAPXServer *is, CamelIMAPXJob *job)
 	CamelFolder *folder = job->folder;
 	CamelException *ex = job->ex;
 	const gchar *full_name;
+	gboolean did_status = FALSE;
 
 	full_name = camel_folder_get_full_name (folder);
 
-	total = camel_folder_summary_count (folder->summary);
-	/* Check if there are any new messages. The old imap doc says one needs to reselect in case of inbox to fetch
-	   new messages. Need to check if its still true. Just use noop now */
-	if (ifolder->exists_on_server == total) {
-		camel_imapx_server_noop (is, folder, ex);
-
-		if (camel_exception_is_set (ex))
-			goto exception;
-	}
-
-	/* Fetch the new messages */
-	if (ifolder->exists_on_server > total)
-	{
-		imapx_server_fetch_new_messages (is, folder, FALSE, job->ex);
-		if (camel_exception_is_set (job->ex))
-			goto exception;
-	}
-
-	/* Sync changes before fetching status, else unread count will not match. need to think about better ways for this */
+	/* Sync changes before fetching status, else unread count will not
+	   match. Need to think about better ways for this */
 	imapx_server_sync_changes (is, folder, job->pri, ex);
 	if (camel_exception_is_set (job->ex))
 		goto exception;
 
-	/* Check if a rescan is needed */
+	/* If we already know we something changed, don't bother with
+	   STATUS */
 	total = camel_folder_summary_count (folder->summary);
-	if (ifolder->exists_on_server == total) {
-		guint32 unread;
+
+	if (total == ifolder->exists_on_server &&
+	    ifolder->last_known_modseq == ifolder->modseq_on_server &&
+	    ifolder->last_known_uidnext == ifolder->uidnext_on_server) {
 		CamelIMAPXCommand *ic;
 		
-		if (is->cinfo && is->cinfo->capa & IMAPX_CAPABILITY_CONDSTORE)
-			ic = camel_imapx_command_new ("STATUS", NULL, "STATUS %f (MESSAGES UNSEEN HIGHESTMODSEQ)", folder);
-		else
-			ic = camel_imapx_command_new ("STATUS", NULL, "STATUS %f (MESSAGES UNSEEN)", folder);
-		ic->job = job;
-		ic->pri = job->pri;
-		ic->complete = imapx_command_status_done;
-		imapx_command_run_sync (is, ic);
-
-		if (camel_exception_is_set (ic->ex) || ic->status->result != IMAPX_OK) {
-			if (!camel_exception_is_set (ic->ex))
-				camel_exception_setv(job->ex, 1, "Error refreshing folder: %s", ic->status->text);
+		if (is->select && !strcmp(full_name, is->select)) {
+			/* We may not issue STATUS on the current folder. ReSELECT it instead. */
+			if (imapx_idle_supported(is) && imapx_in_idle(is))
+				imapx_stop_idle(is, job->ex);
+			if (camel_exception_is_set(job->ex))
+				goto exception;
+			imapx_select(is, folder, TRUE, job->ex);
+			if (camel_exception_is_set(job->ex))
+				goto exception;
+		} else {
+			if (is->cinfo && is->cinfo->capa & IMAPX_CAPABILITY_CONDSTORE)
+				ic = camel_imapx_command_new ("STATUS", NULL, "STATUS %f (MESSAGES UNSEEN UIDNEXT HIGHESTMODSEQ)", folder);
 			else
-				camel_exception_xfer (job->ex, ic->ex);
+				ic = camel_imapx_command_new ("STATUS", NULL, "STATUS %f (MESSAGES UNSEEN UIDNEXT)", folder);
+		
+			ic->job = job;
+			ic->pri = job->pri;
+			ic->complete = imapx_command_status_done;
+
+			imapx_command_run_sync (is, ic);
 
+			if (camel_exception_is_set (ic->ex) || ic->status->result != IMAPX_OK) {
+				if (!camel_exception_is_set (ic->ex))
+					camel_exception_setv(job->ex, 1, "Error refreshing folder: %s", ic->status->text);
+				else
+					camel_exception_xfer (job->ex, ic->ex);
+
+				camel_imapx_command_free (ic);
+				goto exception;
+			}
 			camel_imapx_command_free (ic);
-			goto exception;
+			did_status = TRUE;
 		}
-		camel_imapx_command_free (ic);
+	}
 
-		unread = folder->summary->unread_count;
+	e(printf("total %d / %d, unread %d / %d, modseq %d / %d, uidnext %d / %d\n",
+		 total, ifolder->exists_on_server,
+		 folder->summary->unread_count, ifolder->unread_on_server,
+		 ifolder->last_known_modseq, ifolder->modseq_on_server,
+		 ifolder->last_known_uidnext, ifolder->uidnext_on_server));
 
-		e(printf("total %d / %d, unread %d / %d, modseq %d / %d\n",
-		       total, ifolder->exists_on_server,
-		       unread, ifolder->unread_on_server,
-			 ifolder->last_known_modseq, ifolder->modseq_on_server));
-		if (total == ifolder->exists_on_server &&
-		    unread == ifolder->unread_on_server &&
-		    ifolder->last_known_modseq == ifolder->modseq_on_server)
+	/* Fetch the new messages */
+	if (ifolder->exists_on_server > total ||
+	    ifolder->uidnext_on_server > ifolder->last_known_uidnext)
+	{
+		imapx_server_fetch_new_messages (is, folder, FALSE, job->ex);
+		if (camel_exception_is_set (job->ex))
 			goto exception;
 	}
 
-	ifolder->last_known_modseq = ifolder->modseq_on_server;
-	imapx_job_scan_changes_start (is, job);
-	return;
+	/* The unread_on_server count is only valid for non-selected folder,
+	   if we used STATUS command. For selected folder we don't have an
+	   accurate current UNSEEN count */
+	if (total != ifolder->exists_on_server ||
+	    (did_status && folder->summary->unread_count != ifolder->unread_on_server) ||
+	    ifolder->last_known_modseq != ifolder->modseq_on_server ||
+	    ifolder->last_known_uidnext != ifolder->uidnext_on_server) {
+		ifolder->last_known_modseq = ifolder->modseq_on_server;
+		imapx_job_scan_changes_start (is, job);
+		return;
+	}
 
 exception:
 	imapx_job_done (is, job);
diff --git a/camel/providers/imapx/camel-imapx-server.h b/camel/providers/imapx/camel-imapx-server.h
index e1f774f..323fa8b 100644
--- a/camel/providers/imapx/camel-imapx-server.h
+++ b/camel/providers/imapx/camel-imapx-server.h
@@ -99,6 +99,7 @@ struct _CamelIMAPXServer {
 	guint32 uidvalidity;
 	guint32 unseen;
 	guint32 highestmodseq;
+	guint32 uidnext;
 	guint32 exists;
 	guint32 recent;
 	guint32 mode;
diff --git a/camel/providers/imapx/camel-imapx-stream.c b/camel/providers/imapx/camel-imapx-stream.c
index c63cdc3..c2ced74 100644
--- a/camel/providers/imapx/camel-imapx-stream.c
+++ b/camel/providers/imapx/camel-imapx-stream.c
@@ -36,7 +36,7 @@
 #include "camel-imapx-exception.h"
 
 #define t(x) 
-#define io(x)
+#define io(x) x
 
 #define CAMEL_IMAPX_STREAM_SIZE (4096)
 #define CAMEL_IMAPX_STREAM_TOKEN (4096) /* maximum token size */
