[evolution-kolab] KolabMailImapClient: added API for querying folder type information



commit 786cfd9f5852dfa9942de76cf4ab0f889db46081
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Mon Jul 23 20:12:52 2012 +0200

    KolabMailImapClient: added API for querying folder type information
    
    * added an online-mode folder type querying function
    * this function is supposed to not rely on cached folder
      type information but to query the Kolab server each
      time

 src/libekolab/kolab-mail-imap-client.c |   68 ++++++++++++++++++++++++++++++++
 src/libekolab/kolab-mail-imap-client.h |    6 +++
 2 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/src/libekolab/kolab-mail-imap-client.c b/src/libekolab/kolab-mail-imap-client.c
index 209fdee..1472187 100644
--- a/src/libekolab/kolab-mail-imap-client.c
+++ b/src/libekolab/kolab-mail-imap-client.c
@@ -1054,6 +1054,7 @@ kolab_mail_imap_client_query_foldernames (KolabMailImapClient *self,
 KolabFolderTypeID
 kolab_mail_imap_client_get_folder_type (KolabMailImapClient *self,
                                         const gchar *foldername,
+                                        gboolean do_updatedb,
                                         GCancellable *cancellable,
                                         GError **err)
 {
@@ -1070,6 +1071,7 @@ kolab_mail_imap_client_get_folder_type (KolabMailImapClient *self,
 
 	foldertype = camel_kolab_imapx_store_get_folder_type (priv->store,
 	                                                      foldername,
+	                                                      do_updatedb,
 	                                                      cancellable,
 	                                                      &tmp_err);
 	if (tmp_err != NULL) {
@@ -1088,6 +1090,69 @@ kolab_mail_imap_client_get_folder_type (KolabMailImapClient *self,
 	return foldertype;
 }
 
+GList*
+kolab_mail_imap_client_query_folder_info_online (KolabMailImapClient *self,
+                                                 GCancellable *cancellable,
+                                                 GError **err)
+{
+	KolabMailImapClientPrivate *priv = NULL;
+	GList *folder_names = NULL;
+	GList *folder_names_ptr = NULL;
+	GList *folder_desc = NULL;
+	GError *tmp_err = NULL;
+
+	g_assert (KOLAB_IS_MAIL_IMAP_CLIENT (self));
+	/* cancellable may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, KOLAB_FOLDER_TYPE_INVAL);
+
+	priv = KOLAB_MAIL_IMAP_CLIENT_PRIVATE (self);
+
+	if (! camel_session_get_online (priv->session)) {
+		g_set_error (err,
+		             KOLAB_CAMEL_ERROR,
+		             KOLAB_CAMEL_ERROR_GENERIC,
+		             _("You must be working online to complete this operation"));
+		return NULL;
+	}
+
+	folder_names = kolab_mail_imap_client_query_foldernames (self,
+	                                                         cancellable,
+	                                                         &tmp_err);
+	if (tmp_err != NULL) {
+		g_propagate_error (err, tmp_err);
+		return NULL;
+	}
+
+	folder_names_ptr = folder_names;
+	while (folder_names_ptr != NULL) {
+		gchar *foldername = (gchar*) folder_names_ptr->data;
+		KolabFolderDescriptor *desc = NULL;
+		KolabFolderTypeID type_id = KOLAB_FOLDER_TYPE_INVAL;
+		type_id = kolab_mail_imap_client_get_folder_type (self,
+		                                                  foldername,
+		                                                  FALSE, /* do not update DBs */
+		                                                  cancellable,
+		                                                  &tmp_err);
+		if (tmp_err != NULL)
+			break;
+
+		desc = kolab_util_folder_descriptor_new (foldername,
+		                                         type_id);
+		folder_desc = g_list_prepend (folder_desc, desc);
+
+		folder_names_ptr = g_list_next (folder_names_ptr);
+	}
+
+	if (tmp_err != NULL) {
+		g_propagate_error (err, tmp_err);
+		kolab_util_glib_glist_free (folder_names);
+		kolab_util_folder_descriptor_glist_free (folder_desc);
+		return NULL;
+	}
+
+	return folder_desc;
+}
+
 static guint64
 kolab_mail_imap_client_get_folder_uidvalidity (KolabMailImapClient *self,
                                                const gchar *foldername,
@@ -1153,6 +1218,7 @@ kolab_mail_imap_client_query_folder_summary (KolabMailImapClient *self,
 
 	foldertype = kolab_mail_imap_client_get_folder_type (self,
 	                                                     foldername,
+	                                                     TRUE, /* update DBs */
 	                                                     cancellable,
 	                                                     &tmp_err);
 	if (tmp_err != NULL) {
@@ -1311,6 +1377,7 @@ kolab_mail_imap_client_query_summaries (KolabMailImapClient *self,
 	/* get folder type and context */
 	foldertype = kolab_mail_imap_client_get_folder_type (self,
 	                                                     foldername,
+	                                                     TRUE, /* update DBs */
 	                                                     cancellable,
 	                                                     &tmp_err);
 	if (foldertype == KOLAB_FOLDER_TYPE_INVAL) {
@@ -1684,6 +1751,7 @@ kolab_mail_imap_client_retrieve (KolabMailImapClient *self,
 	/* folder type/context checking */
 	folder_type = kolab_mail_imap_client_get_folder_type (self,
 	                                                      foldername,
+	                                                      TRUE, /* update DBs */
 	                                                      cancellable,
 	                                                      &tmp_err);
 	if (tmp_err != NULL) {
diff --git a/src/libekolab/kolab-mail-imap-client.h b/src/libekolab/kolab-mail-imap-client.h
index b1b31b2..cea72ac 100644
--- a/src/libekolab/kolab-mail-imap-client.h
+++ b/src/libekolab/kolab-mail-imap-client.h
@@ -138,9 +138,15 @@ kolab_mail_imap_client_query_foldernames_anon (gpointer self,
                                                GCancellable *cancellable,
                                                GError **err);
 
+GList*
+kolab_mail_imap_client_query_folder_info_online (KolabMailImapClient *self,
+                                                 GCancellable *cancellable,
+                                                 GError **err);
+
 KolabFolderTypeID
 kolab_mail_imap_client_get_folder_type (KolabMailImapClient *self,
                                         const gchar *foldername,
+                                        gboolean do_updatedb,
                                         GCancellable *cancellable,
                                         GError **err);
 



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