aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mail/em-migrate.c126
1 files changed, 118 insertions, 8 deletions
diff --git a/mail/em-migrate.c b/mail/em-migrate.c
index 6fa53646e8..2ca4a990fb 100644
--- a/mail/em-migrate.c
+++ b/mail/em-migrate.c
@@ -67,7 +67,9 @@
#include "e-util/e-util-private.h"
#include "e-util/e-plugin.h"
+#include "mail-component.h"
#include "mail-config.h"
+#include "mail-session.h"
#include "em-utils.h"
#include "em-migrate.h"
@@ -1194,7 +1196,7 @@ static GtkLabel *label;
static GtkProgressBar *progress;
static void
-em_migrate_setup_progress_dialog (void)
+em_migrate_setup_progress_dialog (const char *desc)
{
GtkWidget *vbox, *hbox, *w;
@@ -1207,9 +1209,8 @@ em_migrate_setup_progress_dialog (void)
gtk_widget_show (vbox);
gtk_container_add ((GtkContainer *) window, vbox);
- w = gtk_label_new (_("The location and hierarchy of the Evolution mailbox "
- "folders has changed since Evolution 1.x.\n\nPlease be "
- "patient while Evolution migrates your folders..."));
+ w = gtk_label_new (desc);
+
gtk_label_set_line_wrap ((GtkLabel *) w, TRUE);
gtk_widget_show (w);
gtk_box_pack_start_defaults ((GtkBox *) vbox, w);
@@ -1240,12 +1241,11 @@ em_migrate_set_folder_name (const char *folder_name)
{
char *text;
- text = g_strdup_printf (_("Migrating `%s':"), folder_name);
+ text = g_strdup_printf (_("Migrating '%s':"), folder_name);
gtk_label_set_text (label, text);
g_free (text);
gtk_progress_bar_set_fraction (progress, 0.0);
-
while (gtk_events_pending ())
gtk_main_iteration ();
}
@@ -1862,7 +1862,9 @@ em_migrate_local_folders_1_4 (EMMigrateSession *session, CamelException *ex)
return -1;
}
- em_migrate_setup_progress_dialog ();
+ em_migrate_setup_progress_dialog (_("The location and hierarchy of the Evolution mailbox "
+ "folders has changed since Evolution 1.x.\n\nPlease be "
+ "patient while Evolution migrates your folders..."));
while (res == 0 && (dent = readdir (dir))) {
char *full_path;
@@ -2837,6 +2839,112 @@ em_update_sa_junk_setting_2_23 (void)
g_object_unref (client);
}
+
+static void
+migrate_folders(CamelStore *store, CamelFolderInfo *fi, const char *acc, CamelException *ex)
+{
+ CamelFolder *folder;
+
+ while (fi) {
+ char *tmp = g_strdup_printf ("%s/%s", acc, fi->full_name);
+ em_migrate_set_folder_name (tmp);
+ g_free (tmp);
+ folder = camel_store_get_folder (store, fi->full_name, 0, ex);
+ camel_folder_summary_migrate_infos (folder->summary);
+ migrate_folders(store, fi->child, acc, ex);
+ fi = fi->next;
+ }
+}
+
+static CamelStore *
+setup_local_store (MailComponent *mc)
+{
+ CamelURL *url;
+ char *tmp;
+ CamelStore *store;
+
+ url = camel_url_new("mbox:", NULL);
+ tmp = g_build_filename (mail_component_peek_base_directory(mc), "local", NULL);
+ camel_url_set_path(url, tmp);
+ g_free(tmp);
+ tmp = camel_url_to_string(url, 0);
+ store = (CamelStore *)camel_session_get_service(session, tmp, CAMEL_PROVIDER_STORE, NULL);
+ g_free(tmp);
+
+ return store;
+
+}
+static void
+migrate_to_db()
+{
+ EAccountList *accounts;
+ EIterator *iter;
+ int i=0, len;
+ MailComponent *component = mail_component_peek ();
+ CamelStore *store = NULL;
+ CamelFolderInfo *info;
+
+ if (!(accounts = mail_config_get_accounts ()))
+ return;
+
+ iter = e_list_get_iterator ((EList *) accounts);
+ len = e_list_length ((EList *) accounts);
+
+ camel_session_set_online ((CamelSession *) session, FALSE);
+ em_migrate_setup_progress_dialog (_("The summary format of the Evolution mailbox "
+ "folders has been moved to sqlite since Evolution 2.24.\n\nPlease be "
+ "patient while Evolution migrates your folders..."));
+
+ em_migrate_set_progress ( (double)i/(len+1));
+ store = setup_local_store (component);
+ info = camel_store_get_folder_info (store, NULL, CAMEL_STORE_FOLDER_INFO_RECURSIVE|CAMEL_STORE_FOLDER_INFO_FAST|CAMEL_STORE_FOLDER_INFO_SUBSCRIBED, NULL);
+ if (info) {
+ migrate_folders(store, info, _("On This Computer"), NULL);
+ }
+ i++;
+ em_migrate_set_progress ( (double)i/(len+1));
+
+
+ while (e_iterator_is_valid (iter)) {
+ EAccount *account = (EAccount *) e_iterator_get (iter);
+ EAccountService *service;
+ const char *name;
+
+
+ service = account->source;
+ name = account->name;
+ em_migrate_set_progress ( (double)i/(len+1));
+ if (account->enabled
+ && service->url != NULL
+ && service->url[0]
+ && strncmp(service->url, "mbox:", 5) != 0) {
+
+ CamelException ex;
+
+ camel_exception_init (&ex);
+ mail_component_load_store_by_uri (component, service->url, name);
+
+ store = (CamelStore *) camel_session_get_service (session, service->url, CAMEL_PROVIDER_STORE, &ex);
+ info = camel_store_get_folder_info (store, NULL, CAMEL_STORE_FOLDER_INFO_RECURSIVE|CAMEL_STORE_FOLDER_INFO_FAST|CAMEL_STORE_FOLDER_INFO_SUBSCRIBED, &ex);
+ if (info) {
+ migrate_folders(store, info, account->name, &ex);
+
+ } else
+ printf("%s(%d):%s: failed to get folder infos \n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
+ camel_exception_clear(&ex);
+
+ }
+ i++;
+ e_iterator_next (iter);
+
+ }
+
+ //camel_session_set_online ((CamelSession *) session, TRUE);
+
+ g_object_unref (iter);
+ em_migrate_close_progress_dialog ();
+}
+
int
em_migrate (const char *evolution_dir, int major, int minor, int revision, CamelException *ex)
{
@@ -2926,8 +3034,10 @@ em_migrate (const char *evolution_dir, int major, int minor, int revision, Camel
if (major < 2 || (major == 2 && minor < 22))
em_update_message_notify_settings_2_21 ();
- if (major < 2 || (major == 2 && minor < 24))
+ if (major < 2 || (major == 2 && minor < 24)) {
em_update_sa_junk_setting_2_23 ();
+ migrate_to_db();
+ }
#endif /* !G_OS_WIN32 */
return 0;