[evolution-data-server] Add camel_imapx_mailbox_to_folder_path().



commit 957c1a846f1755eac4559964be28a100271af7d4
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Aug 26 09:38:18 2013 -0400

    Add camel_imapx_mailbox_to_folder_path().
    
    Replaces camel_imapx_store_summary_mailbox_to_path().
    
    Converts the given mailbox name to a Camel folder path, which just
    replaces all hierarchy separator characters with '/'.  If '/' appears
    in the mailbox name, it is replaced with the hierarchy separator.

 camel/camel-imapx-server.c        |   34 ++++++++++++++++----------------
 camel/camel-imapx-store-summary.c |   29 +++------------------------
 camel/camel-imapx-store-summary.h |    4 ---
 camel/camel-imapx-utils.c         |   38 +++++++++++++++++++++++++++++++++++++
 camel/camel-imapx-utils.h         |    3 ++
 5 files changed, 62 insertions(+), 46 deletions(-)
---
diff --git a/camel/camel-imapx-server.c b/camel/camel-imapx-server.c
index 5d0e90a..64abb2c 100644
--- a/camel/camel-imapx-server.c
+++ b/camel/camel-imapx-server.c
@@ -2071,18 +2071,18 @@ imapx_untagged_quotaroot (CamelIMAPXServer *is,
        CamelIMAPXStore *store;
        CamelIMAPXStoreNamespace *ns;
        CamelFolder *folder = NULL;
-       gchar *mailbox = NULL;
+       gchar *mailbox_name = NULL;
        gchar **quota_root_names = NULL;
        gboolean success;
        GError *local_error = NULL;
 
        success = camel_imapx_parse_quotaroot (
-               stream, cancellable, &mailbox, &quota_root_names, error);
+               stream, cancellable, &mailbox_name, &quota_root_names, error);
 
        /* Sanity check */
        g_return_val_if_fail (
-               (success && (mailbox != NULL)) ||
-               (!success && (mailbox == NULL)), FALSE);
+               (success && (mailbox_name != NULL)) ||
+               (!success && (mailbox_name == NULL)), FALSE);
 
        if (!success)
                return FALSE;
@@ -2090,12 +2090,12 @@ imapx_untagged_quotaroot (CamelIMAPXServer *is,
        store = camel_imapx_server_ref_store (is);
 
        ns = camel_imapx_store_summary_namespace_find_by_mailbox (
-               store->summary, mailbox);
+               store->summary, mailbox_name);
        if (ns != NULL) {
                gchar *folder_path;
 
-               folder_path = camel_imapx_store_summary_mailbox_to_path (
-                       store->summary, mailbox, ns->sep);
+               folder_path = camel_imapx_mailbox_to_folder_path (
+                       mailbox_name, ns->sep);
                if (folder_path != NULL) {
                        folder = camel_store_get_folder_sync (
                                CAMEL_STORE (store), folder_path, 0,
@@ -2114,11 +2114,11 @@ imapx_untagged_quotaroot (CamelIMAPXServer *is,
        if (local_error != NULL) {
                g_warning (
                        "%s: Failed to get folder '%s': %s",
-                       G_STRFUNC, mailbox, local_error->message);
+                       G_STRFUNC, mailbox_name, local_error->message);
                g_error_free (local_error);
        }
 
-       g_free (mailbox);
+       g_free (mailbox_name);
        g_strfreev (quota_root_names);
 
        return TRUE;
@@ -2218,18 +2218,18 @@ imapx_untagged_status (CamelIMAPXServer *is,
                store->summary, mailbox_name);
 
        if (ns != NULL) {
-               gchar *path_name;
+               gchar *folder_path;
 
-               path_name = camel_imapx_store_summary_mailbox_to_path (
-                       store->summary, mailbox_name, ns->sep);
+               folder_path = camel_imapx_mailbox_to_folder_path (
+                       mailbox_name, ns->sep);
                c (is->tagprefix,
-                       "Got folder path '%s' for full '%s'\n",
-                       path_name, mailbox_name);
-               if (path_name != NULL) {
+                       "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), path_name,
+                               CAMEL_STORE (store), folder_path,
                                0, cancellable, &local_error);
-                       g_free (path_name);
+                       g_free (folder_path);
                }
        }
 
diff --git a/camel/camel-imapx-store-summary.c b/camel/camel-imapx-store-summary.c
index 8132337..15f2301 100644
--- a/camel/camel-imapx-store-summary.c
+++ b/camel/camel-imapx-store-summary.c
@@ -427,27 +427,6 @@ camel_imapx_store_summary_mailbox (CamelIMAPXStoreSummary *s,
 }
 
 gchar *
-camel_imapx_store_summary_mailbox_to_path (CamelIMAPXStoreSummary *s,
-                                           const gchar *mailbox,
-                                           gchar dir_sep)
-{
-       gchar *path, *p;
-
-       p = path = g_strdup (mailbox);
-
-       if (dir_sep && dir_sep != '/') {
-               while (*p) {
-                       if (*p == '/')
-                               *p = dir_sep;
-                       else if (*p == dir_sep)
-                               *p = '/';
-                       p++;
-               }
-       }
-       return path;
-}
-
-gchar *
 camel_imapx_store_summary_path_to_mailbox (CamelIMAPXStoreSummary *s,
                                            const gchar *path,
                                            gchar dir_sep)
@@ -561,8 +540,8 @@ camel_imapx_store_summary_add_from_mailbox (CamelIMAPXStoreSummary *s,
                        if (mailbox_copy[len] == ns->sep)
                                len++;
 
-                       prefix = camel_imapx_store_summary_mailbox_to_path (
-                               s, mailbox_copy + len, ns->sep);
+                       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);
@@ -573,8 +552,8 @@ camel_imapx_store_summary_add_from_mailbox (CamelIMAPXStoreSummary *s,
                d (" (pathu8 = '%s')", pathu8);
        } else {
                d ("(Cannot find namespace for '%s')\n", mailbox_copy);
-               pathu8 = camel_imapx_store_summary_mailbox_to_path (
-                       s, mailbox_copy, dir_sep);
+               pathu8 = camel_imapx_mailbox_to_folder_path (
+                       mailbox_copy, dir_sep);
        }
 
        info = (CamelIMAPXStoreInfo *) camel_store_summary_add_from_path ((CamelStoreSummary *) s, pathu8);
diff --git a/camel/camel-imapx-store-summary.h b/camel/camel-imapx-store-summary.h
index 63aa46f..797a17f 100644
--- a/camel/camel-imapx-store-summary.h
+++ b/camel/camel-imapx-store-summary.h
@@ -101,10 +101,6 @@ CamelIMAPXStoreNamespace *
                                                 const gchar *mailbox);
 
 /* converts to/from utf8 canonical nasmes */
-gchar *                camel_imapx_store_summary_mailbox_to_path
-                                               (CamelIMAPXStoreSummary *s,
-                                                const gchar *mailbox,
-                                                gchar dir_sep);
 gchar *                camel_imapx_store_summary_path_to_mailbox
                                                (CamelIMAPXStoreSummary *s,
                                                 const gchar *path,
diff --git a/camel/camel-imapx-utils.c b/camel/camel-imapx-utils.c
index 984d7c0..474a059 100644
--- a/camel/camel-imapx-utils.c
+++ b/camel/camel-imapx-utils.c
@@ -2568,6 +2568,44 @@ camel_imapx_mailbox_is_inbox (const gchar *mailbox_name)
        return (g_ascii_strcasecmp (mailbox_name, "INBOX") == 0);
 }
 
+/**
+ * camel_imapx_mailbox_to_folder_path:
+ * @mailbox_name: a mailbox name
+ * @separator: mailbox separator character
+ *
+ * Converts @mailbox_name to a Camel folder path, which just replaces all
+ * @separator characters with '/'.  If '/' appears in @mailbox_name, it is
+ * replaced with @separator.  Free the returned string with g_free().
+ *
+ * Returns: a newly-allocated Camel folder path
+ *
+ * Since: 3.10
+ **/
+gchar *
+camel_imapx_mailbox_to_folder_path (const gchar *mailbox_name,
+                                    gchar separator)
+{
+       gchar *folder_path;
+
+       g_return_val_if_fail (mailbox_name != NULL, NULL);
+
+       folder_path = g_strdup (mailbox_name);
+
+       if (separator != '\0' && separator != '/') {
+               gchar *cp = folder_path;
+
+               while (*cp != '\0') {
+                       if (*cp == '/')
+                               *cp = separator;
+                       else if (*cp == separator)
+                               *cp = '/';
+                       cp++;
+               }
+       }
+
+       return folder_path;
+}
+
 gboolean
 camel_imapx_parse_quota (CamelIMAPXStream *is,
                          GCancellable *cancellable,
diff --git a/camel/camel-imapx-utils.h b/camel/camel-imapx-utils.h
index 7e99f76..31e6a46 100644
--- a/camel/camel-imapx-utils.h
+++ b/camel/camel-imapx-utils.h
@@ -322,6 +322,9 @@ gchar *             camel_imapx_parse_mailbox       (struct _CamelIMAPXStream *is,
                                                 GCancellable *cancellable,
                                                 GError **error);
 gboolean       camel_imapx_mailbox_is_inbox    (const gchar *mailbox_name);
+gchar *                camel_imapx_mailbox_to_folder_path
+                                               (const gchar *mailbox_name,
+                                                gchar separator);
 
 /* ********************************************************************** */
 


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