[evolution-data-server] imapx: More improvements to server unseen count tracking



commit 23503ac0c08fa8d933acb4be653257e596da6ae3
Author: David Woodhouse <David Woodhouse intel com>
Date:   Sun Jul 11 12:17:13 2010 +0100

    imapx: More improvements to server unseen count tracking
    
    We're using the unseen count as part of our check for when things have
    changed on the server (or when QRESYNC has gone wrong), and we need to
    rescan all flags. But the server doesn't *tell* us about changes to the
    unseen count, like it does for the total count of messages. So we have to
    be more careful about tracking it -- especially since the server doesn't
    even tell us in SELECT, and we can't issue STATUS to find it out when the
    folder is selected.
    
    One place that it was getting out of sync was when the server notified us
    about new messages in SELECT, which weren't there when we last issued STATUS.
    For messages with a UID equal to or higher than what we thought was the
    folder's UIDNEXT, we also have to update the unseen count.
    
    So far, the _only_ time we've hit the QRESYNC sanity check which triggers
    a full rescan has been due to this kind of cosmetic unseen count discrepancy.
    It's half tempting to disable that check in the QRESYNC sanity check, but
    actually it's useful to get it right for the legacy servers too, because it
    might cause us to miss updates if we get out of sync.

 camel/providers/imapx/camel-imapx-server.c |   53 ++++++++++++++++++++++++++--
 1 files changed, 50 insertions(+), 3 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index 406e9f8..f25eac4 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -1478,8 +1478,16 @@ imapx_untagged(CamelIMAPXServer *imap, GError **error)
 						finfo->user_flags = NULL;
 					}
 
+					/* If the message is a really new one -- equal or higher than what
+					   we know as UIDNEXT for the folder, then it came in since we last
+					   fetched UIDNEXT and UNREAD count. We'll update UIDNEXT in the
+					   command completion, but update UNREAD count now according to the
+					   message SEEN flag */
 					if (!(server_flags & CAMEL_MESSAGE_SEEN)) {
-						if (job->u.refresh_info.update_unseen) {
+						CamelIMAPXFolder *ifolder = (CamelIMAPXFolder *)job->folder;
+						unsigned long long uidl = strtoull(mi->uid, NULL, 10);
+
+						if (uidl >= ifolder->uidnext_on_server) {
 							c(printf("Updating unread count for new message %s\n", mi->uid));
 							((CamelIMAPXFolder *)job->folder)->unread_on_server++;
 						} else {
@@ -2380,7 +2388,12 @@ imapx_command_select_done (CamelIMAPXServer *is, CamelIMAPXCommand *ic)
 		is->state = IMAPX_SELECTED;
 		ifolder->exists_on_server = is->exists;
 		ifolder->modseq_on_server = is->highestmodseq;
-		ifolder->uidnext_on_server = is->uidnext;
+		if (ifolder->uidnext_on_server < is->uidnext) {
+			imapx_server_fetch_new_messages (is, is->select_pending, TRUE, TRUE, NULL);
+			/* We don't do this right now because we want the new messages to
+			   update the unseen count. */
+			//ifolder->uidnext_on_server = is->uidnext;
+		}
 		ifolder->uidvalidity_on_server = is->uidvalidity;
 #if 0
 		/* This must trigger a complete index rebuild! */
@@ -3444,6 +3457,8 @@ imapx_index_next (GPtrArray *uids, CamelFolderSummary *s, guint index)
 static void
 imapx_command_step_fetch_done(CamelIMAPXServer *is, CamelIMAPXCommand *ic)
 {
+	CamelIMAPXFolder *ifolder = (CamelIMAPXFolder *)ic->job->folder;
+	CamelIMAPXSummary *isum = (CamelIMAPXSummary *)ic->job->folder->summary;
 	CamelIMAPXJob *job = ic->job;
 	gint i = job->u.refresh_info.index;
 	GArray *infos = job->u.refresh_info.infos;
@@ -3499,6 +3514,22 @@ imapx_command_step_fetch_done(CamelIMAPXServer *is, CamelIMAPXCommand *ic)
 		}
 	}
 
+	if (camel_folder_summary_count(job->folder->summary)) {
+		gchar *uid = camel_folder_summary_uid_from_index (job->folder->summary,
+						  camel_folder_summary_count(job->folder->summary) - 1);
+		unsigned long long uidl = strtoull(uid, NULL, 10);
+		g_free(uid);
+
+		uidl++;
+
+		if (uidl > ifolder->uidnext_on_server) {
+			c(printf("Updating uidnext_on_server for '%s' to %lld\n",
+				 camel_folder_get_full_name(job->folder), uidl));
+			ifolder->uidnext_on_server = uidl;
+		}
+	}
+	isum->uidnext = ifolder->uidnext_on_server;
+
 cleanup:
 	for (i=0;i<infos->len;i++) {
 		struct _refresh_info *r = &g_array_index(infos, struct _refresh_info, i);
@@ -3732,7 +3763,6 @@ imapx_command_fetch_new_messages_done (CamelIMAPXServer *is, CamelIMAPXCommand *
 			g_propagate_error (&ic->job->error, ic->error);
 		goto exception;
 	}
-	isum->uidnext = ifolder->uidnext_on_server;
 
 	if (camel_folder_change_info_changed(ic->job->u.refresh_info.changes)) {
 		imapx_update_store_summary (ic->job->folder);
@@ -3741,6 +3771,23 @@ imapx_command_fetch_new_messages_done (CamelIMAPXServer *is, CamelIMAPXCommand *
 		camel_folder_change_info_clear(ic->job->u.refresh_info.changes);
 	}
 
+	if (camel_folder_summary_count(ic->job->folder->summary)) {
+		gchar *uid = camel_folder_summary_uid_from_index (ic->job->folder->summary,
+					  camel_folder_summary_count(ic->job->folder->summary) - 1);
+		unsigned long long uidl = strtoull(uid, NULL, 10);
+		g_free(uid);
+
+		uidl++;
+
+		if (uidl > ifolder->uidnext_on_server) {
+			c(printf("Updating uidnext_on_server for '%s' to %lld\n",
+				 camel_folder_get_full_name(ic->job->folder), uidl));
+			ifolder->uidnext_on_server = uidl;
+		}
+	}
+
+	isum->uidnext = ifolder->uidnext_on_server;
+
 exception:
 	if (ic->job->noreply)
 		camel_folder_change_info_free(ic->job->u.refresh_info.changes);



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