[evolution-data-server] Add camel_imapx_mailbox_is_inbox().
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Add camel_imapx_mailbox_is_inbox().
- Date: Tue, 6 Aug 2013 07:46:17 +0000 (UTC)
commit c630b810f652f9ec76c01c4b9094274bc13b69c8
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue Aug 6 09:45:42 2013 +0200
Add camel_imapx_mailbox_is_inbox().
Returns whether a mailbox name is the special mailbox INBOX. The
function just performs a case-insensitive string comparison; it's
more for readability.
camel/camel-imapx-folder.c | 2 +-
camel/camel-imapx-store-summary.c | 4 ++-
camel/camel-imapx-store.c | 63 ++++++++++++-------------------------
camel/camel-imapx-utils.c | 21 ++++++++++++-
camel/camel-imapx-utils.h | 1 +
5 files changed, 45 insertions(+), 46 deletions(-)
---
diff --git a/camel/camel-imapx-folder.c b/camel/camel-imapx-folder.c
index 27c6031..b3ce6c0 100644
--- a/camel/camel-imapx-folder.c
+++ b/camel/camel-imapx-folder.c
@@ -1148,7 +1148,7 @@ camel_imapx_folder_new (CamelStore *store,
if (filter_all)
folder->folder_flags |= CAMEL_FOLDER_FILTER_RECENT;
- if (!g_ascii_strcasecmp (folder_name, "INBOX")) {
+ if (camel_imapx_mailbox_is_inbox (folder_name)) {
if (filter_inbox)
folder->folder_flags |= CAMEL_FOLDER_FILTER_RECENT;
diff --git a/camel/camel-imapx-store-summary.c b/camel/camel-imapx-store-summary.c
index 31fcf45..598e1b2 100644
--- a/camel/camel-imapx-store-summary.c
+++ b/camel/camel-imapx-store-summary.c
@@ -124,7 +124,9 @@ camel_imapx_store_summary_full_name (CamelIMAPXStoreSummary *s,
{
gint count, i;
CamelIMAPXStoreInfo *info;
- gboolean is_inbox = g_ascii_strcasecmp (full_name, "INBOX") == 0;
+ gboolean is_inbox;
+
+ is_inbox = camel_imapx_mailbox_is_inbox (full_name);
count = camel_store_summary_count ((CamelStoreSummary *) s);
for (i = 0; i < count; i++) {
diff --git a/camel/camel-imapx-store.c b/camel/camel-imapx-store.c
index a2c1c8b..3ef6eb3 100644
--- a/camel/camel-imapx-store.c
+++ b/camel/camel-imapx-store.c
@@ -99,23 +99,28 @@ G_DEFINE_TYPE_WITH_CODE (
static guint
imapx_name_hash (gconstpointer key)
{
- if (g_ascii_strcasecmp (key, "INBOX") == 0)
- return g_str_hash ("INBOX");
- else
- return g_str_hash (key);
+ const gchar *mailbox = key;
+
+ if (camel_imapx_mailbox_is_inbox (mailbox))
+ mailbox = "INBOX";
+
+ return g_str_hash (mailbox);
}
static gboolean
imapx_name_equal (gconstpointer a,
gconstpointer b)
{
- gconstpointer aname = a, bname = b;
+ const gchar *mailbox_a = a;
+ const gchar *mailbox_b = b;
+
+ if (camel_imapx_mailbox_is_inbox (mailbox_a))
+ mailbox_a = "INBOX";
- if (g_ascii_strcasecmp (a, "INBOX") == 0)
- aname = "INBOX";
- if (g_ascii_strcasecmp (b, "INBOX") == 0)
- bname = "INBOX";
- return g_str_equal (aname, bname);
+ if (camel_imapx_mailbox_is_inbox (mailbox_b))
+ mailbox_b = "INBOX";
+
+ return g_str_equal (mailbox_a, mailbox_b);
}
static void
@@ -507,7 +512,7 @@ get_folder_offline (CamelStore *store,
summary = CAMEL_STORE_SUMMARY (imapx_store->summary);
si = camel_store_summary_path (summary, folder_name);
- is_inbox = (g_ascii_strcasecmp (folder_name, "INBOX") == 0);
+ is_inbox = camel_imapx_mailbox_is_inbox (folder_name);
if (si == NULL && is_inbox)
si = (CamelStoreInfo *) camel_imapx_store_summary_full_name (
@@ -569,7 +574,7 @@ imapx_build_folder_info (CamelIMAPXStore *imapx_store,
else
name++;
- if (!g_ascii_strcasecmp (fi->full_name, "INBOX"))
+ if (camel_imapx_mailbox_is_inbox (fi->full_name))
fi->display_name = g_strdup (_("Inbox"));
else
fi->display_name = g_strdup (name);
@@ -638,34 +643,6 @@ fill_fi (CamelStore *store,
}
}
-/* imap needs to treat inbox case insensitive */
-/* we'll assume the names are normalized already */
-static guint
-folder_hash (gconstpointer ap)
-{
- const gchar *a = ap;
-
- if (g_ascii_strcasecmp (a, "INBOX") == 0)
- a = "INBOX";
-
- return g_str_hash (a);
-}
-
-static gint
-folder_equal (gconstpointer ap,
- gconstpointer bp)
-{
- const gchar *a = ap;
- const gchar *b = bp;
-
- if (g_ascii_strcasecmp (a, "INBOX") == 0)
- a = "INBOX";
- if (g_ascii_strcasecmp (b, "INBOX") == 0)
- b = "INBOX";
-
- return g_str_equal (a, b);
-}
-
static gboolean
imapx_match_pattern (CamelIMAPXStoreNamespace *ns,
const gchar *pattern,
@@ -1008,7 +985,7 @@ get_folder_info_offline (CamelStore *store,
/* Modify the checks to see match the namespaces from preferences */
if ((g_str_equal (name, full_name)
|| imapx_match_pattern (ns, pattern, full_name)
- || (include_inbox && !g_ascii_strcasecmp (full_name, "INBOX")))
+ || (include_inbox && camel_imapx_mailbox_is_inbox (full_name)))
&& ( (!use_subscriptions
|| (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED) == 0)
|| (si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED)
@@ -1200,8 +1177,8 @@ fetch_folders_for_namespaces (CamelIMAPXStore *imapx_store,
list_ext = "RETURN (SUBSCRIBED)";
folders = g_hash_table_new_full (
- (GHashFunc) folder_hash,
- (GEqualFunc) folder_equal,
+ (GHashFunc) imapx_name_hash,
+ (GEqualFunc) imapx_name_equal,
(GDestroyNotify) NULL,
(GDestroyNotify) camel_folder_info_free);
diff --git a/camel/camel-imapx-utils.c b/camel/camel-imapx-utils.c
index 7ae683e..c0af8f3 100644
--- a/camel/camel-imapx-utils.c
+++ b/camel/camel-imapx-utils.c
@@ -2625,7 +2625,7 @@ exit:
* @cancellable: optional #GCancellable object, or %NULL
* @error: return location for a #GError, or %NULL
*
- * Parses a "mailbox" token from @is, with the special case for "INBOX" as
+ * Parses a "mailbox" token from @is, with the special case for INBOX as
* described in <ulink url="http://tools.ietf.org/html/rfc3501#section-5.1">
* RFC 3501 section 5.1</ulink>.
*
@@ -2659,6 +2659,25 @@ camel_imapx_parse_mailbox (CamelIMAPXStream *is,
return mailbox;
}
+/**
+ * camel_imapx_mailbox_is_inbox:
+ * @mailbox: a mailbox name
+ *
+ * Returns whether @mailbox is the special mailbox INBOX. The function just
+ * performs a case-insensitive string comparsion; it's more for readability.
+ *
+ * Returns: %TRUE if @mailbox is INBOX, %FALSE if not
+ *
+ * Since: 3.10
+ **/
+gboolean
+camel_imapx_mailbox_is_inbox (const gchar *mailbox)
+{
+ g_return_val_if_fail (mailbox != NULL, FALSE);
+
+ return (g_ascii_strcasecmp (mailbox, "INBOX") == 0);
+}
+
gboolean
camel_imapx_parse_quota (CamelIMAPXStream *is,
GCancellable *cancellable,
diff --git a/camel/camel-imapx-utils.h b/camel/camel-imapx-utils.h
index cd974d9..3d50d01 100644
--- a/camel/camel-imapx-utils.h
+++ b/camel/camel-imapx-utils.h
@@ -339,6 +339,7 @@ gboolean camel_imapx_command_add_qresync_parameter
gchar * camel_imapx_parse_mailbox (struct _CamelIMAPXStream *is,
GCancellable *cancellable,
GError **error);
+gboolean camel_imapx_mailbox_is_inbox (const gchar *mailbox);
/* ********************************************************************** */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]