[evolution-data-server/imap-notify: 16/40] CamelIMAPXStore: Simplify get_folder_info_offline().



commit ca4bf8a3d0cbc58e241bab32cf5303cb5b3a3a80
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Sep 10 16:08:40 2013 -0400

    CamelIMAPXStore: Simplify get_folder_info_offline().
    
    Forget about namespaces when offline and just match folder paths.

 camel/camel-imapx-store.c |  167 +++++++++++++++-----------------------------
 1 files changed, 57 insertions(+), 110 deletions(-)
---
diff --git a/camel/camel-imapx-store.c b/camel/camel-imapx-store.c
index 92ec79f..ee6d9db 100644
--- a/camel/camel-imapx-store.c
+++ b/camel/camel-imapx-store.c
@@ -1112,40 +1112,6 @@ fill_fi (CamelStore *store,
        }
 }
 
-static gboolean
-imapx_match_pattern (CamelIMAPXStoreNamespace *ns,
-                     const gchar *pattern,
-                     const gchar *name)
-{
-       gchar p, n, dir_sep;
-
-       if (!ns)
-               return TRUE;
-
-       dir_sep = ns->sep;
-       if (!dir_sep)
-               dir_sep = '/';
-       p = *pattern++;
-       n = *name++;
-       while (n && p) {
-               if (n == p) {
-                       p = *pattern++;
-                       n = *name++;
-               } else if (p == '%') {
-                       if (n != dir_sep) {
-                               n = *name++;
-                       } else {
-                               p = *pattern++;
-                       }
-               } else if (p == '*') {
-                       return TRUE;
-               } else
-                       return FALSE;
-       }
-
-       return n == 0 && (p == '%' || p == 0);
-}
-
 static void
 imapx_unmark_folder_subscribed (CamelIMAPXStore *imapx_store,
                                 const gchar *folder_path,
@@ -1238,8 +1204,6 @@ get_folder_info_offline (CamelStore *store,
        CamelFolderInfo *fi;
        GPtrArray *folders;
        GPtrArray *array;
-       gchar *pattern, *name;
-       gboolean use_namespace;
        gboolean use_subscriptions;
        guint ii;
 
@@ -1247,9 +1211,6 @@ get_folder_info_offline (CamelStore *store,
 
        settings = camel_service_ref_settings (service);
 
-       use_namespace = camel_imapx_settings_get_use_namespace (
-               CAMEL_IMAPX_SETTINGS (settings));
-
        use_subscriptions = camel_imapx_settings_get_use_subscriptions (
                CAMEL_IMAPX_SETTINGS (settings));
 
@@ -1264,36 +1225,6 @@ get_folder_info_offline (CamelStore *store,
                top = "";
        }
 
-       /* get starting point */
-       if (top[0] == 0) {
-               gchar *namespace = NULL;
-
-               if (use_namespace) {
-                       settings = camel_service_ref_settings (service);
-
-                       namespace = camel_imapx_settings_dup_namespace (
-                               CAMEL_IMAPX_SETTINGS (settings));
-
-                       g_object_unref (settings);
-               }
-
-               if (namespace != NULL) {
-                       name = g_strdup (imapx_store->summary->namespaces->personal->prefix);
-                       top = imapx_store->summary->namespaces->personal->prefix;
-               } else
-                       name = g_strdup ("");
-
-               g_free (namespace);
-       } else {
-               name = camel_imapx_store_summary_mailbox_from_path (
-                       imapx_store->summary, top);
-               if (name == NULL)
-                       name = camel_imapx_store_summary_path_to_mailbox (
-                               imapx_store->summary, top, imapx_store->dir_sep);
-       }
-
-       pattern = imapx_concat (imapx_store, name, "*");
-
        /* folder_info_build will insert parent nodes as necessary and mark
         * them as noselect, which is information we actually don't have at
         * the moment. So let it do the right thing by bailing out if it's
@@ -1305,60 +1236,76 @@ get_folder_info_offline (CamelStore *store,
 
        for (ii = 0; ii < array->len; ii++) {
                CamelStoreInfo *si;
-               const gchar *mailbox;
-               CamelIMAPXStoreNamespace *ns;
+               const gchar *folder_path;
+               gboolean si_is_inbox;
+               gboolean si_is_match;
 
                si = g_ptr_array_index (array, ii);
+               folder_path = camel_store_info_path (store_summary, si);
+               si_is_inbox = (g_ascii_strcasecmp (folder_path, "INBOX") == 0);
 
-               mailbox = ((CamelIMAPXStoreInfo *) si)->mailbox_name;
-               if (mailbox == NULL || *mailbox == '\0')
-                       continue;
+               /* Filter by folder path. */
+               si_is_match =
+                       (include_inbox && si_is_inbox) ||
+                       g_str_has_prefix (folder_path, top);
 
-               ns = camel_imapx_store_summary_namespace_find_by_mailbox (
-                       imapx_store->summary, mailbox);
-
-               /* Modify the checks to see match the namespaces from preferences */
-               if ((g_str_equal (name, mailbox)
-                    || imapx_match_pattern (ns, pattern, mailbox)
-                    || (include_inbox && camel_imapx_mailbox_is_inbox (mailbox)))
-                   && ( (!use_subscriptions
-                           || (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED) == 0)
-                       || (si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED)
-                       || (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIPTION_LIST) != 0)) {
-                       const gchar *folder_path;
-
-                       folder_path = camel_store_info_path (store_summary, si);
-                       fi = imapx_store_build_folder_info (
-                               imapx_store, folder_path, 0);
-                       fi->unread = si->unread;
-                       fi->total = si->total;
-                       if ((fi->flags & CAMEL_FOLDER_TYPE_MASK) != 0)
-                               fi->flags = (fi->flags & CAMEL_FOLDER_TYPE_MASK) | (si->flags & 
~CAMEL_FOLDER_TYPE_MASK);
-                       else
-                               fi->flags = si->flags;
-
-                       /* blah, this gets lost somewhere, i can't be bothered finding out why */
-                       if (!g_ascii_strcasecmp (fi->full_name, "inbox")) {
-                               fi->flags = (fi->flags & ~CAMEL_FOLDER_TYPE_MASK) | CAMEL_FOLDER_TYPE_INBOX;
-                               fi->flags |= CAMEL_FOLDER_SYSTEM;
-                       }
+               if (!si_is_match)
+                       continue;
 
-                       if (!(si->flags & CAMEL_FOLDER_NOSELECT))
-                               fill_fi ((CamelStore *) imapx_store, fi);
+               /* Filter by subscription flags.
+                *
+                * Skip the folder if:
+                *   The user only wants to see subscribed folders
+                *   AND the folder is not subscribed
+                *   AND the caller only wants SUBSCRIBED folder info
+                *   AND the caller does NOT want a SUBSCRIPTION_LIST
+                *
+                * Note that having both SUBSCRIBED and SUBSCRIPTION_LIST
+                * flags set is contradictory.  SUBSCRIPTION_LIST wins in
+                * that case.
+                */
+               si_is_match =
+                       !use_subscriptions ||
+                       (si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED) ||
+                       !(flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED) ||
+                       (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIPTION_LIST);
+
+               if (!si_is_match)
+                       continue;
 
-                       if (!fi->child)
-                               fi->flags |= CAMEL_FOLDER_NOCHILDREN;
-                       g_ptr_array_add (folders, fi);
+               fi = imapx_store_build_folder_info (
+                       imapx_store, folder_path, 0);
+               fi->unread = si->unread;
+               fi->total = si->total;
+               if ((fi->flags & CAMEL_FOLDER_TYPE_MASK) != 0)
+                       fi->flags =
+                               (fi->flags & CAMEL_FOLDER_TYPE_MASK) |
+                               (si->flags & ~CAMEL_FOLDER_TYPE_MASK);
+               else
+                       fi->flags = si->flags;
+
+               /* blah, this gets lost somewhere, i can't be bothered finding out why */
+               if (si_is_inbox) {
+                       fi->flags =
+                               (fi->flags & ~CAMEL_FOLDER_TYPE_MASK) |
+                               CAMEL_FOLDER_TYPE_INBOX;
+                       fi->flags |= CAMEL_FOLDER_SYSTEM;
                }
+
+               if (!(si->flags & CAMEL_FOLDER_NOSELECT))
+                       fill_fi ((CamelStore *) imapx_store, fi);
+
+               if (!fi->child)
+                       fi->flags |= CAMEL_FOLDER_NOCHILDREN;
+
+               g_ptr_array_add (folders, fi);
        }
 
        camel_store_summary_array_free (store_summary, array);
 
-       g_free (pattern);
-
        fi = camel_folder_info_build (folders, top, '/', TRUE);
+
        g_ptr_array_free (folders, TRUE);
-       g_free (name);
 
        return fi;
 }


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