[evolution-data-server/imap-notify: 7/40] CamelIMAPXFolder: Add camel_imapx_folder_list_mailbox().
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/imap-notify: 7/40] CamelIMAPXFolder: Add camel_imapx_folder_list_mailbox().
- Date: Thu, 12 Sep 2013 17:02:07 +0000 (UTC)
commit 583f86cb698d947115e74db575d1a269b0ff4baa
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue Sep 3 15:08:52 2013 -0400
CamelIMAPXFolder: Add camel_imapx_folder_list_mailbox().
Ensures that a folder's "mailbox" property is set, going so far as to
issue a LIST command if necessary (but should be a rarely needed last
resort).
Note the LIST command part of the function is currently unfinished.
Need to rework LIST command handling in CamelIMAPXServer first.
camel/camel-imapx-folder.c | 90 +++++++++++++++++++++++++++++++
camel/camel-imapx-folder.h | 4 ++
docs/reference/camel/camel-sections.txt | 1 +
3 files changed, 95 insertions(+), 0 deletions(-)
---
diff --git a/camel/camel-imapx-folder.c b/camel/camel-imapx-folder.c
index 4634551..643d711 100644
--- a/camel/camel-imapx-folder.c
+++ b/camel/camel-imapx-folder.c
@@ -1242,6 +1242,96 @@ camel_imapx_folder_set_mailbox (CamelIMAPXFolder *folder,
g_object_notify (G_OBJECT (folder), "mailbox");
}
+/**
+ * camel_imapx_folder_list_mailbox:
+ * @folder: a #CamelIMAPXFolder
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @error: return location for a #GError, or %NULL
+ *
+ * Ensures that @folder's #CamelIMAPXFolder:mailbox property is set,
+ * going so far as to issue a LIST command if necessary (but should
+ * be a rarely needed last resort).
+ *
+ * If @folder's #CamelFolder:parent-store is disconnected from the IMAP
+ * server or an error occurs during the LIST command, the function sets
+ * @error and returns %NULL.
+ *
+ * The returned #CamelIMAPXMailbox is referenced for thread-safety and
+ * should be unreferenced with g_object_unref() when finished with it.
+ *
+ * Returns: a #CamelIMAPXMailbox, or %NULL
+ *
+ * Since: 3.12
+ **/
+CamelIMAPXMailbox *
+camel_imapx_folder_list_mailbox (CamelIMAPXFolder *folder,
+ GCancellable *cancellable,
+ GError **error)
+{
+ CamelIMAPXStore *imapx_store;
+ CamelIMAPXServer *server = NULL;
+ CamelIMAPXMailbox *mailbox;
+ CamelStore *parent_store;
+ CamelStoreSummary *store_summary;
+ CamelStoreInfo *store_info;
+ CamelIMAPXStoreInfo *imapx_store_info;
+ gchar *folder_path = NULL;
+ gchar *mailbox_name = NULL;
+
+ g_return_val_if_fail (CAMEL_IS_IMAPX_FOLDER (folder), FALSE);
+
+ /* First check if we already have a mailbox. */
+
+ mailbox = camel_imapx_folder_ref_mailbox (folder);
+ if (mailbox != NULL)
+ goto exit;
+
+ /* Obtain the mailbox name from the store summary. */
+
+ folder_path = camel_folder_dup_full_name (CAMEL_FOLDER (folder));
+ parent_store = camel_folder_get_parent_store (CAMEL_FOLDER (folder));
+
+ imapx_store = CAMEL_IMAPX_STORE (parent_store);
+ store_summary = CAMEL_STORE_SUMMARY (imapx_store->summary);
+
+ store_info = camel_store_summary_path (store_summary, folder_path);
+
+ /* This should never fail. We needed the CamelStoreInfo
+ * to instantiate the CamelIMAPXFolder in the first place. */
+ g_return_val_if_fail (store_info != NULL, FALSE);
+
+ imapx_store_info = (CamelIMAPXStoreInfo *) store_info;
+ mailbox_name = g_strdup (imapx_store_info->mailbox_name);
+
+ camel_store_summary_info_unref (store_summary, store_info);
+
+ /* See if the CamelIMAPXServer already has the mailbox. */
+
+ server = camel_imapx_store_ref_server (imapx_store, error);
+
+ if (server == NULL)
+ goto exit;
+
+ mailbox = camel_imapx_server_ref_mailbox (server, mailbox_name);
+ if (mailbox != NULL) {
+ camel_imapx_folder_set_mailbox (folder, mailbox);
+ goto exit;
+ }
+
+ /* Last resort is to issue a LIST command. Maintainer should
+ * monitor IMAP logs to make sure this is rarely if ever used. */
+
+ g_warn_if_reached (); /* FIXME Implement this. */
+
+exit:
+ g_clear_object (&server);
+
+ g_free (folder_path);
+ g_free (mailbox_name);
+
+ return mailbox;
+}
+
gchar **
camel_imapx_folder_dup_quota_root_names (CamelIMAPXFolder *folder)
{
diff --git a/camel/camel-imapx-folder.h b/camel/camel-imapx-folder.h
index 0fefce3..f2120f0 100644
--- a/camel/camel-imapx-folder.h
+++ b/camel/camel-imapx-folder.h
@@ -96,6 +96,10 @@ CamelIMAPXMailbox *
camel_imapx_folder_ref_mailbox (CamelIMAPXFolder *folder);
void camel_imapx_folder_set_mailbox (CamelIMAPXFolder *folder,
CamelIMAPXMailbox *mailbox);
+CamelIMAPXMailbox *
+ camel_imapx_folder_list_mailbox (CamelIMAPXFolder *folder,
+ GCancellable *cancellable,
+ GError **error);
gchar ** camel_imapx_folder_dup_quota_root_names
(CamelIMAPXFolder *folder);
void camel_imapx_folder_set_quota_root_names
diff --git a/docs/reference/camel/camel-sections.txt b/docs/reference/camel/camel-sections.txt
index b07fc46..fb203fe 100644
--- a/docs/reference/camel/camel-sections.txt
+++ b/docs/reference/camel/camel-sections.txt
@@ -778,6 +778,7 @@ CamelIMAPXFolder
camel_imapx_folder_new
camel_imapx_folder_ref_mailbox
camel_imapx_folder_set_mailbox
+camel_imapx_folder_list_mailbox
camel_imapx_folder_dup_quota_root_names
camel_imapx_folder_set_quota_root_names
camel_imapx_folder_add_move_to_real_junk
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]