+/*
+static void on_tnylist_accounts_debug_print(gpointer data, gpointer user_data)
+{
+ TnyAccount* account = TNY_ACCOUNT(data);
+ const gchar *prefix = (const gchar*)(user_data);
+
+ printf("%s account id=%s\n", prefix, tny_account_get_id (account));
+}
+*/
+
+static void
+add_account_folders_to_merged_folder (TnyAccount *account, TnyMergeFolder* merge_folder)
+{
+ const gchar* account_id = tny_account_get_id (account);
+ const gboolean is_actual_local_folders_account = account_id &&
+ (strcmp (account_id, MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID) == 0);
+
+ TnyList *list_outbox_folders = tny_simple_list_new ();
+ tny_folder_store_get_folders (TNY_FOLDER_STORE (account),
+ list_outbox_folders, NULL, NULL);
+
+ TnyIterator* iter = tny_list_create_iterator (list_outbox_folders);
+ while (!tny_iterator_is_done (iter))
+ {
+ TnyFolder *folder = TNY_FOLDER (tny_iterator_get_current (iter));
+
+ if (folder) {
+ gboolean add = TRUE;
+ /* TODO: Do not add outboxes that are inside local-folders/,
+ * because these are just left-over from earlier Modest versions
+ * that put the outbox there: */
+ if (is_actual_local_folders_account) {
+ const TnyFolderType type = modest_tny_folder_get_local_folder_type (folder);
+ if (type == TNY_FOLDER_TYPE_OUTBOX) {
+ add = FALSE;
+ }
+ }
+
+ if (add)
+ tny_merge_folder_add_folder (merge_folder, folder);
+
+ g_object_unref (folder);
+ }
+
+ tny_iterator_next (iter);
+ }
+
+ g_object_unref (list_outbox_folders);
+}
+
+
+static void
+add_account_folders_to_simple_folder_store (TnyAccount *account, ModestTnySimpleFolderStore* store)
+{
+ g_return_if_fail (account);
+ g_return_if_fail (store);
+
+ TnyList *list_outbox_folders = tny_simple_list_new ();
+ tny_folder_store_get_folders (TNY_FOLDER_STORE (account),
+ list_outbox_folders, NULL, NULL);
+
+ /* Special handling for the .modest/local-folders account,
+ * to avoid adding unwanted folders.
+ * We cannot prevent them from being in the TnyAccount without
+ * changing the libtinymail-camel. */
+ const gchar* account_id = tny_account_get_id (account);
+ const gboolean is_actual_local_folders_account = account_id &&
+ (strcmp (account_id, MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID) == 0);
+
+ TnyIterator* iter = tny_list_create_iterator (list_outbox_folders);
+ while (!tny_iterator_is_done (iter))
+ {
+ TnyFolder *folder = TNY_FOLDER (tny_iterator_get_current (iter));
+
+ if (folder) {
+ gboolean add = TRUE;
+ /* TODO: Do not add outboxes that are inside local-folders/,
+ * because these are just left-over from earlier Modest versions
+ * that put the outbox there: */
+ if (is_actual_local_folders_account) {
+ const TnyFolderType type = modest_tny_folder_get_local_folder_type (folder);
+ if (type == TNY_FOLDER_TYPE_OUTBOX) {
+ add = FALSE;
+ }
+ }
+
+ if (add)
+ modest_tny_simple_folder_store_add_folder (store, folder);
+
+ g_object_unref (folder);
+ }
+
+ tny_iterator_next (iter);
+ }
+
+ g_object_unref (list_outbox_folders);
+}
+