[evolution/gnome-3-4] Run mbox-to-Maildir conversion before loading modules.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/gnome-3-4] Run mbox-to-Maildir conversion before loading modules.
- Date: Fri, 10 Aug 2012 16:35:08 +0000 (UTC)
commit b5d60a4d5a5838f95f2bb71efc49e216c978cd60
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Aug 10 12:32:47 2012 -0400
Run mbox-to-Maildir conversion before loading modules.
Invoke the mbox-to-Maildir conversion directly from main(), just
before the call to e_shell_load_modules().
The reason the code is here and not in the mail module is because
we inform the user at startup of the impending mail conversion by
displaying a popup dialog and waiting for confirmation.
This has to be done before we load modules because some of the
EShellBackends immediately add GMainContext sources that would
otherwise get dispatched during gtk_dialog_run(), and we don't
want them dispatched until after the conversion is complete.
mail/e-mail-migrate.c | 452 ------------------------------------------
shell/Makefile.am | 3 +-
shell/e-convert-local-mail.c | 344 ++++++++++++++++++++++++++++++++
shell/main.c | 15 ++
4 files changed, 361 insertions(+), 453 deletions(-)
---
diff --git a/mail/e-mail-migrate.c b/mail/e-mail-migrate.c
index 6de187e..b3cba46 100644
--- a/mail/e-mail-migrate.c
+++ b/mail/e-mail-migrate.c
@@ -73,50 +73,6 @@
/* 1.4 upgrade functions */
-#define EM_TYPE_MIGRATE_SESSION \
- (em_migrate_session_get_type ())
-
-typedef struct _EMMigrateSession {
- CamelSession parent_object;
-
- CamelStore *store; /* new folder tree store */
- gchar *srcdir; /* old folder tree path */
-} EMMigrateSession;
-
-typedef struct _EMMigrateSessionClass {
- CamelSessionClass parent_class;
-
-} EMMigrateSessionClass;
-
-GType em_migrate_session_get_type (void);
-
-G_DEFINE_TYPE (EMMigrateSession, em_migrate_session, CAMEL_TYPE_SESSION)
-
-static void
-em_migrate_session_class_init (EMMigrateSessionClass *class)
-{
-}
-
-static void
-em_migrate_session_init (EMMigrateSession *session)
-{
-}
-
-static EMMigrateSession *
-em_migrate_session_new (const gchar *user_data_dir)
-{
- const gchar *user_cache_dir;
-
- /* FIXME Really need to kill this function and
- * get the cache dir from EShellBackend. */
- user_cache_dir = mail_session_get_cache_dir ();
-
- return g_object_new (
- EM_TYPE_MIGRATE_SESSION,
- "user-data-dir", user_data_dir,
- "user-cache-dir", user_cache_dir, NULL);
-}
-
static GtkProgressBar *progress;
static void
@@ -473,372 +429,6 @@ em_update_sa_junk_setting_2_23 (void)
g_object_unref (client);
}
-static gboolean
-mbox_to_maildir_migration_needed (EShellBackend *shell_backend)
-{
- gchar *local_store;
- gchar *local_outbox;
- const gchar *data_dir;
- gboolean migration_needed = FALSE;
-
- data_dir = e_shell_backend_get_data_dir (shell_backend);
-
- local_store = g_build_filename (data_dir, "local", NULL);
- local_outbox = g_build_filename (local_store, ".Outbox", NULL);
-
- /* If this is a fresh install (no local store exists yet)
- * then obviously there's nothing to migrate to Maildir. */
- if (!g_file_test (local_store, G_FILE_TEST_IS_DIR))
- migration_needed = FALSE;
-
- /* Look for a Maildir Outbox folder. */
- else if (!g_file_test (local_outbox, G_FILE_TEST_IS_DIR))
- migration_needed = TRUE;
-
- g_free (local_store);
- g_free (local_outbox);
-
- return migration_needed;
-}
-
-/* Folder names with '.' are converted to '_' */
-static gchar *
-sanitize_maildir_folder_name (gchar *folder_name)
-{
- gchar *maildir_folder_name;
-
- maildir_folder_name = g_strdup (folder_name);
- g_strdelimit (maildir_folder_name, ".", '_');
-
- return maildir_folder_name;
-}
-
-static void
-copy_folder (CamelStore *mbox_store,
- CamelStore *maildir_store,
- const gchar *mbox_fname,
- const gchar *maildir_fname)
-{
- CamelFolder *fromfolder, *tofolder;
- GPtrArray *uids;
-
- fromfolder = camel_store_get_folder_sync (
- mbox_store, mbox_fname, 0, NULL, NULL);
- if (fromfolder == NULL) {
- g_warning ("Cannot find mbox folder %s \n", mbox_fname);
- return;
- }
-
- tofolder = camel_store_get_folder_sync (
- maildir_store, maildir_fname,
- CAMEL_STORE_FOLDER_CREATE,
- NULL, NULL);
- if (tofolder == NULL) {
- g_warning ("Cannot create maildir folder %s \n", maildir_fname);
- g_object_unref (fromfolder);
- return;
- }
-
- uids = camel_folder_get_uids (fromfolder);
- camel_folder_transfer_messages_to_sync (
- fromfolder, uids, tofolder,
- FALSE, NULL,
- NULL, NULL);
- camel_folder_free_uids (fromfolder, uids);
-
- g_object_unref (fromfolder);
- g_object_unref (tofolder);
-}
-
-static void
-copy_folders (CamelStore *mbox_store,
- CamelStore *maildir_store,
- CamelFolderInfo *fi,
- EMMigrateSession *session)
-{
- if (fi) {
- if (!g_str_has_prefix (fi->full_name, ".#evolution")) {
- gchar *maildir_folder_name;
-
- /* sanitize folder names and copy folders */
- maildir_folder_name = sanitize_maildir_folder_name (fi->full_name);
- copy_folder (
- mbox_store, maildir_store,
- fi->full_name, maildir_folder_name);
- g_free (maildir_folder_name);
- }
-
- if (fi->child)
- copy_folders (mbox_store, maildir_store, fi->child, session);
-
- copy_folders (mbox_store, maildir_store, fi->next, session);
- }
-}
-
-struct MigrateStore {
- EMMigrateSession *session;
- CamelStore *mbox_store;
- CamelStore *maildir_store;
- gboolean complete;
-};
-
-static void
-migrate_stores (struct MigrateStore *ms)
-{
- CamelFolderInfo *mbox_fi;
- CamelStore *mbox_store = ms->mbox_store;
- CamelStore *maildir_store = ms->maildir_store;
-
- mbox_fi = camel_store_get_folder_info_sync (
- mbox_store, NULL,
- CAMEL_STORE_FOLDER_INFO_RECURSIVE |
- CAMEL_STORE_FOLDER_INFO_FAST |
- CAMEL_STORE_FOLDER_INFO_SUBSCRIBED,
- NULL, NULL);
-
- /* FIXME progres dialog */
- copy_folders (mbox_store, maildir_store, mbox_fi, ms->session);
- ms->complete = TRUE;
-
- return;
-}
-
-static gboolean
-migrate_mbox_to_maildir (EShellBackend *shell_backend,
- EMMigrateSession *session)
-{
- CamelService *mbox_service, *maildir_service;
- CamelStore *mbox_store, *maildir_store;
- CamelSettings *settings;
- const gchar *data_dir;
- gchar *path;
- struct MigrateStore ms;
-
- data_dir = e_shell_backend_get_data_dir (shell_backend);
-
- mbox_service = camel_session_add_service (
- CAMEL_SESSION (session), "local_mbox", "mbox",
- CAMEL_PROVIDER_STORE, NULL);
-
- settings = camel_service_get_settings (mbox_service);
- path = g_build_filename (data_dir, "local_mbox", NULL);
- g_object_set (settings, "path", path, NULL);
- g_free (path);
-
- maildir_service = camel_session_add_service (
- CAMEL_SESSION (session), "local", "maildir",
- CAMEL_PROVIDER_STORE, NULL);
-
- settings = camel_service_get_settings (maildir_service);
- path = g_build_filename (data_dir, "local", NULL);
- g_object_set (settings, "path", path, NULL);
- g_mkdir (path, 0700);
- g_free (path);
-
- mbox_store = CAMEL_STORE (mbox_service);
- maildir_store = CAMEL_STORE (maildir_service);
-
- ms.mbox_store = mbox_store;
- ms.maildir_store = maildir_store;
- ms.session = session;
- ms.complete = FALSE;
-
- g_thread_create ((GThreadFunc) migrate_stores, &ms, TRUE, NULL);
- while (!ms.complete)
- g_main_context_iteration (NULL, TRUE);
-
- return TRUE;
-}
-
-static void
-rename_mbox_dir (EShellBackend *shell_backend)
-{
- gchar *local_mbox_path, *new_mbox_path;
- const gchar *data_dir;
-
- data_dir = e_shell_backend_get_data_dir (shell_backend);
- local_mbox_path = g_build_filename (data_dir, "local", NULL);
- new_mbox_path = g_build_filename (data_dir, "local_mbox", NULL);
-
- if (!g_file_test (local_mbox_path, G_FILE_TEST_EXISTS))
- goto exit;
-
- if (g_file_test (new_mbox_path, G_FILE_TEST_EXISTS))
- goto exit;
-
- g_rename (local_mbox_path, new_mbox_path);
-
-exit:
- g_free (local_mbox_path);
- g_free (new_mbox_path);
-}
-
-static gboolean
-create_mbox_account (EShellBackend *shell_backend,
- EMMigrateSession *session)
-{
- EMailBackend *mail_backend;
- EMailSession *mail_session;
- CamelService *service;
- CamelURL *url;
- EAccountList *accounts;
- EAccount *account;
- const gchar *data_dir;
- gchar *name, *id, *temp, *uri, *folder_uri;
-
- mail_backend = E_MAIL_BACKEND (shell_backend);
- mail_session = e_mail_backend_get_session (mail_backend);
- data_dir = e_shell_backend_get_data_dir (shell_backend);
-
- account = e_account_new ();
- account->enabled = TRUE;
-
- g_free (account->uid);
- account->uid = g_strdup ("local_mbox");
-
- url = camel_url_new ("mbox:", NULL);
- temp = g_build_filename (data_dir, "local_mbox", NULL);
- camel_url_set_path (url, temp);
- g_free (temp);
-
- uri = camel_url_to_string (url, 0);
- e_account_set_string (account, E_ACCOUNT_SOURCE_URL, uri);
-
-#ifndef G_OS_WIN32
- name = g_locale_to_utf8 (g_get_user_name (), -1, NULL, NULL, NULL);
-#else
- name = g_strdup (g_get_user_name ());
-#endif
-
- id = g_strconcat (name, "@", "localhost", NULL);
- e_account_set_string (account, E_ACCOUNT_ID_NAME, name);
- e_account_set_string (account, E_ACCOUNT_ID_ADDRESS, id);
- e_account_set_string (account, E_ACCOUNT_NAME, id);
-
- accounts = e_get_account_list ();
- if (e_account_list_find (accounts, E_ACCOUNT_ID_ADDRESS, id)) {
- g_object_unref (account);
- goto exit;
- }
-
- /* This will also add it to the EMailSession. */
- e_account_list_add (accounts, account);
-
- service = camel_session_get_service (
- CAMEL_SESSION (mail_session), account->uid);
-
- folder_uri = e_mail_folder_uri_build (
- CAMEL_STORE (service), "Sent");
- e_account_set_string (
- account, E_ACCOUNT_SENT_FOLDER_URI, folder_uri);
- g_free (folder_uri);
-
- folder_uri = e_mail_folder_uri_build (
- CAMEL_STORE (service), "Drafts");
- e_account_set_string (
- account, E_ACCOUNT_DRAFTS_FOLDER_URI, folder_uri);
- g_free (folder_uri);
-
- e_account_list_save (accounts);
-
-exit:
- camel_url_free (url);
- g_free (uri);
- g_free (name);
- g_free (id);
-
- return TRUE;
-}
-
-static void
-change_sent_and_drafts_local_folders (EShellBackend *shell_backend)
-{
- EMailBackend *backend;
- EMailSession *session;
- EAccountList *accounts;
- EIterator *iter;
- const gchar *data_dir;
- gboolean changed = FALSE;
- CamelURL *url;
- gchar *tmp_uri, *drafts_uri, *sent_uri, *old_drafts_uri, *old_sent_uri;
-
- accounts = e_get_account_list ();
- if (!accounts)
- return;
-
- backend = E_MAIL_BACKEND (shell_backend);
- session = e_mail_backend_get_session (backend);
-
- data_dir = e_shell_backend_get_data_dir (shell_backend);
-
- tmp_uri = g_strconcat ("mbox:", data_dir, "/", "local", NULL);
- url = camel_url_new (tmp_uri, NULL);
- g_free (tmp_uri);
-
- g_return_if_fail (url != NULL);
-
- camel_url_set_fragment (url, "Drafts");
- drafts_uri = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
-
- camel_url_set_fragment (url, "Sent");
- sent_uri = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
-
- camel_url_free (url);
-
- tmp_uri = g_strconcat (
- "mbox:", g_get_home_dir (),
- "/.evolution/mail/local", NULL);
- url = camel_url_new (tmp_uri, NULL);
- g_free (tmp_uri);
-
- g_return_if_fail (url != NULL);
-
- camel_url_set_fragment (url, "Drafts");
- old_drafts_uri = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
-
- camel_url_set_fragment (url, "Sent");
- old_sent_uri = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
-
- camel_url_free (url);
-
- for (iter = e_list_get_iterator ((EList *) accounts);
- e_iterator_is_valid (iter); e_iterator_next (iter)) {
- EAccount *account = (EAccount *) e_iterator_get (iter);
- const gchar *uri;
-
- if (!account)
- continue;
-
- uri = e_account_get_string (account, E_ACCOUNT_DRAFTS_FOLDER_URI);
- if (g_strcmp0 (uri, drafts_uri) == 0 ||
- g_strcmp0 (uri, old_drafts_uri) == 0) {
- changed = TRUE;
- e_account_set_string (
- account, E_ACCOUNT_DRAFTS_FOLDER_URI,
- e_mail_session_get_local_folder_uri (
- session, E_MAIL_LOCAL_FOLDER_DRAFTS));
- }
-
- uri = e_account_get_string (account, E_ACCOUNT_SENT_FOLDER_URI);
- if (g_strcmp0 (uri, sent_uri) == 0 || g_strcmp0 (uri, old_sent_uri) == 0) {
- changed = TRUE;
- e_account_set_string (
- account, E_ACCOUNT_SENT_FOLDER_URI,
- e_mail_session_get_local_folder_uri (
- session, E_MAIL_LOCAL_FOLDER_SENT));
- }
- }
-
- g_object_unref (iter);
- g_free (old_drafts_uri);
- g_free (drafts_uri);
- g_free (old_sent_uri);
- g_free (sent_uri);
-
- if (changed)
- e_account_list_save (accounts);
-}
-
static void
em_rename_camel_url_params (CamelURL *url)
{
@@ -1079,45 +669,6 @@ em_rename_account_params (void)
e_account_list_save (account_list);
}
-static gboolean
-migrate_local_store (EShellBackend *shell_backend)
-{
- EMMigrateSession *session;
- const gchar *data_dir;
- gchar *local_store;
- gint response;
-
- if (!mbox_to_maildir_migration_needed (shell_backend))
- return TRUE;
-
- response = e_alert_run_dialog_for_args (
- e_shell_get_active_window (NULL),
- "mail:ask-migrate-store", NULL);
-
- if (response == GTK_RESPONSE_CANCEL)
- exit (EXIT_SUCCESS);
-
- rename_mbox_dir (shell_backend);
- data_dir = e_shell_backend_get_data_dir (shell_backend);
- local_store = g_build_filename (data_dir, "local", NULL);
-
- if (!g_file_test (local_store, G_FILE_TEST_EXISTS))
- g_mkdir_with_parents (local_store, 0700);
-
- session = em_migrate_session_new (data_dir);
- camel_session_set_online (CAMEL_SESSION (session), FALSE);
-
- migrate_mbox_to_maildir (shell_backend, session);
- create_mbox_account (shell_backend, session);
- change_sent_and_drafts_local_folders (shell_backend);
-
- g_object_unref (session);
-
- g_free (local_store);
-
- return TRUE;
-}
-
static void
em_ensure_proxy_ignore_hosts_being_list (void)
{
@@ -1310,9 +861,6 @@ e_mail_migrate (EShellBackend *shell_backend,
* match CamelSettings property names. */
em_rename_account_params ();
- if (!migrate_local_store (shell_backend))
- return FALSE;
-
if (major <= 2 || (major == 3 && minor < 4))
em_rename_folder_views (shell_backend);
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 9259d63..aa5b898 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -140,7 +140,8 @@ evolution_CPPFLAGS = \
$(CLUTTER_CFLAGS)
evolution_SOURCES = \
- main.c
+ main.c \
+ e-convert-local-mail.c
evolution_LDADD = \
libeshell.la \
diff --git a/shell/e-convert-local-mail.c b/shell/e-convert-local-mail.c
new file mode 100644
index 0000000..6b20c5e
--- /dev/null
+++ b/shell/e-convert-local-mail.c
@@ -0,0 +1,344 @@
+/*
+ * e-convert-local-mail.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include <config.h>
+
+#include <glib/gstdio.h>
+#include <camel/camel.h>
+
+#include <libedataserver/e-data-server-util.h>
+
+#include <shell/e-shell.h>
+#include <libemail-utils/e-account-utils.h>
+#include <libevolution-utils/e-alert-dialog.h>
+
+#define MBOX_UID "local_mbox"
+
+/* Forward Declarations */
+void e_convert_local_mail (EShell *shell);
+
+static gboolean
+mail_to_maildir_migration_needed (const gchar *mail_data_dir)
+{
+ gchar *local_store;
+ gchar *local_outbox;
+ gboolean migration_needed = FALSE;
+
+ local_store = g_build_filename (mail_data_dir, "local", NULL);
+ local_outbox = g_build_filename (local_store, ".Outbox", NULL);
+
+ /* If this is a fresh install (no local store exists yet)
+ * then obviously there's nothing to migrate to Maildir. */
+ if (!g_file_test (local_store, G_FILE_TEST_IS_DIR))
+ migration_needed = FALSE;
+
+ /* Look for a Maildir Outbox folder. */
+ else if (!g_file_test (local_outbox, G_FILE_TEST_IS_DIR))
+ migration_needed = TRUE;
+
+ g_free (local_store);
+ g_free (local_outbox);
+
+ return migration_needed;
+}
+
+/* Folder names with '.' are converted to '_' */
+static gchar *
+sanitize_maildir_folder_name (gchar *folder_name)
+{
+ gchar *maildir_folder_name;
+
+ maildir_folder_name = g_strdup (folder_name);
+ g_strdelimit (maildir_folder_name, ".", '_');
+
+ return maildir_folder_name;
+}
+
+static void
+copy_folder (CamelStore *mail_store,
+ CamelStore *maildir_store,
+ const gchar *mail_fname,
+ const gchar *maildir_fname)
+{
+ CamelFolder *fromfolder, *tofolder;
+ GPtrArray *uids;
+
+ fromfolder = camel_store_get_folder_sync (
+ mail_store, mail_fname, 0, NULL, NULL);
+ if (fromfolder == NULL) {
+ g_warning ("Cannot find mail folder %s \n", mail_fname);
+ return;
+ }
+
+ tofolder = camel_store_get_folder_sync (
+ maildir_store, maildir_fname,
+ CAMEL_STORE_FOLDER_CREATE, NULL, NULL);
+ if (tofolder == NULL) {
+ g_warning ("Cannot create maildir folder %s \n", maildir_fname);
+ g_object_unref (fromfolder);
+ return;
+ }
+
+ uids = camel_folder_get_uids (fromfolder);
+ camel_folder_transfer_messages_to_sync (
+ fromfolder, uids, tofolder, FALSE, NULL, NULL, NULL);
+ camel_folder_free_uids (fromfolder, uids);
+
+ g_object_unref (fromfolder);
+ g_object_unref (tofolder);
+}
+
+static void
+copy_folders (CamelStore *mail_store,
+ CamelStore *maildir_store,
+ CamelFolderInfo *fi,
+ CamelSession *session)
+{
+ if (fi) {
+ if (!g_str_has_prefix (fi->full_name, ".#evolution")) {
+ gchar *maildir_folder_name;
+
+ /* sanitize folder names and copy folders */
+ maildir_folder_name = sanitize_maildir_folder_name (fi->full_name);
+ copy_folder (
+ mail_store, maildir_store,
+ fi->full_name, maildir_folder_name);
+ g_free (maildir_folder_name);
+ }
+
+ if (fi->child)
+ copy_folders (mail_store, maildir_store, fi->child, session);
+
+ copy_folders (mail_store, maildir_store, fi->next, session);
+ }
+}
+
+struct MigrateStore {
+ CamelSession *session;
+ CamelStore *mail_store;
+ CamelStore *maildir_store;
+ gboolean complete;
+};
+
+static void
+migrate_stores (struct MigrateStore *ms)
+{
+ CamelFolderInfo *mail_fi;
+ CamelStore *mail_store = ms->mail_store;
+ CamelStore *maildir_store = ms->maildir_store;
+
+ mail_fi = camel_store_get_folder_info_sync (
+ mail_store, NULL,
+ CAMEL_STORE_FOLDER_INFO_RECURSIVE |
+ CAMEL_STORE_FOLDER_INFO_FAST |
+ CAMEL_STORE_FOLDER_INFO_SUBSCRIBED,
+ NULL, NULL);
+
+ /* FIXME progres dialog */
+ copy_folders (mail_store, maildir_store, mail_fi, ms->session);
+ ms->complete = TRUE;
+}
+
+static void
+rename_mbox_dir (const gchar *mail_data_dir)
+{
+ gchar *old_mail_dir;
+ gchar *new_mail_dir;
+ gboolean need_rename;
+
+ old_mail_dir = g_build_filename (mail_data_dir, "local", NULL);
+ new_mail_dir = g_build_filename (mail_data_dir, MBOX_UID, NULL);
+
+ /* Rename if old directory exists and new directory does not. */
+ need_rename =
+ g_file_test (old_mail_dir, G_FILE_TEST_EXISTS) &&
+ !g_file_test (new_mail_dir, G_FILE_TEST_EXISTS);
+
+ if (need_rename)
+ g_rename (old_mail_dir, new_mail_dir);
+
+ g_free (old_mail_dir);
+ g_free (new_mail_dir);
+}
+
+static gboolean
+migrate_mbox_to_maildir (CamelSession *session)
+{
+ CamelService *mbox_service;
+ CamelService *maildir_service;
+ CamelSettings *settings;
+ const gchar *data_dir;
+ gchar *path;
+ struct MigrateStore ms;
+ GError *error = NULL;
+
+ data_dir = camel_session_get_user_data_dir (session);
+
+ mbox_service = camel_session_add_service (
+ session, MBOX_UID, "mbox",
+ CAMEL_PROVIDER_STORE, &error);
+
+ if (error != NULL) {
+ g_warn_if_fail (mbox_service == NULL);
+ g_warning ("%s: %s", G_STRFUNC, error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ settings = camel_service_get_settings (mbox_service);
+ path = g_build_filename (data_dir, MBOX_UID, NULL);
+ g_object_set (settings, "path", path, NULL);
+ g_free (path);
+
+ maildir_service = camel_session_add_service (
+ session, "local", "maildir",
+ CAMEL_PROVIDER_STORE, &error);
+
+ if (error != NULL) {
+ g_warn_if_fail (maildir_service == NULL);
+ g_warning ("%s: %s", G_STRFUNC, error->message);
+ g_object_unref (mbox_service);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ settings = camel_service_get_settings (maildir_service);
+ path = g_build_filename (data_dir, "local", NULL);
+ g_object_set (settings, "path", path, NULL);
+ g_mkdir (path, 0700);
+ g_free (path);
+
+ ms.mail_store = CAMEL_STORE (mbox_service);
+ ms.maildir_store = CAMEL_STORE (maildir_service);
+ ms.session = session;
+ ms.complete = FALSE;
+
+ g_thread_create ((GThreadFunc) migrate_stores, &ms, TRUE, NULL);
+ while (!ms.complete)
+ g_main_context_iteration (NULL, TRUE);
+
+ return TRUE;
+}
+
+static gboolean
+create_mbox_account (CamelSession *session)
+{
+ CamelURL *url;
+ EAccountList *accounts;
+ EAccount *account;
+ const gchar *data_dir;
+ gchar *name, *id, *temp, *uri;
+
+ data_dir = camel_session_get_user_data_dir (session);
+
+ account = e_account_new ();
+ account->enabled = TRUE;
+
+ g_free (account->uid);
+ account->uid = g_strdup ("local_mbox");
+
+ url = camel_url_new ("mbox:", NULL);
+ temp = g_build_filename (data_dir, "local_mbox", NULL);
+ camel_url_set_path (url, temp);
+ g_free (temp);
+
+ uri = camel_url_to_string (url, 0);
+ e_account_set_string (account, E_ACCOUNT_SOURCE_URL, uri);
+
+#ifndef G_OS_WIN32
+ name = g_locale_to_utf8 (g_get_user_name (), -1, NULL, NULL, NULL);
+#else
+ name = g_strdup (g_get_user_name ());
+#endif
+
+ id = g_strconcat (name, "@", "localhost", NULL);
+ e_account_set_string (account, E_ACCOUNT_ID_NAME, name);
+ e_account_set_string (account, E_ACCOUNT_ID_ADDRESS, id);
+ e_account_set_string (account, E_ACCOUNT_NAME, "local_mbox");
+
+ accounts = e_get_account_list ();
+ if (e_account_list_find (accounts, E_ACCOUNT_ID_ADDRESS, id)) {
+ g_object_unref (account);
+ goto exit;
+ }
+
+ e_account_list_add (accounts, account);
+
+exit:
+ camel_url_free (url);
+ g_free (uri);
+ g_free (name);
+ g_free (id);
+
+ return TRUE;
+}
+
+void
+e_convert_local_mail (EShell *shell)
+{
+ CamelSession *session;
+ const gchar *user_data_dir;
+ const gchar *user_cache_dir;
+ gchar *mail_data_dir;
+ gchar *mail_cache_dir;
+ gchar *local_store;
+ gint response;
+
+ camel_provider_init ();
+
+ user_data_dir = e_get_user_data_dir ();
+ user_cache_dir = e_get_user_cache_dir ();
+
+ mail_data_dir = g_build_filename (user_data_dir, "mail", NULL);
+ mail_cache_dir = g_build_filename (user_cache_dir, "mail", NULL);
+
+ if (!mail_to_maildir_migration_needed (mail_data_dir))
+ goto exit;
+
+ response = e_alert_run_dialog_for_args (
+ e_shell_get_active_window (NULL),
+ "mail:ask-migrate-store", NULL);
+
+ if (response == GTK_RESPONSE_CANCEL)
+ exit (EXIT_SUCCESS);
+
+ rename_mbox_dir (mail_data_dir);
+
+ local_store = g_build_filename (mail_data_dir, "local", NULL);
+
+ if (!g_file_test (local_store, G_FILE_TEST_EXISTS))
+ g_mkdir_with_parents (local_store, 0700);
+
+ g_free (local_store);
+
+ session = g_object_new (
+ CAMEL_TYPE_SESSION,
+ "online", FALSE,
+ "user-data-dir", mail_data_dir,
+ "user-cache-dir", mail_cache_dir,
+ NULL);
+
+ migrate_mbox_to_maildir (session);
+ create_mbox_account (session);
+
+ g_object_unref (session);
+
+exit:
+ g_free (mail_data_dir);
+ g_free (mail_cache_dir);
+}
diff --git a/shell/main.c b/shell/main.c
index 4aa6425..f48bb50 100644
--- a/shell/main.c
+++ b/shell/main.c
@@ -118,6 +118,9 @@ static gchar *geometry = NULL;
static gchar *requested_view = NULL;
static gchar **remaining_args;
+/* Forward declarations */
+void e_convert_local_mail (EShell *shell);
+
static void
categories_icon_theme_hack (void)
{
@@ -651,6 +654,18 @@ main (gint argc,
goto exit;
}
+ /* This routine converts the local mail store from mbox format to
+ * Maildir format as needed. The reason the code is here and not
+ * in the mail module is because we inform the user at startup of
+ * the impending mail conversion by displaying a popup dialog and
+ * waiting for confirmation before proceeding.
+ *
+ * This has to be done before we load modules because some of the
+ * EShellBackends immediately add GMainContext sources that would
+ * otherwise get dispatched during gtk_dialog_run(), and we don't
+ * want them dispatched until after the conversion is complete. */
+ e_convert_local_mail (shell);
+
e_shell_load_modules (shell);
if (!disable_eplugin) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]