[evolution-data-server/imap-notify: 11/40] CamelIMAPXStore: Add imapx_store_process_mailbox_status().



commit 78b5c1c0b5012660fd9393bfb0a92bb591e077fb
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Aug 30 16:13:08 2013 -0400

    CamelIMAPXStore: Add imapx_store_process_mailbox_status().
    
    Processes a CamelIMAPXMailbox by adding relevant information to the
    CamelIMAPXFolder, and invalidating the local cache if a UIDVALIDITY
    change is detected.

 camel/camel-imapx-server.c |   53 -----------------------------------
 camel/camel-imapx-store.c  |   65 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 53 deletions(-)
---
diff --git a/camel/camel-imapx-server.c b/camel/camel-imapx-server.c
index 41e58e6..cba2c5d 100644
--- a/camel/camel-imapx-server.c
+++ b/camel/camel-imapx-server.c
@@ -2632,12 +2632,7 @@ imapx_untagged_status (CamelIMAPXServer *is,
 {
        CamelIMAPXStatusResponse *response;
        CamelIMAPXMailbox *mailbox;
-       CamelIMAPXStoreNamespace *ns;
-       CamelIMAPXStore *store;
-       CamelFolder *folder = NULL;
        const gchar *mailbox_name;
-       guint32 uidvalidity;
-       GError *local_error = NULL;
 
        g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
 
@@ -2647,7 +2642,6 @@ imapx_untagged_status (CamelIMAPXServer *is,
                return FALSE;
 
        mailbox_name = camel_imapx_status_response_get_mailbox_name (response);
-       uidvalidity = camel_imapx_status_response_get_uidvalidity (response);
 
        mailbox = camel_imapx_server_ref_mailbox (is, mailbox_name);
 
@@ -2657,55 +2651,8 @@ imapx_untagged_status (CamelIMAPXServer *is,
                g_object_unref (mailbox);
        }
 
-       store = camel_imapx_server_ref_store (is);
-
-       ns = camel_imapx_store_summary_namespace_find_by_mailbox (
-               store->summary, mailbox_name);
-
-       if (ns != NULL) {
-               gchar *folder_path;
-
-               folder_path = camel_imapx_mailbox_to_folder_path (
-                       mailbox_name, ns->sep);
-               c (is->tagprefix,
-                       "Got folder path '%s' for mailbox '%s'\n",
-                       folder_path, mailbox_name);
-               if (folder_path != NULL) {
-                       folder = camel_store_get_folder_sync (
-                               CAMEL_STORE (store), folder_path,
-                               0, cancellable, &local_error);
-                       g_free (folder_path);
-               }
-       }
-
-       g_object_unref (store);
-
-       if (folder != NULL) {
-               CamelIMAPXSummary *imapx_summary;
-               CamelIMAPXFolder *imapx_folder;
-
-               imapx_summary = CAMEL_IMAPX_SUMMARY (folder->summary);
-
-               imapx_folder = CAMEL_IMAPX_FOLDER (folder);
-               camel_imapx_folder_process_status_response (
-                       imapx_folder, response);
-
-               if (uidvalidity > 0 && uidvalidity != imapx_summary->validity)
-                       camel_imapx_folder_invalidate_local_cache (
-                               imapx_folder, uidvalidity);
-       } else {
-               c (is->tagprefix,
-                       "Received STATUS for unknown folder '%s'\n",
-                       mailbox_name);
-       }
-
        g_object_unref (response);
 
-       if (local_error != NULL) {
-               g_propagate_error (error, local_error);
-               return FALSE;
-       }
-
        return TRUE;
 }
 
diff --git a/camel/camel-imapx-store.c b/camel/camel-imapx-store.c
index 38261a1..2e55669 100644
--- a/camel/camel-imapx-store.c
+++ b/camel/camel-imapx-store.c
@@ -532,6 +532,69 @@ imapx_store_process_mailbox_attributes (CamelIMAPXStore *store,
 }
 
 static void
+imapx_store_process_mailbox_status (CamelIMAPXStore *store,
+                                    CamelIMAPXMailbox *mailbox)
+{
+       CamelFolder *folder = NULL;
+       const gchar *mailbox_name;
+       guint32 messages;
+       guint32 unseen;
+       guint32 uidnext;
+       guint32 uidvalidity;
+       guint64 highestmodseq;
+       gchar *folder_path;
+       gchar separator;
+       GError *local_error = NULL;
+
+       mailbox_name = camel_imapx_mailbox_get_name (mailbox);
+       separator = camel_imapx_mailbox_get_separator (mailbox);
+
+       messages = camel_imapx_mailbox_get_messages (mailbox);
+       unseen = camel_imapx_mailbox_get_unseen (mailbox);
+       uidnext = camel_imapx_mailbox_get_uidnext (mailbox);
+       uidvalidity = camel_imapx_mailbox_get_uidvalidity (mailbox);
+       highestmodseq = camel_imapx_mailbox_get_highestmodseq (mailbox);
+
+       folder_path = camel_imapx_mailbox_to_folder_path (
+               mailbox_name, separator);
+
+       folder = camel_store_get_folder_sync (
+               CAMEL_STORE (store), folder_path, 0, NULL, &local_error);
+
+       /* Sanity check. */
+       g_return_if_fail (
+               ((folder != NULL) && (local_error == NULL)) ||
+               ((folder == NULL) && (local_error != NULL)));
+
+       if (folder != NULL) {
+               CamelIMAPXFolder *imapx_folder;
+               CamelIMAPXSummary *imapx_summary;
+
+               imapx_folder = CAMEL_IMAPX_FOLDER (folder);
+               imapx_summary = CAMEL_IMAPX_SUMMARY (folder->summary);
+
+               imapx_folder->exists_on_server = messages;
+               imapx_folder->unread_on_server = unseen;
+               imapx_folder->uidnext_on_server = uidnext;
+               imapx_folder->uidvalidity_on_server = uidvalidity;
+               imapx_folder->modseq_on_server = highestmodseq;
+
+               if (uidvalidity > 0 && uidvalidity != imapx_summary->validity)
+                       camel_imapx_folder_invalidate_local_cache (
+                               imapx_folder, uidvalidity);
+
+               g_object_unref (folder);
+       } else {
+               g_warning (
+                       "%s: Failed to get folder '%s': %s",
+                       G_STRFUNC, folder_path, local_error->message);
+               g_error_free (local_error);
+       }
+
+       g_free (folder_path);
+}
+
+static void
 imapx_store_mailbox_created_cb (CamelIMAPXServer *server,
                                 CamelIMAPXMailbox *mailbox,
                                 CamelIMAPXStore *store)
@@ -547,6 +610,7 @@ imapx_store_mailbox_renamed_cb (CamelIMAPXServer *server,
                                 CamelIMAPXStore *store)
 {
        imapx_store_process_mailbox_attributes (store, mailbox, oldname);
+       imapx_store_process_mailbox_status (store, mailbox);
 }
 
 static void
@@ -555,6 +619,7 @@ imapx_store_mailbox_updated_cb (CamelIMAPXServer *server,
                                 CamelIMAPXStore *store)
 {
        imapx_store_process_mailbox_attributes (store, mailbox, NULL);
+       imapx_store_process_mailbox_status (store, mailbox);
 }
 
 static void


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