[evolution-data-server/meego-eds: 44/47] Fix fetch-more to return FALSE when there are none to fetch.



commit 86fd1636200aa52c743b0051c699eedce1cb6d86
Author: Srinivasa Ragavan <srini linux intel com>
Date:   Mon Jun 13 16:18:57 2011 +0300

    Fix fetch-more to return FALSE when there are none to fetch.

 camel/providers/imapx/camel-imapx-server.c |   17 +++++++++++++----
 camel/providers/pop3/camel-pop3-folder.c   |   19 ++++++++-----------
 2 files changed, 21 insertions(+), 15 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index b59ce5e..16620ab 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -4024,7 +4024,7 @@ imapx_job_fetch_old_messages_start (CamelIMAPXServer *is, CamelIMAPXJob *job)
 		unsigned long long uidl;
 		start_uid = camel_folder_summary_uid_from_index (folder->summary, 0);
 		uidl = strtoull(start_uid, NULL, 10);
-		end_uid = g_strdup_printf("%lld", (uidl-job->u.refresh_info.fetch_old_msg_count > 0) ? (uidl-job->u.refresh_info.fetch_old_msg_count) : 1);
+		end_uid = g_strdup_printf("%lld", ((((int)uidl)-job->u.refresh_info.fetch_old_msg_count) > 0) ? (uidl-job->u.refresh_info.fetch_old_msg_count) : 1);
 	} else {
 		/* */
 		g_error("Shouldn't call fetch old messages without anything. ");
@@ -5425,8 +5425,13 @@ camel_imapx_server_fetch_old_messages (CamelIMAPXServer *is,
                                        GError **error)
 {
 	CamelIMAPXJob *job;
-	gboolean success;
+	unsigned long long firstuid, newfirstuid;
+	gchar *uid;
 
+	uid = camel_folder_summary_uid_from_index (folder->summary, 0);
+	firstuid = strtoull(uid, NULL, 10);
+	g_free (uid);
+	
 	job = g_malloc0(sizeof(*job));
 	job->type = IMAPX_JOB_FETCH_OLD_MESSAGES;
 	job->start = imapx_job_fetch_old_messages_start;
@@ -5437,11 +5442,15 @@ camel_imapx_server_fetch_old_messages (CamelIMAPXServer *is,
 	job->u.refresh_info.fetch_old_msg_count = count;
 	job->op = camel_operation_registered ();
 
-	success = imapx_submit_job (is, job, error);
+	imapx_submit_job (is, job, error);
+
+	uid = camel_folder_summary_uid_from_index (folder->summary, 0);
+	newfirstuid = strtoull(uid, NULL, 10);
+	g_free (uid);
 
 	g_free (job);
 
-	return success;
+	return firstuid != newfirstuid;
 }
 
 static void
diff --git a/camel/providers/pop3/camel-pop3-folder.c b/camel/providers/pop3/camel-pop3-folder.c
index 4ea10ab..e3f49b4 100644
--- a/camel/providers/pop3/camel-pop3-folder.c
+++ b/camel/providers/pop3/camel-pop3-folder.c
@@ -240,7 +240,7 @@ cmd_list(CamelPOP3Engine *pe, CamelPOP3Stream *stream, gpointer data)
 	} while (ret>0);
 
 	/* Trim the list for mobile devices*/
-	if (pop3_folder->mobile) {
+	if (pop3_folder->mobile && pop3_folder->uids->len) {
 		gboolean save_uid = FALSE;
 		
 		d(printf("*********** Mobile mode *************\n"));
@@ -296,7 +296,9 @@ cmd_list(CamelPOP3Engine *pe, CamelPOP3Stream *stream, gpointer data)
 			g_ptr_array_remove_range (pop3_folder->uids, 0, i);
 			d(printf("Removing %d uids that are old\n", i));
 			
-		} 
+		} else /* We are the first uid. Nothing more to fetch */
+			pop3_folder->fetch_more = -1;
+
 
 		if (save_uid) {
 			char *contents;
@@ -315,6 +317,8 @@ cmd_list(CamelPOP3Engine *pe, CamelPOP3Stream *stream, gpointer data)
 			g_free (path);
 			g_free(root);
 			d(printf("Saving last uid %d\n", fi->id));
+			if (fi->id == pop3_folder->first_id)
+				pop3_folder->fetch_more = -1;
 			
 		}
 
@@ -425,20 +429,13 @@ pop3_fetch_old_messages (CamelFolder *folder, int count, GError **error)
 	CamelPOP3FolderInfo *fi;
 	CamelPOP3Folder *pop3_folder = (CamelPOP3Folder *)folder;
 
-	/* If we have the first message already, then return FALSE */
-	fi = pop3_folder->uids->pdata[0];
-	if (fi->id == pop3_folder->first_id)
-		return FALSE;
-	
 	pop3_folder->fetch_more = count;
 	pop3_refresh_info (folder, error);
-	pop3_folder->fetch_more = 0;
 
 	/* Even if we downloaded the first/oldest message, just now, return TRUE so that we wont waste another cycle */
-	fi = pop3_folder->uids->pdata[0];
-	if (fi->id == pop3_folder->first_id)
+	if (pop3_folder->fetch_more == -1)
 		return FALSE;
-
+	
 	return TRUE;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]