Index: camel/providers/imap/camel-imap-store.c
===================================================================
--- camel/providers/imap/camel-imap-store.c	(revision 9761)
+++ camel/providers/imap/camel-imap-store.c	(working copy)
@@ -2385,7 +2385,7 @@ parse_list_response_as_folder_info (Came
 	if (si == NULL)
 		return NULL;
 
-	newflags = (si->info.flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED) | (flags & ~CAMEL_STORE_INFO_FOLDER_SUBSCRIBED);
+	newflags = (si->info.flags & (CAMEL_STORE_INFO_FOLDER_SUBSCRIBED | CAMEL_STORE_INFO_FOLDER_CHECK_FOR_NEW)) | (flags & ~CAMEL_STORE_INFO_FOLDER_SUBSCRIBED);
 	if (si->info.flags != newflags) {
 		si->info.flags = newflags;
 		camel_store_summary_touch((CamelStoreSummary *)imap_store->summary);
@@ -3074,12 +3074,19 @@ imap_can_refresh_folder (CamelStore *sto
 	      (camel_url_get_param (((CamelService *)store)->url, "check_all") != NULL) ||
 	      (camel_url_get_param (((CamelService *)store)->url, "check_lsub") != NULL && (info->flags & CAMEL_FOLDER_SUBSCRIBED) != 0);
 
-	if (!res && !camel_exception_is_set (ex)) {
-		CamelFolder *folder;
+	if (!res && !camel_exception_is_set (ex) && CAMEL_IS_IMAP_STORE (store)) {
+		CamelStoreInfo *si;
+		CamelStoreSummary *sm = CAMEL_STORE_SUMMARY (((CamelImapStore *)(store))->summary);
 
-		folder = camel_store_get_folder (store, info->full_name, 0, ex);
-		if (folder && CAMEL_IS_IMAP_FOLDER (folder))
-			res = CAMEL_IMAP_FOLDER (folder)->check_folder;
+		if (!sm)
+			return FALSE;
+
+		si = camel_store_summary_path (sm, info->full_name);
+		if (si) {
+			res = (si->flags & CAMEL_STORE_INFO_FOLDER_CHECK_FOR_NEW) != 0 ? TRUE : FALSE;
+
+			camel_store_summary_info_free (sm, si);
+		}
 	}
 
 	return res;
Index: camel/providers/imap/ChangeLog
===================================================================
--- camel/providers/imap/ChangeLog	(revision 9761)
+++ camel/providers/imap/ChangeLog	(working copy)
@@ -1,3 +1,15 @@
+2008-11-18  Milan Crha  <mcrha@redhat.com>
+
+	** Part of fix for bug #558883
+
+	* camel-imap-store.c: (parse_list_response_as_folder_info):
+	Do not strip CAMEL_STORE_INFO_FOLDER_CHECK_FOR_NEW if set.
+	* camel-imap-store.c: (imap_can_refresh_folder):
+	Check if can refresh folder based on the data in store's folder
+	summary, to not download whole folder content because of this.
+	* camel-imap-folder.c: (imap_setv):
+	Set the 'check_folder' flag to store's folder summary too.
+
 2008-11-07  Srinivasa Ragavan  <sragavan@novell.com>
 
 	** Fix for bug #558883
Index: camel/providers/imap/camel-imap-folder.c
===================================================================
--- camel/providers/imap/camel-imap-folder.c	(revision 9761)
+++ camel/providers/imap/camel-imap-folder.c	(working copy)
@@ -473,6 +473,7 @@ imap_getv(CamelObject *object, CamelExce
 			break; }
 			/* imap args */
 		case CAMEL_IMAP_FOLDER_ARG_CHECK_FOLDER:
+			/* The internal value has precedence before the one stored in the summary. */
 			*arg->ca_int = ((CamelImapFolder *)object)->check_folder;
 			break;
 			/* CamelObject args */
@@ -514,8 +515,27 @@ imap_setv (CamelObject *object, CamelExc
 		switch (tag & CAMEL_ARG_TAG) {
 		case CAMEL_IMAP_FOLDER_ARG_CHECK_FOLDER:
 			if (((CamelImapFolder *)object)->check_folder != arg->ca_int) {
+				CamelFolder *folder = (CamelFolder *)object;
+
 				((CamelImapFolder *)object)->check_folder = arg->ca_int;
 				save = 1;
+
+				/* store both to the summary and to folder cmeta, to have this value restored correctly next time folder is fully loaded */
+				if (folder->parent_store && CAMEL_IS_IMAP_STORE (folder->parent_store)) {
+					CamelStoreInfo *si;
+					CamelStoreSummary *sm = CAMEL_STORE_SUMMARY (((CamelImapStore *)(folder->parent_store))->summary);
+
+					si = camel_store_summary_path (sm, folder->full_name);
+					if (si) {
+						if ((si->flags & CAMEL_STORE_INFO_FOLDER_CHECK_FOR_NEW) != 0 ? 1 : 0 != (arg->ca_int) ? 1 : 0) {
+							si->flags = (si->flags & (~CAMEL_STORE_INFO_FOLDER_CHECK_FOR_NEW)) | ((arg->ca_int) ? CAMEL_STORE_INFO_FOLDER_CHECK_FOR_NEW : 0);
+							camel_store_summary_touch (sm);
+							camel_store_summary_save (sm);
+						}
+
+						camel_store_summary_info_free (sm, si);
+					}
+				}
 			}
 			break;
 		default:
Index: camel/camel-store-summary.h
===================================================================
--- camel/camel-store-summary.h	(revision 9761)
+++ camel/camel-store-summary.h	(working copy)
@@ -57,6 +57,7 @@ typedef enum _CamelStoreInfoFlags {
 
 	/* not in camle-store.h yet */
 	CAMEL_STORE_INFO_FOLDER_READONLY = 1<<13,
+	CAMEL_STORE_INFO_FOLDER_CHECK_FOR_NEW = 1<<14,
 
 	CAMEL_STORE_INFO_FOLDER_FLAGGED = 1<<31
 } CamelStoreInfoFlags;
Index: camel/ChangeLog
===================================================================
--- camel/ChangeLog	(revision 9761)
+++ camel/ChangeLog	(working copy)
@@ -1,3 +1,10 @@
+2008-11-18  Milan Crha  <mcrha@redhat.com>
+
+	** Part of fix for bug #558883
+
+	* camel-store-summary.h: (CAMEL_STORE_INFO_FOLDER_CHECK_FOR_NEW):
+	Define new flag.
+
 2008-11-17  Matthew Barnes  <mbarnes@redhat.com>
 
 	** Fixes bug #531090
