Fix modest_tny_msg_header_get_all_recipients_list (in case from is empty)
[modest] / src / modest-local-folder-info.c
index 1c89200..d0bcb75 100644 (file)
 #include <glib/gi18n.h>
 #include <string.h> /* strcmp */
 #include <modest-local-folder-info.h>
+#include <modest-defs.h>
+#include <stdio.h>
 
 typedef struct {
-       ModestLocalFolderType   type;
-       const gchar             *name;
-       const gchar             *display_name;
+       TnyFolderType   type;
+       const gchar     *name;
+       const gchar     *display_name;
 } ModestLocalFolder;
 
 const ModestLocalFolder ModestLocalFolderMap[] = {
-       { MODEST_LOCAL_FOLDER_TYPE_JUNK,    "junk",    N_("Junk")},
-       { MODEST_LOCAL_FOLDER_TYPE_TRASH,   "trash",   N_("Trash")},
-       { MODEST_LOCAL_FOLDER_TYPE_DRAFTS,  "drafts",  N_("Drafts")},
-       { MODEST_LOCAL_FOLDER_TYPE_SENT,    "sent",    N_("Sent")},
-       { MODEST_LOCAL_FOLDER_TYPE_OUTBOX,  "outbox",  N_("Outbox")},
-       { MODEST_LOCAL_FOLDER_TYPE_ARCHIVE, "archive", N_("Archive")}
+       { TNY_FOLDER_TYPE_UNKNOWN,  "<unknown>",  N_("<Unknown>")},
+       { TNY_FOLDER_TYPE_NORMAL,   "<normal>",   N_("<Normal>")},
+       { TNY_FOLDER_TYPE_OUTBOX,   "outbox",     N_("mcen_me_folder_outbox")},
+       { TNY_FOLDER_TYPE_TRASH,    "trash",      N_("Trash")},
+       { TNY_FOLDER_TYPE_JUNK,     "junk",       N_("Junk")},
+       { TNY_FOLDER_TYPE_SENT,     "sent",       N_("mcen_me_folder_sent")},
+       { TNY_FOLDER_TYPE_ROOT,     "<root>",     N_("<root>")},
+       { TNY_FOLDER_TYPE_NOTES,    "notes",      N_("Notes")},
+       { TNY_FOLDER_TYPE_DRAFTS,   "drafts",     N_("mcen_me_folder_drafts")},
+       { TNY_FOLDER_TYPE_ARCHIVE,  "archive",    N_("mcen_me_folder_archive")}
 };
 
 
-ModestLocalFolderType
+TnyFolderType
 modest_local_folder_info_get_type (const gchar *name)
 {
        int i;
-
-       g_return_val_if_fail (name, MODEST_LOCAL_FOLDER_TYPE_UNKNOWN);
+       g_return_val_if_fail (name, TNY_FOLDER_TYPE_UNKNOWN);
 
        for (i = 0; i != G_N_ELEMENTS(ModestLocalFolderMap); ++i) {
                if (strcmp (ModestLocalFolderMap[i].name, name) == 0)
                        return ModestLocalFolderMap[i].type;
        }
-       return MODEST_LOCAL_FOLDER_TYPE_UNKNOWN;
+       return TNY_FOLDER_TYPE_UNKNOWN;
 }
 
+
 const gchar*
-modest_local_folder_info_get_type_name (ModestLocalFolderType type)
+modest_local_folder_info_get_type_name (TnyFolderType type)
 {
        int i = 0;
-       g_return_val_if_fail (type > MODEST_LOCAL_FOLDER_TYPE_UNKNOWN &&
-                             type < MODEST_LOCAL_FOLDER_TYPE_NUM, NULL);
+       g_return_val_if_fail (type >= TNY_FOLDER_TYPE_UNKNOWN &&
+                             type <  TNY_FOLDER_TYPE_NUM, NULL);
        
        for (i = 0; i != G_N_ELEMENTS(ModestLocalFolderMap); ++i) {
                if (ModestLocalFolderMap[i].type == type)
@@ -76,24 +82,69 @@ modest_local_folder_info_get_type_name (ModestLocalFolderType type)
 }
 
 const gchar*
-modest_local_folder_info_get_type_display_name (ModestLocalFolderType type)
+modest_local_folder_info_get_type_display_name (TnyFolderType type)
 {
        int i = 0;
-       g_return_val_if_fail (type > MODEST_LOCAL_FOLDER_TYPE_UNKNOWN &&
-                             type < MODEST_LOCAL_FOLDER_TYPE_NUM, NULL);
+       g_return_val_if_fail (type >= TNY_FOLDER_TYPE_UNKNOWN &&
+                             type <  TNY_FOLDER_TYPE_NUM, NULL);
        
+       /* Note that we call _() to get the localized name.
+        * This works because we used N_() on the static string when we initialized the array,
+        * to mark the string for translation.
+        */
        for (i = 0; i != G_N_ELEMENTS(ModestLocalFolderMap); ++i) {
                if (ModestLocalFolderMap[i].type == type)
-                       return ModestLocalFolderMap[i].display_name;
+                       return _(ModestLocalFolderMap[i].display_name);
        }
        return NULL;    
 }
 
 
 gchar *
-modest_local_folder_info_get_maildir_path (void)
+modest_local_folder_info_get_maildir_path (const gchar* location_filepath)
+{
+       return g_build_filename (location_filepath ? location_filepath : g_get_home_dir(),
+                                MODEST_DIR,
+                                MODEST_LOCAL_FOLDERS_MAILDIR, 
+                                NULL);
+}
+
+gchar*
+modest_per_account_local_outbox_folder_info_get_maildir_path (const gchar* account_name)
 {
-       return g_build_filename (g_get_home_dir(), ".modest",
-                                "local_folders", NULL);
+       /* This directory should contain an "outbox" child directory: */
+       gchar *escaped, *filename;
+
+#if GLIB_CHECK_VERSION(2, 16, 0)
+       escaped = g_uri_escape_string (account_name, NULL, FALSE);
+#else
+       /* TODO: escape without calling glib */
+       escaped = g_strdup (account_name);
+#endif
+       filename = g_build_filename (g_get_home_dir(),
+                                    MODEST_DIR,
+                                    MODEST_PER_ACCOUNT_LOCAL_OUTBOX_FOLDERS_MAILDIR, 
+                                    escaped,
+                                    NULL);
+       g_free (escaped);
+
+       return filename;
 }
 
+gchar*
+modest_per_account_local_outbox_folder_info_get_maildir_path_to_outbox_folder (const gchar* account_name)
+{
+       gchar *path_to_account_folder = 
+               modest_per_account_local_outbox_folder_info_get_maildir_path(account_name);
+       if (!path_to_account_folder)
+               return NULL;
+
+       gchar *path = g_build_filename (path_to_account_folder, "outbox", NULL);
+
+       g_free (path_to_account_folder);
+
+       return path;
+}
+
+
+