Creating folders



Hi folks,

I had some problems trying to create folders. I realized that the folder
returned by tny_camel_folder_create_folder has only the id (full_name)
of the CamelFolder. I don't know if this should be like that because the
returned TnyFolder is almost unusable. I made a patch that sets the
missing attributes to the TnyFolder from a CamelFolderInfo, but I'm not
sure if this method is supposed to work like this.

The attached patch also includes a check into the method
tny_camel_store_account_subscribe, that checks if the folder supports
subscriptions. I think it could be useful.

Br.
Index: libtinymail-camel/tny-camel-folder.c
===================================================================
--- libtinymail-camel/tny-camel-folder.c	(revision 1191)
+++ libtinymail-camel/tny-camel-folder.c	(working copy)
@@ -1316,6 +1316,25 @@
 	return;
 }
 
+static void
+tny_camel_folder_set_folder_info (TnyFolderStore *self, TnyCamelFolder *folder, CamelFolderInfo *info)
+{
+	TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (self);
+	TnyCamelStoreAccountPriv *apriv = TNY_CAMEL_STORE_ACCOUNT_GET_PRIVATE (priv->account);
+
+	_tny_camel_folder_set_id (folder, info->full_name);
+	_tny_camel_folder_set_folder_type (folder, info);
+	_tny_camel_folder_set_unread_count (folder, info->unread);
+	_tny_camel_folder_set_all_count (folder, info->total);
+	_tny_camel_folder_set_name (folder, info->name);
+	_tny_camel_folder_set_iter (folder, info);
+	
+	apriv->managed_folders = g_list_prepend (apriv->managed_folders, folder);
+	
+	_tny_camel_folder_set_account (folder,
+				       TNY_STORE_ACCOUNT (priv->account));
+}
+
 static TnyFolder*
 tny_camel_folder_create_folder (TnyFolderStore *self, const gchar *name)
 {
@@ -1335,16 +1354,20 @@
 	CamelException ex = CAMEL_EXCEPTION_INITIALISER;
 
 	if (!priv->folder_name)
-		return;
+		return NULL;
 
 	folname = priv->folder_name;
 	folder = tny_camel_folder_new ();
 	info = camel_store_create_folder (store, priv->folder_name, name, &ex);
 
-	_tny_camel_folder_set_id (TNY_CAMEL_FOLDER (folder), info->full_name);
-	camel_store_free_folder_info (store, info);
+	if (camel_exception_is_set (&ex)) {
+		g_warning ("Creating folder failed: %s\n", 
+			camel_exception_get_description (&ex));
+		g_object_unref (G_OBJECT (folder));
+		return NULL;
+	}
 
-	/* TODO: Error handling using 'ex' */
+	tny_camel_folder_set_folder_info (self, folder, info);
 
 	return folder;
 }
@@ -1428,17 +1451,7 @@
 		{
 			TnyCamelFolder *folder = TNY_CAMEL_FOLDER (tny_camel_folder_new ());
 		    
-			_tny_camel_folder_set_id (folder, iter->full_name);
-			_tny_camel_folder_set_folder_type (folder, iter);
-			_tny_camel_folder_set_unread_count (folder, iter->unread);
-			_tny_camel_folder_set_all_count (folder, iter->total);
-			_tny_camel_folder_set_name (folder, iter->name);
-			_tny_camel_folder_set_iter (folder, iter);
-			
-			apriv->managed_folders = g_list_prepend (apriv->managed_folders, folder);
-			
-			_tny_camel_folder_set_account (folder,
-						 TNY_STORE_ACCOUNT (priv->account));
+			tny_camel_folder_set_folder_info (self, folder, iter);
 
 			tny_list_prepend (list, G_OBJECT (folder));
 		}
Index: libtinymail-camel/tny-camel-store-account.c
===================================================================
--- libtinymail-camel/tny-camel-store-account.c	(revision 1191)
+++ libtinymail-camel/tny-camel-store-account.c	(working copy)
@@ -179,10 +179,14 @@
 			apriv->url_string, &ex);
 	g_static_rec_mutex_unlock (apriv->service_lock);
 
-	camel_store_subscribe_folder (store, tny_folder_get_name (folder), &ex);
+	if (camel_store_supports_subscriptions (store)
+	    && !camel_store_folder_subscribed (store, tny_folder_get_name (folder))) {
+		
+		camel_store_subscribe_folder (store, tny_folder_get_name (folder), &ex);
 
-	/* Sync */
-	_tny_camel_folder_set_subscribed (TNY_CAMEL_FOLDER (folder), TRUE);
+		/* Sync */
+		_tny_camel_folder_set_subscribed (TNY_CAMEL_FOLDER (folder), TRUE);
+	}
 
     	camel_object_unref (CAMEL_OBJECT (store));
     


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