diff options
Diffstat (limited to 'mail')
-rw-r--r-- | mail/e-mail-migrate.c | 82 | ||||
-rw-r--r-- | mail/e-mail-paned-view.c | 28 |
2 files changed, 109 insertions, 1 deletions
diff --git a/mail/e-mail-migrate.c b/mail/e-mail-migrate.c index 3b7de4c387..311d5d2359 100644 --- a/mail/e-mail-migrate.c +++ b/mail/e-mail-migrate.c @@ -1165,6 +1165,85 @@ em_ensure_proxy_ignore_hosts_being_list (void) g_object_unref (client); } +static void +em_rename_view_in_folder (gpointer data, + gpointer user_data) +{ + const gchar *filename = data; + const gchar *views_dir = user_data; + gchar *folderpos, *dotpos; + + g_return_if_fail (filename != NULL); + g_return_if_fail (views_dir != NULL); + + folderpos = strstr (filename, "-folder:__"); + if (!folderpos) + folderpos = strstr (filename, "-folder___"); + if (!folderpos) + return; + + /* points on 'f' from the "folder" word */ + folderpos++; + dotpos = strrchr (filename, '.'); + if (folderpos < dotpos && g_str_equal (dotpos, ".xml")) { + GChecksum *checksum; + gchar *oldname, *newname, *newfile; + + *dotpos = 0; + + /* use MD5 checksum of the folder URI, to not depend on its length */ + checksum = g_checksum_new (G_CHECKSUM_MD5); + g_checksum_update (checksum, (const guchar *) folderpos, -1); + + *folderpos = 0; + newfile = g_strconcat (filename, g_checksum_get_string (checksum), ".xml", NULL); + *folderpos = 'f'; + *dotpos = '.'; + + oldname = g_build_filename (views_dir, filename, NULL); + newname = g_build_filename (views_dir, newfile, NULL); + + g_rename (oldname, newname); + + g_checksum_free (checksum); + g_free (oldname); + g_free (newname); + g_free (newfile); + } +} + +static void +em_rename_folder_views (EShellBackend *shell_backend) +{ + const gchar *config_dir; + gchar *views_dir; + GDir *dir; + + g_return_if_fail (shell_backend != NULL); + + config_dir = e_shell_backend_get_config_dir (shell_backend); + views_dir = g_build_filename (config_dir, "views", NULL); + + dir = g_dir_open (views_dir, 0, NULL); + if (dir) { + GSList *to_rename = NULL; + const gchar *filename; + + while (filename = g_dir_read_name (dir), filename) { + if (strstr (filename, "-folder:__") || + strstr (filename, "-folder___")) + to_rename = g_slist_prepend (to_rename, g_strdup (filename)); + } + + g_dir_close (dir); + + g_slist_foreach (to_rename, em_rename_view_in_folder, views_dir); + g_slist_free_full (to_rename, g_free); + } + + g_free (views_dir); +} + gboolean e_mail_migrate (EShellBackend *shell_backend, gint major, @@ -1219,5 +1298,8 @@ e_mail_migrate (EShellBackend *shell_backend, if (!migrate_local_store (shell_backend)) return FALSE; + if (major <= 2 || (major == 3 && minor < 4)) + em_rename_folder_views (shell_backend); + return TRUE; } diff --git a/mail/e-mail-paned-view.c b/mail/e-mail-paned-view.c index 7a510e3ebd..ea017c758b 100644 --- a/mail/e-mail-paned-view.c +++ b/mail/e-mail-paned-view.c @@ -778,6 +778,32 @@ mail_paned_view_get_view_instance (EMailView *view) return paned_view->priv->view_instance; } +static gchar * +empv_create_view_id (CamelFolder *folder) +{ + GChecksum *checksum; + gchar *res, *folder_uri; + + g_return_val_if_fail (folder != NULL, NULL); + + folder_uri = e_mail_folder_uri_from_folder (folder); + g_return_val_if_fail (folder_uri != NULL, NULL); + + /* to be able to migrate previously saved views */ + e_filename_make_safe (folder_uri); + + /* use MD5 checksum of the folder URI, to not depend on its length */ + checksum = g_checksum_new (G_CHECKSUM_MD5); + g_checksum_update (checksum, (const guchar *) folder_uri, -1); + + res = g_strdup (g_checksum_get_string (checksum)); + + g_checksum_free (checksum); + g_free (folder_uri); + + return res; +} + static void mail_paned_view_update_view_instance (EMailView *view) { @@ -819,7 +845,7 @@ mail_paned_view_update_view_instance (EMailView *view) priv->view_instance = NULL; } - view_id = e_mail_folder_uri_from_folder (folder); + view_id = empv_create_view_id (folder); e_filename_make_safe (view_id); outgoing_folder = |