#include <glib.h>
#include <glib/gi18n.h>
#include <string.h>
+#include <modest-defs.h>
#include <modest-tny-folder.h>
+#include <modest-tny-account.h>
#include <modest-tny-outbox-account.h>
#include <tny-simple-list.h>
#include <tny-camel-folder.h>
#include <tny-merge-folder.h>
-#include <modest-protocol-info.h>
#include <modest-runtime.h>
#include <modest-tny-account-store.h>
#include <modest-text-utils.h>
type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
else
type = tny_folder_get_folder_type (TNY_FOLDER (folder));
+
+ /* Fallback code, some servers (Dovecot in some versions)
+ report incorrectly that the INBOX folder is a normal
+ folder. Really ugly code but... */
+ if (type == TNY_FOLDER_TYPE_NORMAL) {
+ TnyFolderStore *parent = tny_folder_get_folder_store (folder);
+ if (parent) {
+ if (TNY_IS_ACCOUNT (parent)) {
+ gchar *downcase =
+ g_ascii_strdown (tny_camel_folder_get_full_name (TNY_CAMEL_FOLDER (folder)),
+ -1);
+
+ if ((strlen (downcase) == 5) &&
+ !strncmp (downcase, "inbox", 5))
+ type = TNY_FOLDER_TYPE_INBOX;
+ if ((strlen (downcase) == 7) &&
+ !strncmp (downcase, "archive", 7))
+ type = TNY_FOLDER_TYPE_ARCHIVE;
+ g_free (downcase);
+ }
+ g_object_unref (parent);
+ }
+ }
if (type == TNY_FOLDER_TYPE_UNKNOWN) {
const gchar *folder_name =
const gchar*
-modest_tny_folder_get_help_id (const TnyFolder *folder)
+modest_tny_folder_get_help_id (TnyFolder *folder)
{
TnyFolderType type;
const gchar* help_id = NULL;
break;
}
} else {
- ModestTransportStoreProtocol proto;
+ 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 */
- proto = modest_protocol_info_get_transport_store_protocol (tny_account_get_proto (account));
+ protocol_type = modest_tny_account_get_protocol_type (account);
- if (proto == MODEST_PROTOCOL_STORE_IMAP) {
+ if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS)) {
rules = 0;
} else {
/* pop, nntp, ... */
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.
+
+ /* 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;
const gchar* account_id = tny_account_get_id (account);
- if (!account_id)
+ if (!account_id) {
+ g_object_unref (account);
return FALSE;
+ }
+
+ g_object_unref (account);
- g_object_unref (G_OBJECT(account));
-
return (strcmp (account_id, MODEST_MMC_ACCOUNT_ID) == 0);
-}
+}
gboolean
modest_tny_folder_is_remote_folder (TnyFolder *folder)
*
* The code that uses the query is available in revision 3152.
*/
-gboolean
+gboolean
modest_tny_folder_has_subfolder_with_name (TnyFolderStore *parent,
const gchar *new_name,
gboolean non_strict)
g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), FALSE);
g_return_val_if_fail (new_name, FALSE);
-
+
/* Get direct subfolders */
subfolders = tny_simple_list_new ();
- tny_folder_store_get_folders (parent, subfolders, NULL, &err);
+ tny_folder_store_get_folders (parent, subfolders, NULL, FALSE, &err);
/* Check names */
iter = tny_list_create_iterator (subfolders);
while (!tny_iterator_is_done (iter) && !has_name) {
-
+
const gchar *name;
-
+
folder = (TnyFolder*)tny_iterator_get_current (iter);
if (!folder || ! TNY_IS_FOLDER(folder)) {
g_warning ("%s: invalid folder", __FUNCTION__);
+ tny_iterator_next (iter);
continue;
}
-
+
name = tny_folder_get_name (folder);
if (!name) {
g_warning ("%s: folder name == NULL", __FUNCTION__);
g_object_unref (folder);
+ tny_iterator_next (iter);
continue;
}
} else {
has_name = FALSE;
}
-
+
g_object_unref (folder);
tny_iterator_next(iter);
}
-
+
/* free */
- if (iter != NULL)
- g_object_unref (iter);
- if (subfolders != NULL)
- g_object_unref (subfolders);
-
+ g_object_unref (iter);
+ g_object_unref (subfolders);
+
return has_name;
}
}
return found;
}
+
+gchar *
+modest_tny_folder_get_display_name (TnyFolder *folder)
+{
+ TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN;
+ gchar *fname;
+
+ g_return_val_if_fail (TNY_IS_FOLDER (folder), NULL);
+
+ fname = g_strdup (tny_folder_get_name (folder));
+ type = tny_folder_get_folder_type (folder);
+
+ if (modest_tny_folder_is_local_folder (TNY_FOLDER (folder)) ||
+ modest_tny_folder_is_memory_card_folder (TNY_FOLDER (folder))) {
+ type = modest_tny_folder_get_local_or_mmc_folder_type (TNY_FOLDER (folder));
+ if (type != TNY_FOLDER_TYPE_UNKNOWN) {
+ g_free (fname);
+ fname = g_strdup (modest_local_folder_info_get_type_display_name (type));
+ }
+ } else {
+ /* Sometimes an special folder is reported by the server as
+ NORMAL, like some versions of Dovecot */
+ if (type == TNY_FOLDER_TYPE_NORMAL ||
+ type == TNY_FOLDER_TYPE_UNKNOWN) {
+ type = modest_tny_folder_guess_folder_type (TNY_FOLDER (folder));
+ }
+ }
+
+ if (type == TNY_FOLDER_TYPE_INBOX) {
+ g_free (fname);
+ fname = g_strdup (_("mcen_me_folder_inbox"));
+ }
+
+ return fname;
+}
+
+TnyFolder *
+modest_tny_folder_store_find_folder_from_uri (TnyFolderStore *folder_store, const gchar *uri)
+{
+ TnyList *children;
+ TnyIterator *iterator;
+ TnyFolder *result;
+ gchar *uri_to_find, *slash;
+ gint uri_lenght;
+
+ if (uri == NULL)
+ return NULL;
+
+ slash = strrchr (uri, '/');
+ if (slash == NULL)
+ return NULL;
+
+ result = NULL;
+ children = TNY_LIST (tny_simple_list_new ());
+ tny_folder_store_get_folders (folder_store, children, NULL, FALSE, NULL);
+
+ uri_lenght = slash - uri + 1;
+ uri_to_find = g_malloc0 (sizeof(char) * uri_lenght);
+ strncpy (uri_to_find, uri, uri_lenght);
+ uri_to_find[uri_lenght - 1] = '\0';
+
+ for (iterator = tny_list_create_iterator (children);
+ iterator && !tny_iterator_is_done (iterator) && (result == NULL);
+ tny_iterator_next (iterator)) {
+ TnyFolderStore *child;
+
+ child = TNY_FOLDER_STORE (tny_iterator_get_current (iterator));
+ if (!child)
+ continue;
+
+ if (TNY_IS_FOLDER (child)) {
+ gchar *folder_url;
+
+ folder_url = tny_folder_get_url_string (TNY_FOLDER (child));
+ if (uri_to_find && folder_url && !strcmp (folder_url, uri_to_find))
+ result = g_object_ref (child);
+ g_free (folder_url);
+ }
+
+ if ((result == NULL) && TNY_IS_FOLDER_STORE (child)) {
+ result = modest_tny_folder_store_find_folder_from_uri (child, uri);
+ }
+
+ g_object_unref (child);
+ }
+
+ g_free (uri_to_find);
+ g_object_unref (iterator);
+ g_object_unref (children);
+
+ return result;
+}