[evolution-data-server] Propagate STATUS responses to folders directly from imapx_untagged()



commit 61859b2fd607c86cd0dcf68c0fcfbc9ee86db9b2
Author: David Woodhouse <David Woodhouse intel com>
Date:   Wed Jun 23 12:07:33 2010 +0100

    Propagate STATUS responses to folders directly from imapx_untagged()
    
    Storing this in the server-global variables like is->exists is broken;
    any SELECT command which is sent between the untagged STATUS response
    and the tagged completion of the command is going to overwrite the data.
    Not to mention the fact that LIST-STATUS and NOTIFY will be totally hosed,
    when we get more than one untagged STATUS response between tagged commands.

 camel/providers/imapx/camel-imapx-server.c |   37 ++++++++++++++++-----------
 camel/providers/imapx/camel-imapx-utils.c  |    5 ++++
 camel/providers/imapx/camel-imapx-utils.h  |    1 +
 3 files changed, 28 insertions(+), 15 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index 67f2021..c861190 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -1464,10 +1464,29 @@ imapx_untagged(CamelIMAPXServer *imap, CamelException *ex)
 	case IMAPX_STATUS: {
 		struct _state_info *sinfo = imapx_parse_status_info (imap->stream, ex);
 		if (sinfo) {
-			/* this is what we use atm */
-			imap->exists = sinfo->messages;
-			imap->unseen = sinfo->unseen;
+			CamelIMAPXStoreSummary *s = ((CamelIMAPXStore *)imap->store)->summary;
+			CamelIMAPXStoreNamespace *ns;
+			CamelIMAPXFolder *ifolder = NULL;;
+
+			ns = camel_imapx_store_summary_namespace_find_full(s, sinfo->name);
+			if (ns) {
+				gchar *path_name;
+
+				path_name = camel_imapx_store_summary_full_to_path(s, sinfo->name, ns->sep);
+				c(printf("Got folder path '%s' for full '%s'\n", path_name, sinfo->name));
+				if (path_name) {
+					ifolder = (void *)camel_store_get_folder(imap->store, path_name, 0, ex);
+					g_free (path_name);
+				}
+			}
+			if (ifolder) {
+				ifolder->unread_on_server = sinfo->unseen;
+				ifolder->exists_on_server = sinfo->messages;
+			} else {
+				c(printf("Received STATUS for unknown folder '%s'\n", sinfo->name));
+			}
 
+			g_free (sinfo->name);
 			g_free (sinfo);
 		}
 		break;
@@ -1809,17 +1828,6 @@ imapx_command_complete (CamelIMAPXServer *is, CamelIMAPXCommand *ic)
 	e_flag_set (ic->flag);
 }
 
-/* change status to a job and remove command_run_sync */
-static void
-imapx_command_status_done (CamelIMAPXServer *is, CamelIMAPXCommand *ic)
-{
-	CamelIMAPXFolder *ifolder = (CamelIMAPXFolder *) ic->job->folder;
-
-	ifolder->unread_on_server = is->unseen;
-	ifolder->exists_on_server = is->exists;
-	e_flag_set (ic->flag);
-}
-
 /* The caller should free the command as well */
 static void
 imapx_command_run_sync (CamelIMAPXServer *is, CamelIMAPXCommand *ic)
@@ -3572,7 +3580,6 @@ imapx_job_refresh_info_start (CamelIMAPXServer *is, CamelIMAPXJob *job)
 		ic = camel_imapx_command_new (is, "STATUS", full_name, "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) {
diff --git a/camel/providers/imapx/camel-imapx-utils.c b/camel/providers/imapx/camel-imapx-utils.c
index 5eb9eda..62d4b7b 100644
--- a/camel/providers/imapx/camel-imapx-utils.c
+++ b/camel/providers/imapx/camel-imapx-utils.c
@@ -1500,6 +1500,11 @@ imapx_parse_status_info (struct _CamelIMAPXStream *is, CamelException *ex)
 
 	/* skip the folder name */
 	camel_imapx_stream_astring (is, &token, ex);
+	if (camel_exception_is_set(ex)) {
+		g_free (sinfo);
+		return NULL;
+	}
+	sinfo->name = camel_utf7_utf8 ((gchar *)token);
 
 	tok = camel_imapx_stream_token(is, &token, &len, ex);
 	if (tok != '(') {
diff --git a/camel/providers/imapx/camel-imapx-utils.h b/camel/providers/imapx/camel-imapx-utils.h
index e3eb2db..bb537bf 100644
--- a/camel/providers/imapx/camel-imapx-utils.h
+++ b/camel/providers/imapx/camel-imapx-utils.h
@@ -175,6 +175,7 @@ void imapx_free_status(struct _status_info *sinfo);
 /* ********************************************************************** */
 /* parses the response from the status command */
 struct _state_info {
+	gchar *name;
 	guint32 messages;
 	guint32 recent;
 	guint32 uidnext;



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