+modest_tny_folder_get_rules (TnyFolder *folder)
+{
+ ModestTnyFolderRules rules = 0;
+ TnyFolderType type;
+
+ g_return_val_if_fail (TNY_IS_FOLDER(folder), -1);
+
+ if (modest_tny_folder_is_local_folder (folder) ||
+ modest_tny_folder_is_memory_card_folder (folder)) {
+
+ type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
+ g_return_val_if_fail (type != TNY_FOLDER_TYPE_INVALID, -1);
+
+ switch (type) {
+ case TNY_FOLDER_TYPE_OUTBOX:
+ case TNY_FOLDER_TYPE_SENT:
+ case TNY_FOLDER_TYPE_DRAFTS:
+ rules |= MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE;
+ case TNY_FOLDER_TYPE_INBOX:
+ case TNY_FOLDER_TYPE_JUNK:
+ case TNY_FOLDER_TYPE_TRASH:
+ case TNY_FOLDER_TYPE_ROOT:
+ case TNY_FOLDER_TYPE_NOTES:
+ case TNY_FOLDER_TYPE_CONTACTS:
+ case TNY_FOLDER_TYPE_CALENDAR:
+ case TNY_FOLDER_TYPE_ARCHIVE:
+ case TNY_FOLDER_TYPE_MERGE:
+ case TNY_FOLDER_TYPE_NUM:
+ rules |= MODEST_FOLDER_RULES_FOLDER_NON_DELETABLE;
+ rules |= MODEST_FOLDER_RULES_FOLDER_NON_MOVEABLE;
+ rules |= MODEST_FOLDER_RULES_FOLDER_NON_RENAMEABLE;
+ default:
+ break;
+ }
+ } else {
+ ModestProtocolRegistry *protocol_registry;
+ ModestProtocolType protocol_type;
+ TnyFolderType folder_type;
+ TnyAccount *account;
+
+ protocol_registry = modest_runtime_get_protocol_registry ();
+
+ account = modest_tny_folder_get_account ((TnyFolder*)folder);
+ if (!account)
+ return -1; /* no account: nothing is allowed */
+
+ protocol_type = modest_tny_account_get_protocol_type (account);
+
+ if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS)) {
+ rules = 0;
+ } else {
+ /* pop, nntp, ... */
+ rules =
+ MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE |
+ MODEST_FOLDER_RULES_FOLDER_NON_DELETABLE |
+ MODEST_FOLDER_RULES_FOLDER_NON_MOVEABLE |
+ MODEST_FOLDER_RULES_FOLDER_NON_RENAMEABLE;
+
+ }
+ g_object_unref (G_OBJECT(account));
+
+ /* Neither INBOX nor ROOT, nor ARCHIVE folders should me moveable */
+ folder_type = modest_tny_folder_guess_folder_type (folder);
+ g_return_val_if_fail (folder_type != TNY_FOLDER_TYPE_INVALID, -1);
+
+ if ((folder_type == TNY_FOLDER_TYPE_INBOX) ||
+ (folder_type == TNY_FOLDER_TYPE_ROOT) ||
+ (folder_type == TNY_FOLDER_TYPE_ARCHIVE)) {
+ rules |= MODEST_FOLDER_RULES_FOLDER_NON_DELETABLE;
+ rules |= MODEST_FOLDER_RULES_FOLDER_NON_MOVEABLE;
+ rules |= MODEST_FOLDER_RULES_FOLDER_NON_RENAMEABLE;
+ }
+ }
+ return rules;
+}
+
+
+
+gboolean
+modest_tny_folder_is_local_folder (TnyFolder *folder)
+{
+ 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) {
+ g_object_unref (account);
+ return FALSE;
+ }
+
+ g_object_unref (account);
+
+ return (strcmp (account_id, MODEST_MMC_ACCOUNT_ID) == 0);
+}
+
+gboolean
+modest_tny_folder_is_remote_folder (TnyFolder *folder)
+{
+ gboolean is_local = TRUE;
+
+ g_return_val_if_fail (TNY_IS_FOLDER(folder), FALSE);
+
+ is_local = ((modest_tny_folder_is_local_folder(folder)) ||
+ (modest_tny_folder_is_memory_card_folder(folder)));
+
+
+ return !is_local;
+}
+
+
+TnyFolderType
+modest_tny_folder_get_local_or_mmc_folder_type (TnyFolder *folder)
+{
+ g_return_val_if_fail (folder, TNY_FOLDER_TYPE_INVALID);
+ g_return_val_if_fail (modest_tny_folder_is_local_folder(folder)||
+ modest_tny_folder_is_memory_card_folder(folder),
+ TNY_FOLDER_TYPE_INVALID);
+
+ /* 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'
+ */
+
+ const gchar *full_name = tny_camel_folder_get_full_name (TNY_CAMEL_FOLDER (folder));
+ /* printf ("DEBUG: %s: full_name=%s\n", __FUNCTION__, full_name); */
+
+ 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)