+ g_return_val_if_fail (TNY_IS_FOLDER (folder), FALSE);
+
+ /* The merge folder is a special case,
+ * used to merge the per-account local outbox folders.
+ * and can have no get_account() implementation.
+ * We should do something more sophisticated if we
+ * ever use TnyMergeFolder for anything else.
+ */
+ if (TNY_IS_MERGE_FOLDER (folder)) {
+ return TRUE;
+ }
+
+ TnyAccount* account = tny_folder_get_account ((TnyFolder*)folder);
+ if (!account) {
+ g_warning ("folder without account");
+ return FALSE;
+ }
+
+ /* Outbox is a special case, using a derived TnyAccount: */
+ if (MODEST_IS_TNY_OUTBOX_ACCOUNT (account)) {
+ //g_warning ("BUG: should not be reached");
+ /* should be handled with the MERGE_FOLDER above*/
+ g_object_unref (G_OBJECT(account));
+ return TRUE;
+ }
+
+ const gchar* account_id = tny_account_get_id (account);
+ if (!account_id) {
+ g_warning ("BUG: account without account id");
+ g_object_unref (G_OBJECT(account));
+ return FALSE;
+ }
+
+ g_object_unref (G_OBJECT(account));
+ return (strcmp (account_id, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) == 0);
+}
+
+gboolean
+modest_tny_folder_is_memory_card_folder (TnyFolder *folder)
+{
+ g_return_val_if_fail (folder, FALSE);
+
+ /* The merge folder is a special case,
+ * used to merge the per-account local outbox folders.
+ * and can have no get_account() implementation.
+ */
+ if (TNY_IS_MERGE_FOLDER (folder))
+ return FALSE;
+
+ TnyAccount* account = tny_folder_get_account ((TnyFolder*)folder);
+ if (!account)
+ return FALSE;
+
+ const gchar* account_id = tny_account_get_id (account);
+ if (!account_id)
+ return FALSE;
+
+ g_object_unref (G_OBJECT(account));
+
+ return (strcmp (account_id, MODEST_MMC_ACCOUNT_ID) == 0);
+}
+
+
+TnyFolderType
+modest_tny_folder_get_local_or_mmc_folder_type (TnyFolder *folder)
+{
+ g_return_val_if_fail (folder, TNY_FOLDER_TYPE_UNKNOWN);
+ g_return_val_if_fail (modest_tny_folder_is_local_folder(folder)||
+ modest_tny_folder_is_memory_card_folder(folder),
+ TNY_FOLDER_TYPE_UNKNOWN);
+
+ /* The merge folder is a special case,
+ * used to merge the per-account local outbox folders.
+ * and can have no get_account() implementation.
+ * We should do something more sophisticated if we
+ * ever use TnyMergeFolder for anything else.
+ */
+ if (TNY_IS_MERGE_FOLDER (folder))
+ return TNY_FOLDER_TYPE_OUTBOX;
+
+ /* Outbox is a special case, using a derived TnyAccount: */
+ TnyAccount* parent_account = tny_folder_get_account (folder);
+ if (parent_account && MODEST_IS_TNY_OUTBOX_ACCOUNT (parent_account)) {
+ g_object_unref (parent_account);
+ return TNY_FOLDER_TYPE_OUTBOX;
+ }
+
+ if (parent_account) {
+ g_object_unref (parent_account);
+ parent_account = NULL;
+ }
+
+ /* we need to use the camel functions, because we want the
+ * _full name_, that is, the full path name of the folder,
+ * to distinguish between 'Outbox' and 'myfunkyfolder/Outbox'
+ */
+ CamelFolder *camel_folder = tny_camel_folder_get_folder (TNY_CAMEL_FOLDER(folder));
+ if (!camel_folder)
+ return TNY_FOLDER_TYPE_UNKNOWN;
+
+ const gchar *full_name = camel_folder_get_full_name (camel_folder);
+ /* printf ("DEBUG: %s: full_name=%s\n", __FUNCTION__, full_name); */
+ camel_object_unref (CAMEL_OBJECT(camel_folder));
+
+ if (!full_name)
+ return TNY_FOLDER_TYPE_UNKNOWN;
+ else
+ return modest_local_folder_info_get_type (full_name);
+}
+
+gboolean
+modest_tny_folder_is_outbox_for_account (TnyFolder *folder, TnyAccount *account)
+{
+ g_return_val_if_fail(folder, FALSE);
+ g_return_val_if_fail(account, FALSE);
+
+ if (modest_tny_folder_get_local_or_mmc_folder_type (folder) != TNY_FOLDER_TYPE_OUTBOX)
+ return FALSE;
+
+ return TRUE;
+#if 0
+ /* we need to use the camel functions, because we want the
+ * _full name_, that is, the full path name of the folder,
+ * to distinguis between 'Outbox' and 'myfunkyfolder/Outbox'
+ */
+ CamelFolder *camel_folder = tny_camel_folder_get_folder (TNY_CAMEL_FOLDER(folder));
+ if (!camel_folder)
+ return FALSE;
+
+ const gchar *full_name = camel_folder_get_full_name (camel_folder);
+ camel_object_unref (CAMEL_OBJECT(camel_folder));
+
+ if (!full_name)
+ return TNY_FOLDER_TYPE_UNKNOWN;
+ else
+ return modest_local_folder_info_get_type (full_name);
+
+ return FALSE;
+#endif
+}
+
+gchar*
+modest_tny_folder_get_header_unique_id (TnyHeader *header)
+{
+ TnyFolder *folder;
+ gchar *url, *retval;
+ const gchar *uid;
+
+ g_return_val_if_fail (TNY_IS_HEADER (header), NULL);
+
+ folder = tny_header_get_folder (header);
+ if (!folder)
+ return NULL;
+
+ url = tny_folder_get_url_string (folder);
+ uid = tny_header_get_uid (header);
+
+ retval = g_strjoin ("/", url, uid, NULL);
+
+ g_free (url);
+ g_object_unref (folder);
+
+ return retval;
+}
+
+TnyAccount *
+modest_tny_folder_get_account (TnyFolder *folder)
+{
+ TnyAccount *account = NULL;
+
+ if (TNY_IS_MERGE_FOLDER (folder)) {
+ /* TnyMergeFolder does not support get_account(),
+ * because it could be merging folders from multiple accounts.
+ * So we assume that this is the local folders account: */
+
+ account = modest_tny_account_store_get_local_folders_account (modest_runtime_get_account_store());
+ } else {
+ account = tny_folder_get_account (folder);
+ }