Index: camel/camel-exchange-folder.c
===================================================================
--- camel/camel-exchange-folder.c	(revision 1790)
+++ camel/camel-exchange-folder.c	(working copy)
@@ -174,14 +174,28 @@
 {
 	CamelExchangeFolder *exch = CAMEL_EXCHANGE_FOLDER (folder);
 	CamelExchangeStore *store = CAMEL_EXCHANGE_STORE (folder->parent_store);
+	guint32 unread_count, visible_count;
 
 	if (camel_exchange_store_connected (store, ex)) {
 		camel_offline_journal_replay (exch->journal, NULL);
 
 		camel_stub_send (exch->stub, ex, CAMEL_STUB_CMD_REFRESH_FOLDER,
 				 CAMEL_STUB_ARG_FOLDER, folder->full_name,
-				 CAMEL_STUB_ARG_END);
+			     	 CAMEL_STUB_ARG_END);
 	}
+	
+	/* sync up the counts now */
+	if (!camel_stub_send (exch->stub, ex, CAMEL_STUB_CMD_SYNC_COUNT,
+				 CAMEL_STUB_ARG_FOLDER, folder->full_name,
+				 CAMEL_STUB_ARG_RETURN,
+			      	 CAMEL_STUB_ARG_UINT32, &unread_count,
+				 CAMEL_STUB_ARG_UINT32, &visible_count,
+			      	 CAMEL_STUB_ARG_END)){
+		g_print("\n Error syncing up the counts");
+	}
+
+	folder->summary->unread_count = unread_count;
+	folder->summary->visible_count = visible_count;
 }
 
 static void
@@ -708,6 +722,7 @@
 	CamelFolderChangeInfo *changes;
 	CamelStream *stream;
 	CamelMimeMessage *msg;
+	guint32 unread_count, visible_count;
 
 	info = camel_folder_summary_uid (folder->summary, uid);
 	if (info) {
@@ -747,6 +762,18 @@
 
 	camel_folder_summary_add (folder->summary, info);
 
+	if (!camel_stub_send (exch->stub, NULL, CAMEL_STUB_CMD_SYNC_COUNT,
+				 CAMEL_STUB_ARG_FOLDER, folder->full_name,
+				 CAMEL_STUB_ARG_RETURN,
+			      	 CAMEL_STUB_ARG_UINT32, &unread_count,
+				 CAMEL_STUB_ARG_UINT32, &visible_count,
+			      	 CAMEL_STUB_ARG_END)){
+		g_print("\n Error syncing up the counts");
+	}
+
+	folder->summary->unread_count = unread_count;
+	folder->summary->visible_count = visible_count;
+	
 	changes = camel_folder_change_info_new ();
 	camel_folder_change_info_add_uid (changes, uid);
 	camel_folder_change_info_recent_uid (changes, uid);
@@ -1034,7 +1061,7 @@
 
 		if (summary->len - camel_folder_summary_cache_size (folder->summary) > 50)
 			camel_folder_summary_reload_from_db (folder->summary, ex);
-		
+
 		for (i = 0; i < summary->len; i++) {
 			uids->pdata[i] = g_strdup(summary->pdata[i]);
 			info = camel_folder_summary_uid (folder->summary, uids->pdata[i]);
@@ -1083,7 +1110,7 @@
 		camel_operation_end (NULL);
 		if (!ok)
 			return FALSE;
-		
+
 		camel_folder_summary_save_to_db (folder->summary, ex);
 	}
 
Index: camel/camel-stub-constants.h
===================================================================
--- camel/camel-stub-constants.h	(revision 1790)
+++ camel/camel-stub-constants.h	(working copy)
@@ -18,6 +18,7 @@
 	CAMEL_STUB_CMD_GET_TRASH_NAME,
 	CAMEL_STUB_CMD_SYNC_FOLDER,
 	CAMEL_STUB_CMD_REFRESH_FOLDER,
+	CAMEL_STUB_CMD_SYNC_COUNT,
 	CAMEL_STUB_CMD_EXPUNGE_UIDS,
 	CAMEL_STUB_CMD_APPEND_MESSAGE,
 	CAMEL_STUB_CMD_SET_MESSAGE_FLAGS,
Index: mail/mail-stub.h
===================================================================
--- mail/mail-stub.h	(revision 1790)
+++ mail/mail-stub.h	(working copy)
@@ -42,6 +42,7 @@
 	void (*get_trash_name)     (MailStub *);
 	void (*sync_folder)        (MailStub *, const char *folder_name);
 	void (*refresh_folder)     (MailStub *, const char *folder_name);
+	void (*sync_count)     	   (MailStub *, const char *folder_name);
 	void (*expunge_uids)       (MailStub *, const char *folder_name,
 				    GPtrArray *uids);
 	void (*append_message)     (MailStub *, const char *folder_name,
Index: mail/mail-stub-exchange.c
===================================================================
--- mail/mail-stub-exchange.c	(revision 1790)
+++ mail/mail-stub-exchange.c	(working copy)
@@ -95,6 +95,7 @@
 static void get_trash_name (MailStub *stub);
 static void sync_folder (MailStub *stub, const char *folder_name);
 static void refresh_folder (MailStub *stub, const char *folder_name);
+static void sync_count (MailStub *stub, const char *folder_name);
 static void refresh_folder_internal (MailStub *stub, MailStubExchangeFolder *mfld,
 				     gboolean background);
 static void sync_deletions (MailStubExchange *mse, MailStubExchangeFolder *mfld);
@@ -155,6 +156,7 @@
 	stub_class->get_trash_name = get_trash_name;
 	stub_class->sync_folder = sync_folder;
 	stub_class->refresh_folder = refresh_folder;
+	stub_class->sync_count = sync_count;
 	stub_class->expunge_uids = expunge_uids;
 	stub_class->append_message = append_message;
 	stub_class->set_message_flags = set_message_flags;
@@ -1527,6 +1529,32 @@
 }
 
 static void
+sync_count (MailStub *stub, const char *folder_name)
+{
+	MailStubExchange *mse = MAIL_STUB_EXCHANGE (stub);
+	MailStubExchangeFolder *mfld;
+	guint32 unread_count = 0, visible_count = 0;
+	
+	mfld = folder_from_name (mse, folder_name, 0, FALSE);
+	if (!mfld) {
+		mail_stub_return_data (stub, CAMEL_STUB_RETVAL_RESPONSE,
+				       CAMEL_STUB_ARG_UINT32, unread_count,
+				       CAMEL_STUB_ARG_END);
+		mail_stub_return_ok (stub);		
+		return;
+	}
+	
+	unread_count = mfld->unread_count;
+	visible_count = mfld->messages->len;
+
+	mail_stub_return_data (stub, CAMEL_STUB_RETVAL_RESPONSE,
+			       CAMEL_STUB_ARG_UINT32, unread_count,
+			       CAMEL_STUB_ARG_UINT32, visible_count,
+			       CAMEL_STUB_ARG_END);
+	mail_stub_return_ok (stub);
+}
+
+static void
 refresh_folder (MailStub *stub, const char *folder_name)
 {
 	MailStubExchange *mse = MAIL_STUB_EXCHANGE (stub);
Index: mail/mail-stub.c
===================================================================
--- mail/mail-stub.c	(revision 1790)
+++ mail/mail-stub.c	(working copy)
@@ -170,6 +170,21 @@
 		break;
 	}
 
+	case CAMEL_STUB_CMD_SYNC_COUNT:
+	{
+		char *folder_name;
+
+		if (!mail_stub_read_args (stub,
+					  CAMEL_STUB_ARG_FOLDER, &folder_name,
+					  CAMEL_STUB_ARG_END))
+			goto comm_fail;
+		d(printf("SYNC_COUNT %s\n", folder_name));
+		g_object_ref (stub);
+		MS_CLASS (stub)->sync_count (stub, folder_name);
+		g_free (folder_name);
+		break;
+	}
+
 	case CAMEL_STUB_CMD_EXPUNGE_UIDS:
 	{
 		char *folder_name;
