[evolution-data-server/imap-notify: 22/40] camel_imapx_store_summary_add_from_mailbox: Take a mailbox object.



commit b911fe7879504028333ff54a936bdd43af26b658
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Sep 11 10:44:31 2013 -0400

    camel_imapx_store_summary_add_from_mailbox: Take a mailbox object.

 camel/camel-imapx-store-summary.c |   85 +++++++++++++------------------------
 camel/camel-imapx-store-summary.h |    4 +-
 camel/camel-imapx-store.c         |    2 +-
 3 files changed, 32 insertions(+), 59 deletions(-)
---
diff --git a/camel/camel-imapx-store-summary.c b/camel/camel-imapx-store-summary.c
index e02811b..b577e43 100644
--- a/camel/camel-imapx-store-summary.c
+++ b/camel/camel-imapx-store-summary.c
@@ -507,72 +507,45 @@ camel_imapx_store_summary_path_to_mailbox (CamelIMAPXStoreSummary *s,
 
 CamelIMAPXStoreInfo *
 camel_imapx_store_summary_add_from_mailbox (CamelIMAPXStoreSummary *s,
-                                            const gchar *mailbox,
-                                            gchar dir_sep)
+                                            CamelIMAPXMailbox *mailbox)
 {
        CamelIMAPXStoreInfo *info;
-       gchar *pathu8, *prefix;
-       gint len;
-       gchar *mailbox_copy;
-       CamelIMAPXStoreNamespace *ns;
+       const gchar *mailbox_name;
+       gchar *folder_path;
+       gchar separator;
 
-       d ("adding mailbox '%s' '%c'\n", mailbox, dir_sep);
+       g_return_val_if_fail (CAMEL_IS_IMAPX_STORE_SUMMARY (s), NULL);
+       g_return_val_if_fail (CAMEL_IS_IMAPX_MAILBOX (mailbox), NULL);
 
-       len = strlen (mailbox);
-       mailbox_copy = alloca (len + 1);
-       strcpy (mailbox_copy, mailbox);
-       if (mailbox_copy[len - 1] == dir_sep)
-               mailbox_copy[len - 1] = 0;
+       mailbox_name = camel_imapx_mailbox_get_name (mailbox);
+       separator = camel_imapx_mailbox_get_separator (mailbox);
 
-       info = camel_imapx_store_summary_mailbox (s, mailbox_copy);
-       if (info) {
-               camel_store_summary_info_unref ((CamelStoreSummary *) s, (CamelStoreInfo *) info);
-               d ("  already there\n");
+       info = camel_imapx_store_summary_mailbox (s, mailbox_name);
+       if (info != NULL) {
+               camel_store_summary_info_unref (
+                       CAMEL_STORE_SUMMARY (s),
+                       (CamelStoreInfo *) info);
                return info;
        }
 
-       ns = camel_imapx_store_summary_namespace_find_by_mailbox (s, mailbox_copy);
-       if (ns) {
-               d ("(found namespace for '%s' ns '%s') ", mailbox_copy, ns->prefix);
-               dir_sep = ns->sep;
-               len = strlen (ns->prefix);
-               if (len >= strlen (mailbox_copy)) {
-                       pathu8 = g_strdup (ns->prefix);
-               } else {
-                       if (mailbox_copy[len] == ns->sep)
-                               len++;
-
-                       prefix = camel_imapx_mailbox_to_folder_path (
-                               mailbox_copy + len, ns->sep);
-                       if (*ns->prefix) {
-                               pathu8 = g_strdup_printf ("%s/%s", ns->prefix, prefix);
-                               g_free (prefix);
-                       } else {
-                               pathu8 = prefix;
-                       }
-               }
-               d (" (pathu8 = '%s')", pathu8);
-       } else {
-               d ("(Cannot find namespace for '%s')\n", mailbox_copy);
-               pathu8 = camel_imapx_mailbox_to_folder_path (
-                       mailbox_copy, dir_sep);
-       }
+       folder_path = camel_imapx_mailbox_to_folder_path (
+               mailbox_name, separator);
 
-       info = (CamelIMAPXStoreInfo *) camel_store_summary_add_from_path ((CamelStoreSummary *) s, pathu8);
-       if (info) {
-               d ("  '%s' -> '%s'\n", pathu8, mailbox_copy);
-               info->mailbox_name = g_strdup (mailbox_copy);
-               info->separator = dir_sep;
-
-               if (camel_imapx_mailbox_is_inbox (mailbox_copy))
-                       info->info.flags |=
-                               CAMEL_FOLDER_SYSTEM |
-                               CAMEL_FOLDER_TYPE_INBOX;
-       } else {
-               d ("  failed\n");
-       }
+       info = (CamelIMAPXStoreInfo *)
+               camel_store_summary_add_from_path (
+               CAMEL_STORE_SUMMARY (s), folder_path);
+
+       g_free (folder_path);
+
+       g_return_val_if_fail (info != NULL, NULL);
+
+       info->mailbox_name = g_strdup (mailbox_name);
+       info->separator = separator;
 
-       g_free (pathu8);
+       if (camel_imapx_mailbox_is_inbox (mailbox_name))
+               info->info.flags |=
+                       CAMEL_FOLDER_SYSTEM |
+                       CAMEL_FOLDER_TYPE_INBOX;
 
        return info;
 }
diff --git a/camel/camel-imapx-store-summary.h b/camel/camel-imapx-store-summary.h
index 797a17f..ed90cab 100644
--- a/camel/camel-imapx-store-summary.h
+++ b/camel/camel-imapx-store-summary.h
@@ -27,6 +27,7 @@
 #define CAMEL_IMAPX_STORE_SUMMARY_H
 
 #include <camel/camel-store-summary.h>
+#include <camel/camel-imapx-mailbox.h>
 
 /* Standard GObject macros */
 #define CAMEL_TYPE_IMAPX_STORE_SUMMARY \
@@ -113,8 +114,7 @@ CamelIMAPXStoreInfo *
 CamelIMAPXStoreInfo *
                camel_imapx_store_summary_add_from_mailbox
                                                (CamelIMAPXStoreSummary *s,
-                                                const gchar *mailbox,
-                                                gchar dir_sep);
+                                                CamelIMAPXMailbox *mailbox);
 
 /* a convenience lookup function. always use this if path known */
 gchar *                camel_imapx_store_summary_mailbox_from_path
diff --git a/camel/camel-imapx-store.c b/camel/camel-imapx-store.c
index bce91a8..25a5561 100644
--- a/camel/camel-imapx-store.c
+++ b/camel/camel-imapx-store.c
@@ -444,7 +444,7 @@ imapx_store_process_mailbox_attributes (CamelIMAPXStore *store,
        } else {
                /* XXX Shouldn't this take a GError if it can fail? */
                si = camel_imapx_store_summary_add_from_mailbox (
-                       store->summary, mailbox_name, separator);
+                       store->summary, mailbox);
                g_return_if_fail (si != NULL);
                mailbox_was_in_summary = FALSE;
                mailbox_was_subscribed = FALSE;


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