Fix modest_tny_msg_header_get_all_recipients_list (in case from is empty)
[modest] / src / modest-tny-folder.c
index 8188eeb..f654a40 100644 (file)
@@ -30,6 +30,7 @@
 #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>
@@ -84,6 +85,9 @@ modest_tny_folder_guess_folder_type (TnyFolder *folder)
                                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);
@@ -255,9 +259,9 @@ 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. 
+
+       /* 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))
@@ -268,15 +272,15 @@ modest_tny_folder_is_memory_card_folder   (TnyFolder *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);
-       
+
        return (strcmp (account_id, MODEST_MMC_ACCOUNT_ID) == 0);
-}      
+}
 
 gboolean
 modest_tny_folder_is_remote_folder   (TnyFolder *folder)
@@ -402,7 +406,7 @@ modest_tny_folder_get_account (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)
@@ -415,7 +419,7 @@ modest_tny_folder_has_subfolder_with_name (TnyFolderStore *parent,
 
        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, FALSE, &err);
@@ -423,19 +427,21 @@ modest_tny_folder_has_subfolder_with_name (TnyFolderStore *parent,
        /* 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;
                }
 
@@ -455,17 +461,15 @@ modest_tny_folder_has_subfolder_with_name (TnyFolderStore *parent,
                } 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;
 }
 
@@ -524,3 +528,43 @@ modest_tny_folder_get_display_name (TnyFolder *folder)
 
        return fname;
 }
+
+TnyFolder *
+modest_tny_folder_store_find_folder_from_uri (TnyFolderStore *folder_store, const gchar *uri)
+{
+       TnyList *children;
+       TnyIterator *iterator;
+       TnyFolder *result;
+
+       result = NULL;
+       children = TNY_LIST (tny_simple_list_new ());
+       tny_folder_store_get_folders (folder_store, children, NULL, FALSE, NULL);
+
+       for (iterator = tny_list_create_iterator (children);
+            !tny_iterator_is_done (iterator) && (result == NULL);
+            tny_iterator_next (iterator)) {
+               TnyFolderStore *child;
+
+               child = TNY_FOLDER_STORE (tny_iterator_get_current (iterator));
+
+               if (TNY_IS_FOLDER (child)) {
+                       gchar *folder_url;
+
+                       folder_url = tny_folder_get_url_string (TNY_FOLDER (child));
+                       if (g_str_has_prefix (uri, folder_url))
+                               result = g_object_ref (child);
+                       g_free (folder_url);
+               }
+
+               if ((child == NULL) && TNY_IS_FOLDER_STORE (child)) {
+                       result = modest_tny_folder_store_find_folder_from_uri (child, uri);
+               }
+
+               g_object_unref (child);
+       }
+
+       g_object_unref (iterator);
+       g_object_unref (children);
+
+       return result;
+}