From 16e2beab9e4d412399f495f6165d27da80cb3675 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Thu, 7 May 2009 16:38:32 -0400 Subject: Adapt mail to EShellBackend changes. Again, builds but not tested. Lots of compiler warnings to clean up, but I don't have the energy for it. This was pretty grueling. --- addressbook/gui/component/e-book-shell-backend.c | 2 +- mail/Makefile.am | 12 +- mail/e-mail-browser.c | 59 +- mail/e-mail-browser.h | 4 +- mail/e-mail-reader-utils.c | 12 +- mail/e-mail-reader.c | 46 +- mail/e-mail-reader.h | 6 +- mail/e-mail-shell-backend.c | 1303 ++++++++++ mail/e-mail-shell-backend.h | 123 + mail/e-mail-shell-content.c | 16 +- mail/e-mail-shell-migrate.c | 2988 ++++++++++++++++++++++ mail/e-mail-shell-migrate.h | 38 + mail/e-mail-shell-module-migrate.c | 2988 ---------------------- mail/e-mail-shell-module-migrate.h | 38 - mail/e-mail-shell-module-settings.c | 521 ---- mail/e-mail-shell-module-settings.h | 33 - mail/e-mail-shell-module.c | 1166 --------- mail/e-mail-shell-module.h | 84 - mail/e-mail-shell-settings.c | 521 ++++ mail/e-mail-shell-settings.h | 33 + mail/e-mail-shell-sidebar.c | 14 +- mail/e-mail-shell-view-actions.c | 14 +- mail/e-mail-shell-view-private.c | 6 +- mail/e-mail-shell-view-private.h | 2 +- mail/e-mail-shell-view.c | 7 +- mail/em-account-editor.c | 24 +- mail/em-account-prefs.c | 14 +- mail/em-composer-prefs.c | 2 +- mail/em-composer-utils.c | 32 +- mail/em-filter-folder-element.c | 4 +- mail/em-folder-properties.c | 8 +- mail/em-folder-selection.c | 4 +- mail/em-folder-tree-model.c | 68 +- mail/em-folder-tree-model.h | 8 +- mail/em-folder-tree.c | 21 +- mail/em-folder-tree.h | 4 +- mail/em-folder-utils.c | 10 +- mail/em-folder-view.c | 4 +- mail/em-utils.c | 26 +- mail/em-vfolder-rule.c | 4 +- mail/importers/evolution-mbox-importer.c | 9 +- mail/importers/mail-importer.c | 9 +- mail/mail-autofilter.c | 17 +- mail/mail-config.c | 18 +- mail/mail-folder-cache.c | 67 +- mail/mail-folder-cache.h | 5 +- mail/mail-mt.c | 13 +- mail/mail-ops.c | 28 +- mail/mail-send-recv.c | 30 +- mail/mail-send-recv.h | 4 +- mail/mail-session.c | 14 +- mail/mail-session.h | 4 +- mail/mail-tools.c | 6 +- mail/mail-vfolder.c | 66 +- mail/message-list.c | 52 +- 55 files changed, 5425 insertions(+), 5186 deletions(-) create mode 100644 mail/e-mail-shell-backend.c create mode 100644 mail/e-mail-shell-backend.h create mode 100644 mail/e-mail-shell-migrate.c create mode 100644 mail/e-mail-shell-migrate.h delete mode 100644 mail/e-mail-shell-module-migrate.c delete mode 100644 mail/e-mail-shell-module-migrate.h delete mode 100644 mail/e-mail-shell-module-settings.c delete mode 100644 mail/e-mail-shell-module-settings.h delete mode 100644 mail/e-mail-shell-module.c delete mode 100644 mail/e-mail-shell-module.h create mode 100644 mail/e-mail-shell-settings.c create mode 100644 mail/e-mail-shell-settings.h diff --git a/addressbook/gui/component/e-book-shell-backend.c b/addressbook/gui/component/e-book-shell-backend.c index 0e2cddc85f..c8b3810b3e 100644 --- a/addressbook/gui/component/e-book-shell-backend.c +++ b/addressbook/gui/component/e-book-shell-backend.c @@ -547,8 +547,8 @@ e_book_shell_backend_get_source_list (EBookShellBackend *book_shell_backend) void e_module_load (GTypeModule *type_module) { - e_book_shell_view_get_type (type_module); e_book_shell_backend_get_type (type_module); + e_book_shell_view_get_type (type_module); } void diff --git a/mail/Makefile.am b/mail/Makefile.am index 5e8a7bc708..e290e4cb5d 100644 --- a/mail/Makefile.am +++ b/mail/Makefile.am @@ -57,14 +57,14 @@ libevolution_module_mail_la_SOURCES = \ e-mail-reader-utils.h \ e-mail-search-bar.c \ e-mail-search-bar.h \ - e-mail-shell-module.c \ - e-mail-shell-module.h \ - e-mail-shell-module-migrate.c \ - e-mail-shell-module-migrate.h \ - e-mail-shell-module-settings.c \ - e-mail-shell-module-settings.h \ + e-mail-shell-backend.c \ + e-mail-shell-backend.h \ e-mail-shell-content.c \ e-mail-shell-content.h \ + e-mail-shell-migrate.c \ + e-mail-shell-migrate.h \ + e-mail-shell-settings.c \ + e-mail-shell-settings.h \ e-mail-shell-sidebar.c \ e-mail-shell-sidebar.h \ e-mail-shell-view.c \ diff --git a/mail/e-mail-browser.c b/mail/e-mail-browser.c index 69ccc54f44..152821b32a 100644 --- a/mail/e-mail-browser.c +++ b/mail/e-mail-browser.c @@ -32,7 +32,7 @@ #include "mail/e-mail-reader.h" #include "mail/e-mail-reader-utils.h" #include "mail/e-mail-search-bar.h" -#include "mail/e-mail-shell-module.h" +#include "mail/e-mail-shell-backend.h" #include "mail/em-folder-tree-model.h" #include "mail/em-format-html-display.h" #include "mail/message-list.h" @@ -45,7 +45,7 @@ struct _EMailBrowserPrivate { GtkUIManager *ui_manager; - EShellModule *shell_module; + EShellBackend *shell_backend; GtkActionGroup *action_group; EMFormatHTMLDisplay *html_display; @@ -60,7 +60,7 @@ struct _EMailBrowserPrivate { enum { PROP_0, - PROP_SHELL_MODULE, + PROP_SHELL_BACKEND, PROP_SHOW_DELETED, PROP_UI_MANAGER }; @@ -240,12 +240,12 @@ mail_browser_status_message_cb (EMailBrowser *browser, } static void -mail_browser_set_shell_module (EMailBrowser *browser, - EShellModule *shell_module) +mail_browser_set_shell_backend (EMailBrowser *browser, + EShellBackend *shell_backend) { - g_return_if_fail (browser->priv->shell_module == NULL); + g_return_if_fail (browser->priv->shell_backend == NULL); - browser->priv->shell_module = g_object_ref (shell_module); + browser->priv->shell_backend = g_object_ref (shell_backend); } static void @@ -255,8 +255,8 @@ mail_browser_set_property (GObject *object, GParamSpec *pspec) { switch (property_id) { - case PROP_SHELL_MODULE: - mail_browser_set_shell_module ( + case PROP_SHELL_BACKEND: + mail_browser_set_shell_backend ( E_MAIL_BROWSER (object), g_value_get_object (value)); return; @@ -278,9 +278,9 @@ mail_browser_get_property (GObject *object, GParamSpec *pspec) { switch (property_id) { - case PROP_SHELL_MODULE: + case PROP_SHELL_BACKEND: g_value_set_object ( - value, e_mail_reader_get_shell_module ( + value, e_mail_reader_get_shell_backend ( E_MAIL_READER (object))); return; @@ -312,9 +312,9 @@ mail_browser_dispose (GObject *object) priv->ui_manager = NULL; } - if (priv->shell_module != NULL) { - g_object_unref (priv->shell_module); - priv->shell_module = NULL; + if (priv->shell_backend != NULL) { + g_object_unref (priv->shell_backend); + priv->shell_backend = NULL; } if (priv->action_group != NULL) { @@ -362,7 +362,7 @@ mail_browser_constructed (GObject *object) EMFormatHTMLDisplay *html_display; EMailBrowserPrivate *priv; EMailReader *reader; - EShellModule *shell_module; + EShellBackend *shell_backend; EShell *shell; GConfBridge *bridge; GtkAccelGroup *accel_group; @@ -382,9 +382,9 @@ mail_browser_constructed (GObject *object) domain = GETTEXT_PACKAGE; html_display = e_mail_reader_get_html_display (reader); - shell_module = e_mail_reader_get_shell_module (reader); + shell_backend = e_mail_reader_get_shell_backend (reader); - shell = e_shell_module_get_shell (shell_module); + shell = e_shell_backend_get_shell (shell_backend); e_shell_watch_window (shell, GTK_WINDOW (object)); html = EM_FORMAT_HTML (html_display)->html; @@ -392,7 +392,7 @@ mail_browser_constructed (GObject *object) /* The message list is a widget, but it is not shown in the browser. * Unfortunately, the widget is inseparable from its model, and the * model is all we need. */ - priv->message_list = message_list_new (shell_module); + priv->message_list = message_list_new (shell_backend); g_object_ref_sink (priv->message_list); g_signal_connect_swapped ( @@ -536,14 +536,14 @@ mail_browser_get_message_list (EMailReader *reader) return MESSAGE_LIST (priv->message_list); } -static EShellModule * -mail_browser_get_shell_module (EMailReader *reader) +static EShellBackend * +mail_browser_get_shell_backend (EMailReader *reader) { EMailBrowserPrivate *priv; priv = E_MAIL_BROWSER_GET_PRIVATE (reader); - return priv->shell_module; + return priv->shell_backend; } static GtkWindow * @@ -617,12 +617,12 @@ mail_browser_class_init (EMailBrowserClass *class) g_object_class_install_property ( object_class, - PROP_SHELL_MODULE, + PROP_SHELL_BACKEND, g_param_spec_object ( - "shell-module", + "shell-backend", _("Shell Module"), - _("The mail shell module"), - E_TYPE_SHELL_MODULE, + _("The mail shell backend"), + E_TYPE_SHELL_BACKEND, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); @@ -644,7 +644,7 @@ mail_browser_iface_init (EMailReaderIface *iface) iface->get_hide_deleted = mail_browser_get_hide_deleted; iface->get_html_display = mail_browser_get_html_display; iface->get_message_list = mail_browser_get_message_list; - iface->get_shell_module = mail_browser_get_shell_module; + iface->get_shell_backend = mail_browser_get_shell_backend; iface->get_window = mail_browser_get_window; iface->set_message = mail_browser_set_message; iface->show_search_bar = mail_browser_show_search_bar; @@ -705,13 +705,14 @@ e_mail_browser_get_type (void) } GtkWidget * -e_mail_browser_new (EShellModule *shell_module) +e_mail_browser_new (EMailShellBackend *mail_shell_backend) { - g_return_val_if_fail (E_IS_SHELL_MODULE (shell_module), NULL); + g_return_val_if_fail ( + E_IS_MAIL_SHELL_BACKEND (mail_shell_backend), NULL); return g_object_new ( E_TYPE_MAIL_BROWSER, - "shell-module", shell_module, NULL); + "shell-backend", mail_shell_backend, NULL); } void diff --git a/mail/e-mail-browser.h b/mail/e-mail-browser.h index bcc8870478..b67ea9a797 100644 --- a/mail/e-mail-browser.h +++ b/mail/e-mail-browser.h @@ -23,7 +23,7 @@ #define E_MAIL_BROWSER_H #include -#include +#include /* Standard GObject macros */ #define E_TYPE_MAIL_BROWSER \ @@ -60,7 +60,7 @@ struct _EMailBrowserClass { }; GType e_mail_browser_get_type (void); -GtkWidget * e_mail_browser_new (EShellModule *shell_module); +GtkWidget * e_mail_browser_new (EMailShellBackend *mail_shell_backend); void e_mail_browser_close (EMailBrowser *browser); gboolean e_mail_browser_get_show_deleted (EMailBrowser *browser); void e_mail_browser_set_show_deleted (EMailBrowser *browser, diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c index b0c3edff2d..3e069bac06 100644 --- a/mail/e-mail-reader-utils.c +++ b/mail/e-mail-reader-utils.c @@ -62,7 +62,7 @@ gboolean e_mail_reader_confirm_delete (EMailReader *reader) { EShell *shell; - EShellModule *shell_module; + EShellBackend *shell_backend; EShellSettings *shell_settings; MessageList *message_list; CamelFolder *folder; @@ -81,8 +81,8 @@ e_mail_reader_confirm_delete (EMailReader *reader) message_list = e_mail_reader_get_message_list (reader); window = e_mail_reader_get_window (reader); - shell_module = e_mail_reader_get_shell_module (reader); - shell = e_shell_module_get_shell (shell_module); + shell_backend = e_mail_reader_get_shell_backend (reader); + shell = e_shell_backend_get_shell (shell_backend); shell_settings = e_shell_get_shell_settings (shell); folder = message_list->folder; @@ -189,7 +189,7 @@ e_mail_reader_mark_selected (EMailReader *reader, guint e_mail_reader_open_selected (EMailReader *reader) { - EShellModule *shell_module; + EShellBackend *shell_backend; MessageList *message_list; CamelFolder *folder; GtkWindow *window; @@ -201,7 +201,7 @@ e_mail_reader_open_selected (EMailReader *reader) g_return_val_if_fail (E_IS_MAIL_READER (reader), 0); message_list = e_mail_reader_get_message_list (reader); - shell_module = e_mail_reader_get_shell_module (reader); + shell_backend = e_mail_reader_get_shell_backend (reader); window = e_mail_reader_get_window (reader); folder = message_list->folder; @@ -276,7 +276,7 @@ e_mail_reader_open_selected (EMailReader *reader) const gchar *uid = views->pdata[ii]; GtkWidget *browser; - browser = e_mail_browser_new (shell_module); + browser = e_mail_browser_new (shell_backend); e_mail_reader_set_folder ( E_MAIL_READER (browser), folder, folder_uri); e_mail_reader_set_message ( diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c index c5db73c4f9..c65feaae2d 100644 --- a/mail/e-mail-reader.c +++ b/mail/e-mail-reader.c @@ -39,7 +39,7 @@ #include "mail/e-mail-browser.h" #include "mail/e-mail-reader-utils.h" -#include "mail/e-mail-shell-module.h" +#include "mail/e-mail-shell-backend.h" #include "mail/em-composer-utils.h" #include "mail/em-event.h" #include "mail/em-folder-selector.h" @@ -146,7 +146,7 @@ static void action_mail_copy_cb (GtkAction *action, EMailReader *reader) { - EShellModule *shell_module; + EShellBackend *shell_backend; MessageList *message_list; EMFolderTreeModel *model; CamelFolder *folder; @@ -156,8 +156,8 @@ action_mail_copy_cb (GtkAction *action, const gchar *uri; message_list = e_mail_reader_get_message_list (reader); - shell_module = e_mail_reader_get_shell_module (reader); - model = e_mail_shell_module_get_folder_tree_model (shell_module); + shell_backend = e_mail_reader_get_shell_backend (reader); + model = e_mail_shell_backend_get_folder_tree_model (shell_backend); folder_tree = em_folder_tree_new_with_model (model); selected = message_list_get_selected (message_list); @@ -566,7 +566,7 @@ static void action_mail_move_cb (GtkAction *action, EMailReader *reader) { - EShellModule *shell_module; + EShellBackend *shell_backend; MessageList *message_list; EMFolderTreeModel *model; CamelFolder *folder; @@ -576,8 +576,8 @@ action_mail_move_cb (GtkAction *action, const gchar *uri; message_list = e_mail_reader_get_message_list (reader); - shell_module = e_mail_reader_get_shell_module (reader); - model = e_mail_shell_module_get_folder_tree_model (shell_module); + shell_backend = e_mail_reader_get_shell_backend (reader); + model = e_mail_shell_backend_get_folder_tree_model (shell_backend); folder_tree = em_folder_tree_new_with_model (model); selected = message_list_get_selected (message_list); @@ -900,7 +900,7 @@ action_mail_show_source_cb (GtkAction *action, EMailReader *reader) { EMFormatHTMLDisplay *html_display; - EShellModule *shell_module; + EShellBackend *shell_backend; MessageList *message_list; CamelFolder *folder; GtkWidget *browser; @@ -908,14 +908,14 @@ action_mail_show_source_cb (GtkAction *action, const gchar *folder_uri; message_list = e_mail_reader_get_message_list (reader); - shell_module = e_mail_reader_get_shell_module (reader); + shell_backend = e_mail_reader_get_shell_backend (reader); folder = message_list->folder; folder_uri = message_list->folder_uri; uids = message_list_get_selected (message_list); g_return_if_fail (uids->len > 0); - browser = e_mail_browser_new (shell_module); + browser = e_mail_browser_new (shell_backend); reader = E_MAIL_READER (browser); html_display = e_mail_reader_get_html_display (reader); em_format_set_mode (EM_FORMAT (html_display), EM_FORMAT_SOURCE); @@ -1767,7 +1767,7 @@ mail_reader_message_loaded_cb (CamelFolder *folder, EMailReader *reader = user_data; EMFormatHTMLDisplay *html_display; MessageList *message_list; - EShellModule *shell_module; + EShellBackend *shell_backend; EShellSettings *shell_settings; EShell *shell; EMEvent *event; @@ -1778,8 +1778,8 @@ mail_reader_message_loaded_cb (CamelFolder *folder, html_display = e_mail_reader_get_html_display (reader); message_list = e_mail_reader_get_message_list (reader); - shell_module = e_mail_reader_get_shell_module (reader); - shell = e_shell_module_get_shell (shell_module); + shell_backend = e_mail_reader_get_shell_backend (reader); + shell = e_shell_backend_get_shell (shell_backend); shell_settings = e_shell_get_shell_settings (shell); /* If the user picked a different message in the time it took @@ -2039,7 +2039,7 @@ void e_mail_reader_init (EMailReader *reader) { EShell *shell; - EShellModule *shell_module; + EShellBackend *shell_backend; EShellSettings *shell_settings; EMFormatHTMLDisplay *html_display; GtkActionGroup *action_group; @@ -2055,9 +2055,9 @@ e_mail_reader_init (EMailReader *reader) action_group = e_mail_reader_get_action_group (reader); html_display = e_mail_reader_get_html_display (reader); message_list = e_mail_reader_get_message_list (reader); - shell_module = e_mail_reader_get_shell_module (reader); + shell_backend = e_mail_reader_get_shell_backend (reader); - shell = e_shell_module_get_shell (shell_module); + shell = e_shell_backend_get_shell (shell_backend); shell_settings = e_shell_get_shell_settings (shell); html = EM_FORMAT_HTML (html_display)->html; @@ -2343,7 +2343,7 @@ void e_mail_reader_update_actions (EMailReader *reader) { EShell *shell; - EShellModule *shell_module; + EShellBackend *shell_backend; EShellSettings *shell_settings; GtkAction *action; GtkActionGroup *action_group; @@ -2374,8 +2374,8 @@ e_mail_reader_update_actions (EMailReader *reader) action_group = e_mail_reader_get_action_group (reader); state = e_mail_reader_check_state (reader); - shell_module = e_mail_reader_get_shell_module (reader); - shell = e_shell_module_get_shell (shell_module); + shell_backend = e_mail_reader_get_shell_backend (reader); + shell = e_shell_backend_get_shell (shell_backend); shell_settings = e_shell_get_shell_settings (shell); disable_printing = e_shell_settings_get_boolean ( @@ -2673,17 +2673,17 @@ e_mail_reader_get_message_list (EMailReader *reader) return iface->get_message_list (reader); } -EShellModule * -e_mail_reader_get_shell_module (EMailReader *reader) +EShellBackend * +e_mail_reader_get_shell_backend (EMailReader *reader) { EMailReaderIface *iface; g_return_val_if_fail (E_IS_MAIL_READER (reader), NULL); iface = E_MAIL_READER_GET_IFACE (reader); - g_return_val_if_fail (iface->get_shell_module != NULL, NULL); + g_return_val_if_fail (iface->get_shell_backend != NULL, NULL); - return iface->get_shell_module (reader); + return iface->get_shell_backend (reader); } GtkWindow * diff --git a/mail/e-mail-reader.h b/mail/e-mail-reader.h index 6499eaf07b..13a9ba8080 100644 --- a/mail/e-mail-reader.h +++ b/mail/e-mail-reader.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include /* Standard GObject macros */ #define E_TYPE_MAIL_READER \ @@ -86,7 +86,7 @@ struct _EMailReaderIface { EMFormatHTMLDisplay * (*get_html_display) (EMailReader *reader); MessageList * (*get_message_list) (EMailReader *reader); - EShellModule * (*get_shell_module) (EMailReader *reader); + EShellBackend * (*get_shell_backend) (EMailReader *reader); GtkWindow * (*get_window) (EMailReader *reader); void (*set_folder) (EMailReader *reader, @@ -113,7 +113,7 @@ gboolean e_mail_reader_get_hide_deleted (EMailReader *reader); EMFormatHTMLDisplay * e_mail_reader_get_html_display (EMailReader *reader); MessageList * e_mail_reader_get_message_list (EMailReader *reader); -EShellModule * e_mail_reader_get_shell_module (EMailReader *reader); +EShellBackend * e_mail_reader_get_shell_backend (EMailReader *reader); GtkWindow * e_mail_reader_get_window (EMailReader *reader); void e_mail_reader_set_folder (EMailReader *reader, CamelFolder *folder, diff --git a/mail/e-mail-shell-backend.c b/mail/e-mail-shell-backend.c new file mode 100644 index 0000000000..56f7422f5c --- /dev/null +++ b/mail/e-mail-shell-backend.c @@ -0,0 +1,1303 @@ +/* + * e-mail-shell-backend.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 + * + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "e-mail-shell-backend.h" + +#include +#include +#include +#include +#include + +#include "e-util/e-account-utils.h" +#include "e-util/e-binding.h" +#include "e-util/e-import.h" +#include "e-util/e-util.h" +#include "shell/e-shell.h" +#include "shell/e-shell-window.h" +#include "composer/e-msg-composer.h" +#include "widgets/misc/e-preferences-window.h" + +#include "e-mail-shell-migrate.h" +#include "e-mail-shell-settings.h" +#include "e-mail-shell-view.h" + +#include "e-attachment-handler-mail.h" +#include "e-mail-browser.h" +#include "e-mail-reader.h" +#include "em-account-prefs.h" +#include "em-composer-prefs.h" +#include "em-composer-utils.h" +#include "em-config.h" +#include "em-event.h" +#include "em-folder-tree-model.h" +#include "em-folder-utils.h" +#include "em-format-hook.h" +#include "em-format-html-display.h" +#include "em-junk-hook.h" +#include "em-mailer-prefs.h" +#include "em-network-prefs.h" +#include "em-utils.h" +#include "mail-config.h" +#include "mail-folder-cache.h" +#include "mail-mt.h" +#include "mail-ops.h" +#include "mail-send-recv.h" +#include "mail-session.h" +#include "mail-vfolder.h" +#include "importers/mail-importer.h" + +#define E_MAIL_SHELL_BACKEND_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_MAIL_SHELL_BACKEND, EMailShellBackendPrivate)) + +#define BACKEND_NAME "mail" + +typedef struct _StoreInfo StoreInfo; + +/* XXX Temporary */ +CamelStore *vfolder_store; + +struct _StoreInfo { + CamelStore *store; + gint ref_count; + gchar *name; + + /* Keep a reference to these so they remain around for the session. */ + CamelFolder *vtrash; + CamelFolder *vjunk; + + /* Initialization callback. */ + void (*done) (CamelStore *store, + CamelFolderInfo *info, + gpointer user_data); + gpointer done_user_data; + + guint removed : 1; +}; + +struct _EMailShellBackendPrivate { + GHashTable *store_hash; + MailAsyncEvent *async_event; + EMFolderTreeModel *folder_tree_model; + CamelStore *local_store; + + gint mail_sync_in_progress; + guint mail_sync_timeout_source_id; +}; + +/* Module Entry Points */ +void e_module_load (GTypeModule *type_module); +void e_module_unload (GTypeModule *type_module); + +GType e_mail_shell_backend_type = 0; +static gpointer parent_class; + +/* The array elements correspond to EMailFolderType. */ +static struct { + gchar *name; + gchar *uri; + CamelFolder *folder; +} default_local_folders[] = { + { N_("Inbox") }, + { N_("Drafts") }, + { N_("Outbox") }, + { N_("Sent") }, + { N_("Templates") }, + { "Inbox" } /* "always local" inbox */ +}; + +/* XXX So many things need the shell backend that it's + * just easier for now to make it globally available. + * We should fix this, though. */ +EMailShellBackend *global_mail_shell_backend = NULL; + +extern gint camel_application_is_exiting; + +static StoreInfo * +store_info_new (CamelStore *store, + const gchar *name) +{ + CamelService *service; + StoreInfo *si; + + g_return_val_if_fail (CAMEL_IS_STORE (store), NULL); + + service = CAMEL_SERVICE (store); + + si = g_slice_new0 (StoreInfo); + si->ref_count = 1; + + if (name == NULL) + si->name = camel_service_get_name (service, TRUE); + else + si->name = g_strdup (name); + + si->store = store; + camel_object_ref (store); + + /* If these are vfolders then they need to be opened now, + * otherwise they won't keep track of all folders. */ + if (store->flags & CAMEL_STORE_VTRASH) + si->vtrash = camel_store_get_trash (store, NULL); + if (store->flags & CAMEL_STORE_VJUNK) + si->vjunk = camel_store_get_junk (store, NULL); + + return si; +} + +static StoreInfo * +store_info_ref (StoreInfo *si) +{ + g_return_val_if_fail (si != NULL, si); + g_return_val_if_fail (si->ref_count > 0, si); + + g_atomic_int_add (&si->ref_count, 1); + + return si; +} + +static void +store_info_unref (StoreInfo *si) +{ + g_return_if_fail (si != NULL); + g_return_if_fail (si->ref_count > 0); + + if (g_atomic_int_exchange_and_add (&si->ref_count, -1) > 1) + return; + + if (si->vtrash != NULL) + camel_object_unref (si->vtrash); + if (si->vjunk != NULL) + camel_object_unref (si->vjunk); + camel_object_unref (si->store); + g_free (si->name); + + g_slice_free (StoreInfo, si); +} + +static void +store_hash_free (StoreInfo *si) +{ + si->removed = 1; + store_info_unref (si); +} + +static gboolean +mail_shell_backend_add_store_done (CamelStore *store, + CamelFolderInfo *info, + gpointer user_data) +{ + StoreInfo *si = user_data; + + if (si->done != NULL) + si->done (store, info, si); + + if (!si->removed) { + /* Let the counters know about the already-opened + * junk and trash folders. */ + if (si->vtrash != NULL) + mail_note_folder (si->vtrash); + if (si->vjunk != NULL) + mail_note_folder (si->vjunk); + } + + store_info_unref (si); + + return TRUE; +} + +static void +mail_shell_backend_add_store (EMailShellBackend *mail_shell_backend, + CamelStore *store, + const gchar *name, + void (*done) (CamelStore *store, + CamelFolderInfo *info, + gpointer user_data)) +{ + EMFolderTreeModel *folder_tree_model; + GHashTable *store_hash; + StoreInfo *si; + + store_hash = mail_shell_backend->priv->store_hash; + folder_tree_model = mail_shell_backend->priv->folder_tree_model; + + si = store_info_new (store, name); + si->done = done; + g_hash_table_insert (store_hash, store, si); + + em_folder_tree_model_add_store (folder_tree_model, store, si->name); + + mail_note_store ( + mail_shell_backend, store, NULL, + mail_shell_backend_add_store_done, store_info_ref (si)); +} + +static void +mail_shell_backend_add_local_store_done (CamelStore *store, + CamelFolderInfo *info, + gpointer unused) +{ + gint ii; + + for (ii = 0; ii < G_N_ELEMENTS (default_local_folders); ii++) { + if (default_local_folders[ii].folder != NULL) + mail_note_folder (default_local_folders[ii].folder); + } +} + +static void +mail_shell_backend_add_local_store (EMailShellBackend *mail_shell_backend, + CamelStore *local_store, + const gchar *name) +{ + mail_shell_backend_add_store ( + mail_shell_backend, local_store, name, + mail_shell_backend_add_local_store_done); +} + +static void +mail_shell_backend_init_hooks (void) +{ + e_plugin_hook_register_type (em_config_hook_get_type ()); + e_plugin_hook_register_type (em_event_hook_get_type ()); + e_plugin_hook_register_type (em_junk_hook_get_type ()); + + /* EMFormat classes must be registered before EMFormatHook. */ + em_format_hook_register_type (em_format_get_type ()); + em_format_hook_register_type (em_format_html_get_type ()); + em_format_hook_register_type (em_format_html_display_get_type ()); + e_plugin_hook_register_type (em_format_hook_get_type ()); + + em_junk_hook_register_type (emj_get_type ()); +} + +static void +mail_shell_backend_init_importers (void) +{ + EImportClass *import_class; + EImportImporter *importer; + + import_class = g_type_class_ref (e_import_get_type ()); + + importer = mbox_importer_peek (); + e_import_class_add_importer (import_class, importer, NULL, NULL); + + importer = elm_importer_peek (); + e_import_class_add_importer (import_class, importer, NULL, NULL); + + importer = pine_importer_peek (); + e_import_class_add_importer (import_class, importer, NULL, NULL); +} + +static void +mail_shell_backend_init_local_store (EShellBackend *shell_backend) +{ + EMailShellBackendPrivate *priv; + CamelException ex; + CamelService *service; + CamelURL *url; + MailAsyncEvent *async_event; + const gchar *data_dir; + gchar *temp; + gint ii; + + priv = E_MAIL_SHELL_BACKEND_GET_PRIVATE (shell_backend); + + camel_exception_init (&ex); + + async_event = priv->async_event; + data_dir = e_shell_backend_get_data_dir (shell_backend); + + url = camel_url_new ("mbox:", NULL); + temp = g_build_filename (data_dir, "local", NULL); + camel_url_set_path (url, temp); + g_free (temp); + + temp = camel_url_to_string (url, 0); + service = camel_session_get_service ( + session, temp, CAMEL_PROVIDER_STORE, &ex); + g_free (temp); + + if (service == NULL) + goto fail; + + for (ii = 0; ii < G_N_ELEMENTS (default_local_folders); ii++) { + /* FIXME Should this URI be account relative? */ + camel_url_set_fragment (url, default_local_folders[ii].name); + default_local_folders[ii].uri = camel_url_to_string (url, 0); + default_local_folders[ii].folder = camel_store_get_folder ( + CAMEL_STORE (service), default_local_folders[ii].name, + CAMEL_STORE_FOLDER_CREATE, &ex); + camel_exception_clear (&ex); + } + + camel_url_free (url); + + camel_object_ref (service); + g_object_ref (shell_backend); + + mail_async_event_emit ( + async_event, MAIL_ASYNC_GUI, + (MailAsyncFunc) mail_shell_backend_add_local_store, + shell_backend, service, _("On This Computer")); + + priv->local_store = CAMEL_STORE (service); + + return; + +fail: + g_warning ("Could not initialize local store/folder: %s", ex.desc); + + camel_exception_clear (&ex); + camel_url_free (url); +} + +static void +mail_shell_backend_load_accounts (EShellBackend *shell_backend) +{ + EAccountList *account_list; + EIterator *iter; + + account_list = e_get_account_list (); + + for (iter = e_list_get_iterator ((EList *) account_list); + e_iterator_is_valid (iter); e_iterator_next (iter)) { + + EAccountService *service; + EAccount *account; + const gchar *name; + const gchar *url; + + account = (EAccount *) e_iterator_get (iter); + service = account->source; + name = account->name; + url = service->url; + + if (!account->enabled) + continue; + + if (url == NULL || *url == '\0') + continue; + + /* HACK: mbox URL's are handled by the local store setup + * above. Any that come through as account sources + * are really movemail sources! */ + if (g_str_has_prefix (url, "mbox:")) + continue; + + e_mail_shell_backend_load_store_by_uri ( + E_MAIL_SHELL_BACKEND (shell_backend), url, name); + } + + g_object_unref (iter); +} + +static void +mail_shell_backend_mail_icon_cb (EShellWindow *shell_window, + const gchar *icon_name) +{ + GtkAction *action; + + action = e_shell_window_get_shell_view_action ( + shell_window, BACKEND_NAME); + g_object_set (action, "icon-name", icon_name, NULL); +} + +static void +action_mail_folder_new_cb (GtkAction *action, + EShellWindow *shell_window) +{ + EMFolderTree *folder_tree = NULL; + EMailShellSidebar *mail_shell_sidebar; + EShellSidebar *shell_sidebar; + EShellView *shell_view; + const gchar *view_name; + + /* Take care not to unnecessarily load the mail shell view. */ + view_name = e_shell_window_get_active_view (shell_window); + if (g_strcmp0 (view_name, BACKEND_NAME) != 0) + goto exit; + + shell_view = e_shell_window_get_shell_view (shell_window, view_name); + shell_sidebar = e_shell_view_get_shell_sidebar (shell_view); + + mail_shell_sidebar = E_MAIL_SHELL_SIDEBAR (shell_sidebar); + folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar); + +exit: + em_folder_utils_create_folder ( + NULL, folder_tree, GTK_WINDOW (shell_window)); +} + +static void +action_mail_message_new_cb (GtkAction *action, + EShellWindow *shell_window) +{ + GtkWindow *window = GTK_WINDOW (shell_window); + EMailShellSidebar *mail_shell_sidebar; + EShellSidebar *shell_sidebar; + EShellView *shell_view; + EMFolderTree *folder_tree; + const gchar *view_name; + gchar *uri = NULL; + + if (!em_utils_check_user_can_send_mail (window)) + return; + + /* Take care not to unnecessarily load the mail shell view. */ + view_name = e_shell_window_get_active_view (shell_window); + if (g_strcmp0 (view_name, BACKEND_NAME) != 0) + goto exit; + + shell_view = e_shell_window_get_shell_view (shell_window, view_name); + shell_sidebar = e_shell_view_get_shell_sidebar (shell_view); + + mail_shell_sidebar = E_MAIL_SHELL_SIDEBAR (shell_sidebar); + folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar); + uri = em_folder_tree_get_selected_uri (folder_tree); + +exit: + em_utils_compose_new_message (uri); + + g_free (uri); +} + +static GtkActionEntry item_entries[] = { + + { "mail-message-new", + "mail-message-new", + NC_("New", "_Mail Message"), + "m", + N_("Compose a new mail message"), + G_CALLBACK (action_mail_message_new_cb) } +}; + +static GtkActionEntry source_entries[] = { + + { "mail-folder-new", + "folder-new", + NC_("New", "Mail _Folder"), + NULL, + N_("Create a new mail folder"), + G_CALLBACK (action_mail_folder_new_cb) } +}; + +static void +mail_shell_backend_init_preferences (EShell *shell) +{ + GtkWidget *preferences_window; + + preferences_window = e_shell_get_preferences_window (shell); + + e_preferences_window_add_page ( + E_PREFERENCES_WINDOW (preferences_window), + "mail-accounts", + "preferences-mail-accounts", + _("Mail Accounts"), + em_account_prefs_new (), + 100); + + e_preferences_window_add_page ( + E_PREFERENCES_WINDOW (preferences_window), + "mail", + "preferences-mail", + _("Mail Preferences"), + em_mailer_prefs_new (shell), + 300); + + e_preferences_window_add_page ( + E_PREFERENCES_WINDOW (preferences_window), + "composer", + "preferences-composer", + _("Composer Preferences"), + em_composer_prefs_new (shell), + 400); + + e_preferences_window_add_page ( + E_PREFERENCES_WINDOW (preferences_window), + "system-network-proxy", + "preferences-system-network-proxy", + _("Network Preferences"), + em_network_prefs_new (), + 500); +} + +static void +mail_shell_backend_sync_store_done_cb (CamelStore *store, + gpointer user_data) +{ + EMailShellBackend *mail_shell_backend = user_data; + + mail_shell_backend->priv->mail_sync_in_progress--; +} + +static void +mail_shell_backend_sync_store_cb (CamelStore *store, + EMailShellBackend *mail_shell_backend) +{ + if (!camel_application_is_exiting) { + mail_shell_backend->priv->mail_sync_in_progress++; + mail_sync_store ( + store, FALSE, + mail_shell_backend_sync_store_done_cb, + mail_shell_backend); + } +} + +static gboolean +mail_shell_backend_mail_sync (EMailShellBackend *mail_shell_backend) +{ + if (camel_application_is_exiting) + return FALSE; + + if (mail_shell_backend->priv->mail_sync_in_progress) + goto exit; + + if (session == NULL || !camel_session_is_online (session)) + goto exit; + + e_mail_shell_backend_stores_foreach ( + mail_shell_backend, (GHFunc) + mail_shell_backend_sync_store_cb, + mail_shell_backend); + +exit: + return !camel_application_is_exiting; +} + +static void +mail_shell_backend_notify_online_cb (EShell *shell, + GParamSpec *pspec, + EShellBackend *shell_backend) +{ + gboolean online; + + online = e_shell_get_online (shell); + camel_session_set_online (session, online); +} + +static void +mail_shell_backend_handle_email_uri_cb (gchar *folder_uri, + CamelFolder *folder, + gpointer user_data) +{ + EMailShellBackend *mail_shell_backend = user_data; + CamelURL *url = user_data; + const gchar *forward; + const gchar *reply; + const gchar *uid; + + if (folder == NULL) { + g_warning ("Could not open folder '%s'", folder_uri); + goto exit; + } + + forward = camel_url_get_param (url, "forward"); + reply = camel_url_get_param (url, "reply"); + uid = camel_url_get_param (url, "uid"); + + if (reply != NULL) { + gint mode; + + if (g_strcmp0 (reply, "all") == 0) + mode = REPLY_MODE_ALL; + else if (g_strcmp0 (reply, "list") == 0) + mode = REPLY_MODE_LIST; + else + mode = REPLY_MODE_SENDER; + + em_utils_reply_to_message (folder, uid, NULL, mode, NULL); + + } else if (forward != NULL) { + GPtrArray *uids; + + uids = g_ptr_array_new (); + g_ptr_array_add (uids, g_strdup (uid)); + + if (g_strcmp0 (forward, "attached") == 0) + em_utils_forward_attached (folder, uids, folder_uri); + else if (g_strcmp0 (forward, "inline") == 0) + em_utils_forward_inline (folder, uids, folder_uri); + else if (g_strcmp0 (forward, "quoted") == 0) + em_utils_forward_quoted (folder, uids, folder_uri); + else + em_utils_forward_messages (folder, uids, folder_uri); + + } else { + GtkWidget *browser; + + /* FIXME Should pass in the shell module. */ + browser = e_mail_browser_new (mail_shell_backend); + e_mail_reader_set_folder ( + E_MAIL_READER (browser), folder, folder_uri); + e_mail_reader_set_message ( + E_MAIL_READER (browser), uid, FALSE); + gtk_widget_show (browser); + } + +exit: + camel_url_free (url); +} + +static gboolean +mail_shell_backend_handle_uri_cb (EShell *shell, + const gchar *uri, + EMailShellBackend *mail_shell_backend) +{ + gboolean handled = TRUE; + + if (g_str_has_prefix (uri, "mailto:")) { + if (em_utils_check_user_can_send_mail (NULL)) + em_utils_compose_new_message_with_mailto (uri, NULL); + + } else if (g_str_has_prefix (uri, "email:")) { + CamelURL *url; + + url = camel_url_new (uri, NULL); + if (camel_url_get_param (url, "uid") != NULL) { + gchar *curi = em_uri_to_camel (uri); + + mail_get_folder ( + curi, 0, + mail_shell_backend_handle_email_uri_cb, + mail_shell_backend, mail_msg_unordered_push); + g_free (curi); + + } else { + g_warning ("Email URI's must include a uid parameter"); + camel_url_free (url); + } + } else + handled = FALSE; + + return TRUE; +} + +/* Helper for mail_shell_backend_prepare_for_[off|on]line_cb() */ +static void +mail_shell_store_line_transition_done_cb (CamelStore *store, + gpointer user_data) +{ + EActivity *activity = user_data; + + g_object_unref (activity); +} + +/* Helper for mail_shell_backend_prepare_for_offline_cb() */ +static void +mail_shell_store_prepare_for_offline_cb (CamelService *service, + gpointer unused, + EActivity *activity) +{ + if (CAMEL_IS_DISCO_STORE (service) || CAMEL_IS_OFFLINE_STORE (service)) + mail_store_set_offline ( + CAMEL_STORE (service), TRUE, + mail_shell_store_line_transition_done_cb, + g_object_ref (activity)); +} + +static void +mail_shell_backend_prepare_for_offline_cb (EShell *shell, + EActivity *activity, + EMailShellBackend *mail_shell_backend) +{ + GList *watched_windows; + GtkWidget *parent = NULL; + gboolean synchronize = FALSE; + + watched_windows = e_shell_get_watched_windows (shell); + if (watched_windows != NULL) + parent = GTK_WIDGET (watched_windows->data); + + if (e_shell_get_network_available (shell)) + synchronize = em_utils_prompt_user ( + GTK_WINDOW (parent), + "/apps/evolution/mail/prompts/quick_offline", + "mail:ask-quick-offline", NULL); + + if (!synchronize) { + mail_cancel_all (); + camel_session_set_network_state (session, FALSE); + } + + e_mail_shell_backend_stores_foreach ( + mail_shell_backend, (GHFunc) + mail_shell_store_prepare_for_offline_cb, activity); +} + +/* Helper for mail_shell_backend_prepare_for_online_cb() */ +static void +mail_shell_store_prepare_for_online_cb (CamelService *service, + gpointer unused, + EActivity *activity) +{ + if (CAMEL_IS_DISCO_STORE (service) || CAMEL_IS_OFFLINE_STORE (service)) + mail_store_set_offline ( + CAMEL_STORE (service), FALSE, + mail_shell_store_line_transition_done_cb, + g_object_ref (activity)); +} + +static void +mail_shell_backend_prepare_for_online_cb (EShell *shell, + EActivity *activity, + EMailShellBackend *mail_shell_backend) +{ + camel_session_set_online (session, TRUE); + + e_mail_shell_backend_stores_foreach ( + mail_shell_backend, (GHFunc) + mail_shell_store_prepare_for_online_cb, activity); +} + +static void +mail_shell_backend_send_receive_cb (EShell *shell, + GtkWindow *parent, + EShellBackend *shell_backend) +{ + em_utils_clear_get_password_canceled_accounts_flag (); + mail_send_receive (parent); +} + +static void +mail_shell_backend_window_weak_notify_cb (EShell *shell, + GObject *where_the_object_was) +{ + g_signal_handlers_disconnect_by_func ( + shell, mail_shell_backend_mail_icon_cb, + where_the_object_was); +} + +static void +mail_shell_backend_window_created_cb (EShell *shell, + GtkWindow *window, + EShellBackend *shell_backend) +{ + EShellSettings *shell_settings; + static gboolean first_time = TRUE; + const gchar *backend_name; + + shell_settings = e_shell_get_shell_settings (shell); + + /* This applies to both the composer and signature editor. */ + if (GTKHTML_IS_EDITOR (window)) { + GList *spell_languages; + + e_binding_new ( + G_OBJECT (shell_settings), "composer-inline-spelling", + G_OBJECT (window), "inline-spelling"); + + e_binding_new ( + G_OBJECT (shell_settings), "composer-magic-links", + G_OBJECT (window), "magic-links"); + + e_binding_new ( + G_OBJECT (shell_settings), "composer-magic-smileys", + G_OBJECT (window), "magic-smileys"); + + spell_languages = e_load_spell_languages (); + gtkhtml_editor_set_spell_languages ( + GTKHTML_EDITOR (window), spell_languages); + g_list_free (spell_languages); + } + + if (E_IS_MSG_COMPOSER (window)) { + /* Integrate the new composer into the mail module. */ + em_configure_new_composer (E_MSG_COMPOSER (window)); + return; + } + + if (!E_IS_SHELL_WINDOW (window)) + return; + + backend_name = G_TYPE_MODULE (shell_backend)->name; + + e_shell_window_register_new_item_actions ( + E_SHELL_WINDOW (window), backend_name, + item_entries, G_N_ELEMENTS (item_entries)); + + e_shell_window_register_new_source_actions ( + E_SHELL_WINDOW (window), backend_name, + source_entries, G_N_ELEMENTS (source_entries)); + + g_signal_connect_swapped ( + shell, "event::mail-icon", + G_CALLBACK (mail_shell_backend_mail_icon_cb), window); + + g_object_weak_ref ( + G_OBJECT (window), (GWeakNotify) + mail_shell_backend_window_weak_notify_cb, shell); + + if (first_time) { + g_signal_connect ( + window, "map-event", + G_CALLBACK (e_msg_composer_check_autosave), NULL); + first_time = FALSE; + } +} + +static void +mail_shell_backend_dispose (GObject *object) +{ + EMailShellBackendPrivate *priv; + + priv = E_MAIL_SHELL_BACKEND_GET_PRIVATE (object); + + g_hash_table_remove_all (priv->store_hash); + + if (priv->folder_tree_model != NULL) { + g_object_unref (priv->folder_tree_model); + priv->folder_tree_model = NULL; + } + + if (priv->local_store != NULL) { + camel_object_unref (priv->local_store); + priv->local_store = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +mail_shell_backend_finalize (GObject *object) +{ + EMailShellBackendPrivate *priv; + + priv = E_MAIL_SHELL_BACKEND_GET_PRIVATE (object); + + g_hash_table_destroy (priv->store_hash); + mail_async_event_destroy (priv->async_event); + + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static void +mail_shell_backend_constructed (GObject *object) +{ + EMailShellBackendPrivate *priv; + EShell *shell; + EShellBackend *shell_backend; + + priv = E_MAIL_SHELL_BACKEND_GET_PRIVATE (object); + + shell_backend = E_SHELL_BACKEND (object); + shell = e_shell_backend_get_shell (shell_backend); + + /* This also initializes Camel, so it needs to happen early. */ + mail_session_init (E_MAIL_SHELL_BACKEND (shell_backend)); + + mail_shell_backend_init_hooks (); + mail_shell_backend_init_importers (); + + e_attachment_handler_mail_get_type (); + + /* XXX This never gets unreffed. */ + global_mail_shell_backend = g_object_ref (shell_backend); + + priv->store_hash = g_hash_table_new_full ( + g_direct_hash, g_direct_equal, + (GDestroyNotify) NULL, + (GDestroyNotify) store_hash_free); + + priv->async_event = mail_async_event_new (); + + priv->folder_tree_model = em_folder_tree_model_new ( + E_MAIL_SHELL_BACKEND (shell_backend)); + + g_signal_connect ( + shell, "notify::online", + G_CALLBACK (mail_shell_backend_notify_online_cb), + shell_backend); + + g_signal_connect ( + shell, "handle-uri", + G_CALLBACK (mail_shell_backend_handle_uri_cb), + shell_backend); + + g_signal_connect ( + shell, "prepare-for-offline", + G_CALLBACK (mail_shell_backend_prepare_for_offline_cb), + shell_backend); + + g_signal_connect ( + shell, "prepare-for-online", + G_CALLBACK (mail_shell_backend_prepare_for_online_cb), + shell_backend); + + g_signal_connect ( + shell, "send-receive", + G_CALLBACK (mail_shell_backend_send_receive_cb), + shell_backend); + + g_signal_connect ( + shell, "window-created", + G_CALLBACK (mail_shell_backend_window_created_cb), + shell_backend); + + mail_config_init (); + mail_msg_init (); + + mail_shell_backend_init_local_store (shell_backend); + mail_shell_backend_load_accounts (shell_backend); + + /* Initialize settings before initializing preferences, + * since the preferences bind to the shell settings. */ + e_mail_shell_settings_init (shell); + mail_shell_backend_init_preferences (shell); +} + +static void +mail_shell_backend_start (EShellBackend *shell_backend) +{ + EMailShellBackendPrivate *priv; + EShell *shell; + EShellSettings *shell_settings; + gboolean enable_search_folders; + + priv = E_MAIL_SHELL_BACKEND_GET_PRIVATE (shell_backend); + + shell = e_shell_backend_get_shell (shell_backend); + shell_settings = e_shell_get_shell_settings (shell); + + /* XXX Do we really still need this flag? */ + mail_session_set_interactive (TRUE); + + enable_search_folders = e_shell_settings_get_boolean ( + shell_settings, "mail-enable-search-folders"); + if (enable_search_folders) + vfolder_load_storage (); + + mail_autoreceive_init (shell_backend, session); + + if (g_getenv ("CAMEL_FLUSH_CHANGES") != NULL) + priv->mail_sync_timeout_source_id = g_timeout_add_seconds ( + mail_config_get_sync_timeout (), + (GSourceFunc) mail_shell_backend_mail_sync, + shell_backend); +} + +static void +mail_shell_backend_class_init (EMailShellBackendClass *class) +{ + GObjectClass *object_class; + EShellBackendClass *shell_backend_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EMailShellBackendPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->dispose = mail_shell_backend_dispose; + object_class->finalize = mail_shell_backend_finalize; + object_class->constructed = mail_shell_backend_constructed; + + shell_backend_class = E_SHELL_BACKEND_CLASS (class); + shell_backend_class->name = BACKEND_NAME; + shell_backend_class->aliases = ""; + shell_backend_class->schemes = "mailto:email"; + shell_backend_class->sort_order = 200; + shell_backend_class->view_type = E_TYPE_MAIL_SHELL_VIEW; + shell_backend_class->start = mail_shell_backend_start; + shell_backend_class->is_busy = NULL; + shell_backend_class->shutdown = NULL; + shell_backend_class->migrate = e_mail_shell_migrate; +} + +static void +mail_shell_backend_init (EMailShellBackend *mail_shell_backend) +{ + mail_shell_backend->priv = + E_MAIL_SHELL_BACKEND_GET_PRIVATE (mail_shell_backend); +} + +GType +e_mail_shell_backend_get_type (GTypeModule *type_module) +{ + if (e_mail_shell_backend_type == 0) { + const GTypeInfo type_info = { + sizeof (EMailShellBackendClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) mail_shell_backend_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EMailShellBackend), + 0, /* n_preallocs */ + (GInstanceInitFunc) mail_shell_backend_init, + NULL /* value_table */ + }; + + e_mail_shell_backend_type = + g_type_module_register_type ( + type_module, E_TYPE_SHELL_BACKEND, + "EMailShellBackend", &type_info, 0); + } + + return e_mail_shell_backend_type; +} + +void +e_module_load (GTypeModule *type_module) +{ + e_mail_shell_backend_get_type (type_module); + e_mail_shell_view_get_type (type_module); +} + +void +e_module_unload (GTypeModule *type_module) +{ +} + +/******************************** Public API *********************************/ + +CamelFolder * +e_mail_shell_backend_get_folder (EMailShellBackend *mail_shell_backend, + EMailFolderType folder_type) +{ + g_return_val_if_fail ( + E_IS_MAIL_SHELL_BACKEND (mail_shell_backend), NULL); + + return default_local_folders[folder_type].folder; +} + +const gchar * +e_mail_shell_backend_get_folder_uri (EMailShellBackend *mail_shell_backend, + EMailFolderType folder_type) +{ + g_return_val_if_fail ( + E_IS_MAIL_SHELL_BACKEND (mail_shell_backend), NULL); + + return default_local_folders[folder_type].uri; +} + +EMFolderTreeModel * +e_mail_shell_backend_get_folder_tree_model (EMailShellBackend *mail_shell_backend) +{ + g_return_val_if_fail ( + E_IS_MAIL_SHELL_BACKEND (mail_shell_backend), NULL); + + return mail_shell_backend->priv->folder_tree_model; +} + +void +e_mail_shell_backend_add_store (EMailShellBackend *mail_shell_backend, + CamelStore *store, + const gchar *name) +{ + g_return_if_fail (E_IS_MAIL_SHELL_BACKEND (mail_shell_backend)); + g_return_if_fail (CAMEL_IS_STORE (store)); + g_return_if_fail (name != NULL); + + mail_shell_backend_add_store (mail_shell_backend, store, name, NULL); +} + +CamelStore * +e_mail_shell_backend_get_local_store (EMailShellBackend *mail_shell_backend) +{ + g_return_val_if_fail ( + E_IS_MAIL_SHELL_BACKEND (mail_shell_backend), NULL); + + return mail_shell_backend->priv->local_store; +} + +CamelStore * +e_mail_shell_backend_load_store_by_uri (EMailShellBackend *mail_shell_backend, + const gchar *uri, + const gchar *name) +{ + CamelStore *store; + CamelProvider *provider; + CamelException ex; + + g_return_val_if_fail ( + E_IS_MAIL_SHELL_BACKEND (mail_shell_backend), NULL); + g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (name != NULL, NULL); + + camel_exception_init (&ex); + + /* Load the service, but don't connect. Check its provider, + * and if this belongs in the shell's folder list, add it. */ + + provider = camel_provider_get (uri, &ex); + if (provider == NULL) + goto fail; + + if (!(provider->flags & CAMEL_PROVIDER_IS_STORAGE)) + return NULL; + + store = (CamelStore *) camel_session_get_service ( + session, uri, CAMEL_PROVIDER_STORE, &ex); + if (store == NULL) + goto fail; + + e_mail_shell_backend_add_store (mail_shell_backend, store, name); + + camel_object_unref (store); + + return store; + +fail: + /* FIXME: Show an error dialog. */ + g_warning ( + "Couldn't get service: %s: %s", uri, + camel_exception_get_description (&ex)); + camel_exception_clear (&ex); + + return NULL; +} + +/* Helper for e_mail_shell_backend_remove_store() */ +static void +mail_shell_backend_remove_store_cb (CamelStore *store, + gpointer event_data, + gpointer user_data) +{ + camel_service_disconnect (CAMEL_SERVICE (store), TRUE, NULL); + camel_object_unref (store); +} + +void +e_mail_shell_backend_remove_store (EMailShellBackend *mail_shell_backend, + CamelStore *store) +{ + GHashTable *store_hash; + MailAsyncEvent *async_event; + EMFolderTreeModel *folder_tree_model; + + g_return_if_fail (E_IS_MAIL_SHELL_BACKEND (mail_shell_backend)); + g_return_if_fail (CAMEL_IS_STORE (store)); + + store_hash = mail_shell_backend->priv->store_hash; + async_event = mail_shell_backend->priv->async_event; + folder_tree_model = mail_shell_backend->priv->folder_tree_model; + + /* Because the store hash holds a reference to each store used + * as a key in it, none of them will ever be gc'ed, meaning any + * call to camel_session_get_{service,store} with the same URL + * will always return the same object. So this works. */ + + if (g_hash_table_lookup (store_hash, store) == NULL) + return; + + camel_object_ref (store); + g_hash_table_remove (store_hash, store); + mail_note_store_remove (store); + em_folder_tree_model_remove_store (folder_tree_model, store); + + mail_async_event_emit ( + async_event, MAIL_ASYNC_THREAD, + (MailAsyncFunc) mail_shell_backend_remove_store_cb, + store, NULL, NULL); +} + +void +e_mail_shell_backend_remove_store_by_uri (EMailShellBackend *mail_shell_backend, + const gchar *uri) +{ + CamelStore *store; + CamelProvider *provider; + + g_return_if_fail (E_IS_MAIL_SHELL_BACKEND (mail_shell_backend)); + g_return_if_fail (uri != NULL); + + provider = camel_provider_get (uri, NULL); + if (provider == NULL) + return; + + if (!(provider->flags & CAMEL_PROVIDER_IS_STORAGE)) + return; + + store = (CamelStore *) camel_session_get_service ( + session, uri, CAMEL_PROVIDER_STORE, NULL); + if (store != NULL) { + e_mail_shell_backend_remove_store (mail_shell_backend, store); + camel_object_unref (store); + } +} + +void +e_mail_shell_backend_stores_foreach (EMailShellBackend *mail_shell_backend, + GHFunc func, + gpointer user_data) +{ + GHashTable *store_hash; + GHashTableIter iter; + gpointer key, value; + + g_return_if_fail (E_IS_MAIL_SHELL_BACKEND (mail_shell_backend)); + g_return_if_fail (func != NULL); + + store_hash = mail_shell_backend->priv->store_hash; + + g_hash_table_iter_init (&iter, store_hash); + + while (g_hash_table_iter_next (&iter, &key, &value)) + func (key, ((StoreInfo *) value)->name, user_data); +} + +/******************* Code below here belongs elsewhere. *******************/ + +#include "filter/filter-option.h" +#include "shell/e-shell-settings.h" +#include "mail/e-mail-label-list-store.h" + +GSList * +e_mail_labels_get_filter_options (void) +{ + EShell *shell; + EShellSettings *shell_settings; + EMailLabelListStore *list_store; + GtkTreeModel *model; + GtkTreeIter iter; + GSList *list = NULL; + gboolean valid; + + shell = e_shell_get_default (); + shell_settings = e_shell_get_shell_settings (shell); + list_store = e_shell_settings_get_object ( + shell_settings, "mail-label-list-store"); + + model = GTK_TREE_MODEL (list_store); + valid = gtk_tree_model_get_iter_first (model, &iter); + + while (valid) { + struct _filter_option *option; + gchar *name, *tag; + + name = e_mail_label_list_store_get_name (list_store, &iter); + tag = e_mail_label_list_store_get_tag (list_store, &iter); + + option = g_new0 (struct _filter_option, 1); + option->title = e_str_without_underscores (name); + option->value = tag; /* takes ownership */ + + g_free (name); + + valid = gtk_tree_model_iter_next (model, &iter); + } + + g_object_unref (list_store); + + return list; +} diff --git a/mail/e-mail-shell-backend.h b/mail/e-mail-shell-backend.h new file mode 100644 index 0000000000..fdf8ec6f76 --- /dev/null +++ b/mail/e-mail-shell-backend.h @@ -0,0 +1,123 @@ +/* + * e-mail-shell-backend.h + * + * 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 + * + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef E_MAIL_SHELL_BACKEND_H +#define E_MAIL_SHELL_BACKEND_H + +#include + +#include +#include +#include +#include + +/* Standard GObject macros */ +#define E_TYPE_MAIL_SHELL_BACKEND \ + (e_mail_shell_backend_type) +#define E_MAIL_SHELL_BACKEND(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_MAIL_SHELL_BACKEND, EMailShellBackend)) +#define E_MAIL_SHELL_BACKEND_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_MAIL_SHELL_BACKEND, EMailShellBackendClass)) +#define E_IS_MAIL_SHELL_BACKEND(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_MAIL_SHELL_BACKEND)) +#define E_IS_MAIL_SHELL_BACKEND_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_MAIL_SHELL_BACKEND)) +#define E_MAIL_SHELL_BACKEND_GET_CLASS(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_MAIL_SHELL_BACKEND, EMailShellBackendClass)) + +G_BEGIN_DECLS + +extern GType e_mail_shell_backend_type; + +typedef struct _EMailShellBackend EMailShellBackend; +typedef struct _EMailShellBackendClass EMailShellBackendClass; +typedef struct _EMailShellBackendPrivate EMailShellBackendPrivate; + +struct _EMailShellBackend { + EShellBackend parent; + EMailShellBackendPrivate *priv; +}; + +struct _EMailShellBackendClass { + EShellBackendClass parent_class; +}; + +typedef enum { + E_MAIL_FOLDER_INBOX, + E_MAIL_FOLDER_DRAFTS, + E_MAIL_FOLDER_OUTBOX, + E_MAIL_FOLDER_SENT, + E_MAIL_FOLDER_TEMPLATES, + E_MAIL_FOLDER_LOCAL_INBOX +} EMailFolderType; + +struct _EMFolderTreeModel; + +/* Globally available shell backend. + * + * XXX I don't like having this globally available but passing it around + * to all the various utilities that need to access the backend's data + * directory and local folders is too much of a pain for now. */ +extern EMailShellBackend *global_mail_shell_backend; + +GType e_mail_shell_backend_get_type + (GTypeModule *type_module); +CamelFolder * e_mail_shell_backend_get_folder + (EMailShellBackend *mail_shell_backend, + EMailFolderType folder_type); +const gchar * e_mail_shell_backend_get_folder_uri + (EMailShellBackend *mail_shell_backend, + EMailFolderType folder_type); +struct _EMFolderTreeModel * + e_mail_shell_backend_get_folder_tree_model + (EMailShellBackend *mail_shell_backend); +void e_mail_shell_backend_add_store + (EMailShellBackend *mail_shell_backend, + CamelStore *store, + const gchar *name); +CamelStore * e_mail_shell_backend_get_local_store + (EMailShellBackend *mail_shell_backend); +CamelStore * e_mail_shell_backend_load_store_by_uri + (EMailShellBackend *mail_shell_backend, + const gchar *uri, + const gchar *name); +void e_mail_shell_backend_remove_store + (EMailShellBackend *mail_shell_backend, + CamelStore *store); +void e_mail_shell_backend_remove_store_by_uri + (EMailShellBackend *mail_shell_backend, + const gchar *uri); +void e_mail_shell_backend_stores_foreach + (EMailShellBackend *mail_shell_backend, + GHFunc func, + gpointer user_data); + +/* XXX Find a better place for this function. */ +GSList * e_mail_labels_get_filter_options(void); + +G_END_DECLS + +#endif /* E_MAIL_SHELL_BACKEND_H */ diff --git a/mail/e-mail-shell-content.c b/mail/e-mail-shell-content.c index f7bb17592e..50bf0471bb 100644 --- a/mail/e-mail-shell-content.c +++ b/mail/e-mail-shell-content.c @@ -37,7 +37,7 @@ #include "e-mail-reader.h" #include "e-mail-search-bar.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" #include "e-mail-shell-view-actions.h" #define E_MAIL_SHELL_CONTENT_GET_PRIVATE(obj) \ @@ -361,7 +361,7 @@ mail_shell_content_constructed (GObject *object) { EMailShellContentPrivate *priv; EShellContent *shell_content; - EShellModule *shell_module; + EShellBackend *shell_backend; EShellView *shell_view; EShellViewClass *shell_view_class; EMailReader *reader; @@ -382,7 +382,7 @@ mail_shell_content_constructed (GObject *object) shell_content = E_SHELL_CONTENT (object); shell_view = e_shell_content_get_shell_view (shell_content); shell_view_class = E_SHELL_VIEW_GET_CLASS (shell_view); - shell_module = e_shell_view_get_shell_module (shell_view); + shell_backend = e_shell_view_get_shell_backend (shell_view); view_collection = shell_view_class->view_collection; html = EM_FORMAT_HTML (priv->html_display)->html; @@ -398,7 +398,7 @@ mail_shell_content_constructed (GObject *object) container = widget; - widget = message_list_new (shell_module); + widget = message_list_new (shell_backend); gtk_paned_add1 (GTK_PANED (container), widget); priv->message_list = g_object_ref (widget); gtk_widget_show (widget); @@ -507,8 +507,8 @@ mail_shell_content_get_message_list (EMailReader *reader) return MESSAGE_LIST (priv->message_list); } -static EShellModule * -mail_shell_content_get_shell_module (EMailReader *reader) +static EShellBackend * +mail_shell_content_get_shell_backend (EMailReader *reader) { EShellContent *shell_content; EShellView *shell_view; @@ -516,7 +516,7 @@ mail_shell_content_get_shell_module (EMailReader *reader) shell_content = E_SHELL_CONTENT (reader); shell_view = e_shell_content_get_shell_view (shell_content); - return e_shell_view_get_shell_module (shell_view); + return e_shell_view_get_shell_backend (shell_view); } static GtkWindow * @@ -657,7 +657,7 @@ mail_shell_content_iface_init (EMailReaderIface *iface) iface->get_hide_deleted = mail_shell_content_get_hide_deleted; iface->get_html_display = mail_shell_content_get_html_display; iface->get_message_list = mail_shell_content_get_message_list; - iface->get_shell_module = mail_shell_content_get_shell_module; + iface->get_shell_backend = mail_shell_content_get_shell_backend; iface->get_window = mail_shell_content_get_window; iface->set_folder = mail_shell_content_set_folder; iface->show_search_bar = mail_shell_content_show_search_bar; diff --git a/mail/e-mail-shell-migrate.c b/mail/e-mail-shell-migrate.c new file mode 100644 index 0000000000..99469b1d6d --- /dev/null +++ b/mail/e-mail-shell-migrate.c @@ -0,0 +1,2988 @@ +/* + * e-mail-shell-migrate.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 + * + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "e-mail-shell-migrate.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include "e-util/e-account-utils.h" +#include "e-util/e-bconf-map.h" +#include "e-util/e-error.h" +#include "e-util/e-util-private.h" +#include "e-util/e-plugin.h" +#include "e-util/e-signature-utils.h" + +#include "e-mail-shell-backend.h" +#include "shell/e-shell-migrate.h" + +#include "mail-config.h" +#include "em-utils.h" + +#define d(x) x + +#ifndef G_OS_WIN32 +/* No versions previous to 2.8 or thereabouts have been available on + * Windows, so don't bother with upgrade support from earlier versions + * on Win32. Do try to support upgrades from 2.12 and later to the + * current version. + */ + +/* upgrade helper functions */ +static xmlDocPtr +emm_load_xml (const char *dirname, const char *filename) +{ + xmlDocPtr doc; + struct stat st; + char *path; + + path = g_strdup_printf ("%s/%s", dirname, filename); + if (stat (path, &st) == -1 || !(doc = xmlParseFile (path))) { + g_free (path); + return NULL; + } + + g_free (path); + + return doc; +} + +static int +emm_save_xml (xmlDocPtr doc, const char *dirname, const char *filename) +{ + char *path; + int retval; + + path = g_strdup_printf ("%s/%s", dirname, filename); + retval = e_xml_save_file (path, doc); + g_free (path); + + return retval; +} + +static xmlNodePtr +xml_find_node (xmlNodePtr parent, const char *name) +{ + xmlNodePtr node; + + node = parent->children; + while (node != NULL) { + if (node->name && !strcmp ((char *)node->name, name)) + return node; + + node = node->next; + } + + return NULL; +} + +static void +upgrade_xml_uris (xmlDocPtr doc, char * (* upgrade_uri) (const char *uri)) +{ + xmlNodePtr root, node; + char *uri, *new; + + if (!doc || !(root = xmlDocGetRootElement (doc))) + return; + + if (!root->name || strcmp ((char *)root->name, "filteroptions") != 0) { + /* root node is not , nothing to upgrade */ + return; + } + + if (!(node = xml_find_node (root, "ruleset"))) { + /* no ruleset node, nothing to upgrade */ + return; + } + + node = node->children; + while (node != NULL) { + if (node->name && !strcmp ((char *)node->name, "rule")) { + xmlNodePtr actionset, part, val, n; + + if ((actionset = xml_find_node (node, "actionset"))) { + /* filters.xml */ + part = actionset->children; + while (part != NULL) { + if (part->name && !strcmp ((char *)part->name, "part")) { + val = part->children; + while (val != NULL) { + if (val->name && !strcmp ((char *)val->name, "value")) { + char *type; + + type = (char *)xmlGetProp (val, (const unsigned char *)"type"); + if (type && !strcmp ((char *)type, "folder")) { + if ((n = xml_find_node (val, "folder"))) { + uri = (char *)xmlGetProp (n, (const unsigned char *)"uri"); + new = upgrade_uri (uri); + xmlFree (uri); + + xmlSetProp (n, (const unsigned char *)"uri", (unsigned char *)new); + g_free (new); + } + } + + xmlFree (type); + } + + val = val->next; + } + } + + part = part->next; + } + } else if ((actionset = xml_find_node (node, "sources"))) { + /* vfolders.xml */ + n = actionset->children; + while (n != NULL) { + if (n->name && !strcmp ((char *)n->name, "folder")) { + uri = (char *)xmlGetProp (n, (const unsigned char *)"uri"); + new = upgrade_uri (uri); + xmlFree (uri); + + xmlSetProp (n, (const unsigned char *)"uri", (unsigned char *)new); + g_free (new); + } + + n = n->next; + } + } + } + + node = node->next; + } +} + +/* 1.0 upgrade functions & data */ + +/* as much info as we have on a given account */ +struct _account_info_1_0 { + char *name; + char *uri; + char *base_uri; + union { + struct { + /* for imap */ + char *namespace; + char *namespace_full; + guint32 capabilities; + GHashTable *folders; + char dir_sep; + } imap; + } u; +}; + +struct _imap_folder_info_1_0 { + char *folder; + /* encoded? decoded? canonicalised? */ + char dir_sep; +}; + +static GHashTable *accounts_1_0 = NULL; +static GHashTable *accounts_name_1_0 = NULL; + +static void +imap_folder_info_1_0_free (struct _imap_folder_info_1_0 *fi) +{ + g_free(fi->folder); + g_free(fi); +} + +static void +account_info_1_0_free (struct _account_info_1_0 *ai) +{ + g_free(ai->name); + g_free(ai->uri); + g_free(ai->base_uri); + g_free(ai->u.imap.namespace); + g_free(ai->u.imap.namespace_full); + g_hash_table_destroy(ai->u.imap.folders); + g_free(ai); +} + +static char * +get_base_uri(const char *val) +{ + const char *tmp; + + tmp = strchr(val, ':'); + if (tmp) { + tmp++; + if (strncmp(tmp, "//", 2) == 0) + tmp += 2; + tmp = strchr(tmp, '/'); + } + + if (tmp) + return g_strndup(val, tmp-val); + else + return g_strdup(val); +} + +static char * +upgrade_xml_uris_1_0 (const char *uri) +{ + char *out = NULL; + + /* upgrades camel uri's */ + if (strncmp (uri, "imap:", 5) == 0) { + char *base_uri, dir_sep, *folder, *p; + struct _account_info_1_0 *ai; + + /* add namespace, canonicalise dir_sep to / */ + base_uri = get_base_uri (uri); + ai = g_hash_table_lookup (accounts_1_0, base_uri); + + if (ai == NULL) { + g_free (base_uri); + return NULL; + } + + dir_sep = ai->u.imap.dir_sep; + if (dir_sep == 0) { + /* no dir_sep listed, try get it from the namespace, if set */ + if (ai->u.imap.namespace != NULL) { + p = ai->u.imap.namespace; + while ((dir_sep = *p++)) { + if (dir_sep < '0' + || (dir_sep > '9' && dir_sep < 'A') + || (dir_sep > 'Z' && dir_sep < 'a') + || (dir_sep > 'z')) { + break; + } + p++; + } + } + + /* give up ... */ + if (dir_sep == 0) { + g_free (base_uri); + return NULL; + } + } + + folder = g_strdup (uri + strlen (base_uri) + 1); + + /* Add the namespace before the mailbox name, unless the mailbox is INBOX */ + if (ai->u.imap.namespace && strcmp ((char *)folder, "INBOX") != 0) + out = g_strdup_printf ("%s/%s/%s", base_uri, ai->u.imap.namespace, folder); + else + out = g_strdup_printf ("%s/%s", base_uri, folder); + + p = out; + while (*p) { + if (*p == dir_sep) + *p = '/'; + p++; + } + + g_free (folder); + g_free (base_uri); + } else if (strncmp (uri, "exchange:", 9) == 0) { + char *base_uri, *folder, *p; + + /* exchange://user@host/exchange/ * -> exchange://user@host/personal/ * */ + /* Any url encoding (%xx) in the folder name is also removed */ + base_uri = get_base_uri (uri); + uri += strlen (base_uri) + 1; + if (strncmp (uri, "exchange/", 9) == 0) { + folder = e_bconf_url_decode (uri + 9); + p = strchr (folder, '/'); + out = g_strdup_printf ("%s/personal%s", base_uri, p ? p : "/"); + g_free (folder); + } + } else if (strncmp (uri, "exchanget:", 10) == 0) { + /* these should be converted in the accounts table when it is loaded */ + g_warning ("exchanget: uri not converted: '%s'", uri); + } + + return out; +} + +static char * +parse_lsub (const char *lsub, char *dir_sep) +{ + static int comp; + static regex_t pat; + regmatch_t match[3]; + char *m = "^\\* LSUB \\([^)]*\\) \"?([^\" ]+)\"? \"?(.*)\"?$"; + + if (!comp) { + if (regcomp (&pat, m, REG_EXTENDED|REG_ICASE) == -1) { + g_warning ("reg comp '%s' failed: %s", m, g_strerror (errno)); + return NULL; + } + comp = 1; + } + + if (regexec (&pat, lsub, 3, match, 0) == 0) { + if (match[1].rm_so != -1 && match[2].rm_so != -1) { + if (dir_sep) + *dir_sep = (match[1].rm_eo - match[1].rm_so == 1) ? lsub[match[1].rm_so] : 0; + return g_strndup (lsub + match[2].rm_so, match[2].rm_eo - match[2].rm_so); + } + } + + return NULL; +} + +static gboolean +read_imap_storeinfo (struct _account_info_1_0 *si) +{ + FILE *storeinfo; + guint32 tmp; + char *buf, *folder, dir_sep, *path, *name, *p; + struct _imap_folder_info_1_0 *fi; + + si->u.imap.folders = g_hash_table_new_full ( + g_str_hash, g_str_equal, + (GDestroyNotify) NULL, + (GDestroyNotify) imap_folder_info_1_0_free); + + /* get details from uri first */ + name = strstr (si->uri, ";override_namespace"); + if (name) { + name = strstr (si->uri, ";namespace="); + if (name) { + char *end; + + name += strlen (";namespace="); + if (*name == '\"') { + name++; + end = strchr (name, '\"'); + } else { + end = strchr (name, ';'); + } + + if (end) { + /* try get the dir_sep from the namespace */ + si->u.imap.namespace = g_strndup (name, end-name); + + p = si->u.imap.namespace; + while ((dir_sep = *p++)) { + if (dir_sep < '0' + || (dir_sep > '9' && dir_sep < 'A') + || (dir_sep > 'Z' && dir_sep < 'a') + || (dir_sep > 'z')) { + si->u.imap.dir_sep = dir_sep; + break; + } + p++; + } + } + } + } + + /* now load storeinfo if it exists */ + path = g_build_filename (g_get_home_dir (), "evolution", "mail", "imap", si->base_uri + 7, "storeinfo", NULL); + storeinfo = fopen (path, "r"); + g_free (path); + if (storeinfo == NULL) { + g_warning ("could not find imap store info '%s'", path); + return FALSE; + } + + /* ignore version */ + camel_file_util_decode_uint32 (storeinfo, &tmp); + camel_file_util_decode_uint32 (storeinfo, &si->u.imap.capabilities); + g_free (si->u.imap.namespace); + camel_file_util_decode_string (storeinfo, &si->u.imap.namespace); + camel_file_util_decode_uint32 (storeinfo, &tmp); + si->u.imap.dir_sep = tmp; + /* strip trailing dir_sep or / */ + if (si->u.imap.namespace + && (si->u.imap.namespace[strlen (si->u.imap.namespace) - 1] == si->u.imap.dir_sep + || si->u.imap.namespace[strlen (si->u.imap.namespace) - 1] == '/')) { + si->u.imap.namespace[strlen (si->u.imap.namespace) - 1] = 0; + } + + d(printf ("namespace '%s' dir_sep '%c'\n", si->u.imap.namespace, si->u.imap.dir_sep ? si->u.imap.dir_sep : '?')); + + while (camel_file_util_decode_string (storeinfo, &buf) == 0) { + folder = parse_lsub (buf, &dir_sep); + if (folder) { + fi = g_new0 (struct _imap_folder_info_1_0, 1); + fi->folder = folder; + fi->dir_sep = dir_sep; +#if d(!)0 + printf (" add folder '%s' ", folder); + if (dir_sep) + printf ("'%c'\n", dir_sep); + else + printf ("NIL\n"); +#endif + g_hash_table_insert (si->u.imap.folders, fi->folder, fi); + } else { + g_warning ("Could not parse LIST result '%s'\n", buf); + } + } + + fclose (storeinfo); + + return TRUE; +} + +static gboolean +load_accounts_1_0 (xmlDocPtr doc) +{ + xmlNodePtr source; + char *val, *tmp; + int count = 0, i; + char key[32]; + + if (!(source = e_bconf_get_path (doc, "/Mail/Accounts"))) + return TRUE; + + if ((val = e_bconf_get_value (source, "num"))) { + count = atoi (val); + xmlFree (val); + } + + /* load account upgrade info for each account */ + for (i = 0; i < count; i++) { + struct _account_info_1_0 *ai; + char *rawuri; + + sprintf (key, "source_url_%d", i); + if (!(rawuri = e_bconf_get_value (source, key))) + continue; + + ai = g_malloc0 (sizeof (struct _account_info_1_0)); + ai->uri = e_bconf_hex_decode (rawuri); + ai->base_uri = get_base_uri (ai->uri); + sprintf (key, "account_name_%d", i); + ai->name = e_bconf_get_string (source, key); + + d(printf("load account '%s'\n", ai->uri)); + + if (!strncmp (ai->uri, "imap:", 5)) { + read_imap_storeinfo (ai); + } else if (!strncmp (ai->uri, "exchange:", 9)) { + xmlNodePtr node; + + d(printf (" upgrade exchange account\n")); + /* small hack, poke the source_url into the transport_url for exchanget: transports + - this will be picked up later in the conversion */ + sprintf (key, "transport_url_%d", i); + node = e_bconf_get_entry (source, key); + if (node && (val = (char *)xmlGetProp (node, (const unsigned char *)"value"))) { + tmp = e_bconf_hex_decode (val); + xmlFree (val); + if (strncmp (tmp, "exchanget:", 10) == 0) + xmlSetProp (node, (const unsigned char *)"value", (unsigned char *)rawuri); + g_free (tmp); + } else { + d(printf (" couldn't find transport uri?\n")); + } + } + xmlFree (rawuri); + + g_hash_table_insert (accounts_1_0, ai->base_uri, ai); + if (ai->name) + g_hash_table_insert (accounts_name_1_0, ai->name, ai); + } + + return TRUE; +} + +static gboolean +em_migrate_1_0 (const char *data_dir, xmlDocPtr config_xmldb, xmlDocPtr filters, xmlDocPtr vfolders, GError **error) +{ + accounts_1_0 = g_hash_table_new_full ( + g_str_hash, g_str_equal, + (GDestroyNotify) NULL, + (GDestroyNotify) account_info_1_0_free); + accounts_name_1_0 = g_hash_table_new (g_str_hash, g_str_equal); + load_accounts_1_0 (config_xmldb); + + upgrade_xml_uris(filters, upgrade_xml_uris_1_0); + upgrade_xml_uris(vfolders, upgrade_xml_uris_1_0); + + g_hash_table_destroy (accounts_1_0); + g_hash_table_destroy (accounts_name_1_0); + + return TRUE; +} + +/* 1.2 upgrade functions */ +static gboolean +is_xml1encoded (const char *txt) +{ + const unsigned char *p; + int isxml1 = FALSE; + int is8bit = FALSE; + + p = (const unsigned char *)txt; + while (*p) { + if (p[0] == '\\' && p[1] == 'U' && p[2] == '+' + && isxdigit (p[3]) && isxdigit (p[4]) && isxdigit (p[5]) && isxdigit (p[6]) + && p[7] == '\\') { + isxml1 = TRUE; + p+=7; + } else if (p[0] >= 0x80) + is8bit = TRUE; + p++; + } + + /* check for invalid utf8 that needs cleaning */ + if (is8bit && !isxml1) + isxml1 = !g_utf8_validate (txt, -1, NULL); + + return isxml1; +} + +static char * +decode_xml1 (const char *txt) +{ + GString *out = g_string_new (""); + const unsigned char *p; + char *res; + + /* convert: + \U+XXXX\ -> utf8 + 8 bit characters -> utf8 (iso-8859-1) */ + + p = (const unsigned char *) txt; + while (*p) { + if (p[0] > 0x80 + || (p[0] == '\\' && p[1] == 'U' && p[2] == '+' + && isxdigit (p[3]) && isxdigit (p[4]) && isxdigit (p[5]) && isxdigit (p[6]) + && p[7] == '\\')) { + char utf8[8]; + gunichar u; + + if (p[0] == '\\') { + memcpy (utf8, p + 3, 4); + utf8[4] = 0; + u = strtoul (utf8, NULL, 16); + p+=7; + } else + u = p[0]; + utf8[g_unichar_to_utf8 (u, utf8)] = 0; + g_string_append (out, utf8); + } else { + g_string_append_c (out, *p); + } + p++; + } + + res = out->str; + g_string_free (out, FALSE); + + return res; +} + +static char * +utf8_reencode (const char *txt) +{ + GString *out = g_string_new (""); + gchar *p; + char *res; + + /* convert: + libxml1 8 bit utf8 converted to xml entities byte-by-byte chars -> utf8 */ + + p = (gchar *)txt; + + while (*p) { + g_string_append_c (out, (gchar)g_utf8_get_char ((const gchar *)p)); + p = (gchar *)g_utf8_next_char (p); + } + + res = out->str; + if (g_utf8_validate (res, -1, NULL)) { + g_string_free (out, FALSE); + return res; + } else { + g_string_free (out, TRUE); + return g_strdup (txt); + } +} + +static gboolean +upgrade_xml_1_2_rec (xmlNodePtr node) +{ + const char *value_tags[] = { "string", "address", "regex", "file", "command", NULL }; + const char *rule_tags[] = { "title", NULL }; + const char *item_props[] = { "name", NULL }; + struct { + const char *name; + const char **tags; + const char **props; + } tags[] = { + { "value", value_tags, NULL }, + { "rule", rule_tags, NULL }, + { "item", NULL, item_props }, + { 0 }, + }; + xmlNodePtr work; + int i,j; + char *txt, *tmp; + + /* upgrades the content of a node, if the node has a specific parent/node name */ + + for (i = 0; tags[i].name; i++) { + if (!strcmp ((char *)node->name, tags[i].name)) { + if (tags[i].tags != NULL) { + work = node->children; + while (work) { + for (j = 0; tags[i].tags[j]; j++) { + if (!strcmp ((char *)work->name, tags[i].tags[j])) { + txt = (char *)xmlNodeGetContent (work); + if (is_xml1encoded (txt)) { + tmp = decode_xml1 (txt); + d(printf ("upgrading xml node %s/%s '%s' -> '%s'\n", + tags[i].name, tags[i].tags[j], txt, tmp)); + xmlNodeSetContent (work, (unsigned char *)tmp); + g_free (tmp); + } + xmlFree (txt); + } + } + work = work->next; + } + break; + } + + if (tags[i].props != NULL) { + for (j = 0; tags[i].props[j]; j++) { + txt = (char *)xmlGetProp (node, (unsigned char *)tags[i].props[j]); + tmp = utf8_reencode (txt); + d(printf ("upgrading xml property %s on node %s '%s' -> '%s'\n", + tags[i].props[j], tags[i].name, txt, tmp)); + xmlSetProp (node, (const unsigned char *)tags[i].props[j], (unsigned char *)tmp); + g_free (tmp); + xmlFree (txt); + } + } + } + } + + node = node->children; + while (node) { + upgrade_xml_1_2_rec (node); + node = node->next; + } + + return TRUE; +} + +static gboolean +em_upgrade_xml_1_2 (xmlDocPtr doc) +{ + xmlNodePtr root; + + if (!doc || !(root = xmlDocGetRootElement (doc))) + return TRUE; + + return upgrade_xml_1_2_rec (root); +} + +/* ********************************************************************** */ +/* Tables for converting flat bonobo conf -> gconf xml blob */ +/* ********************************************************************** */ + +/* Mail/Accounts/ * */ +static e_bconf_map_t cc_map[] = { + { "account_always_cc_%i", "always", E_BCONF_MAP_BOOL }, + { "account_always_cc_addrs_%i", "recipients", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, + { NULL }, +}; + +static e_bconf_map_t bcc_map[] = { + { "account_always_cc_%i", "always", E_BCONF_MAP_BOOL }, + { "account_always_bcc_addrs_%i", "recipients", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, + { NULL }, +}; + +static e_bconf_map_t pgp_map[] = { + { "account_pgp_encrypt_to_self_%i", "encrypt-to-self", E_BCONF_MAP_BOOL }, + { "account_pgp_always_trust_%i", "always-trust", E_BCONF_MAP_BOOL }, + { "account_pgp_always_sign_%i", "always-sign", E_BCONF_MAP_BOOL }, + { "account_pgp_no_imip_sign_%i", "no-imip-sign", E_BCONF_MAP_BOOL }, + { "account_pgp_key_%i", "key-id", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, + { NULL }, +}; + +static e_bconf_map_t smime_map[] = { + { "account_smime_encrypt_to_self_%i", "encrypt-to-self", E_BCONF_MAP_BOOL }, + { "account_smime_always_sign_%i", "always-sign", E_BCONF_MAP_BOOL }, + { "account_smime_key_%i", "key-id", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, + { NULL }, +}; + +static e_bconf_map_t identity_sig_map[] = { + { "identity_autogenerated_signature_%i", "auto", E_BCONF_MAP_BOOL }, + { "identity_def_signature_%i", "default", E_BCONF_MAP_LONG }, + { NULL }, +}; + +static e_bconf_map_t identity_map[] = { + { "identity_name_%i", "name", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, + { "identity_address_%i", "addr-spec", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, + { "identity_reply_to_%i", "reply-to", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, + { "identity_organization_%i", "organization", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, + { NULL, "signature", E_BCONF_MAP_CHILD, identity_sig_map }, + { NULL }, +}; + +static e_bconf_map_t source_map[] = { + { "source_save_passwd_%i", "save-passwd", E_BCONF_MAP_BOOL }, + { "source_keep_on_server_%i", "keep-on-server", E_BCONF_MAP_BOOL }, + { "source_auto_check_%i", "auto-check", E_BCONF_MAP_BOOL }, + { "source_auto_check_time_%i", "auto-check-timeout", E_BCONF_MAP_LONG }, + { "source_url_%i", "url", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, + { NULL }, +}; + +static e_bconf_map_t transport_map[] = { + { "transport_save_passwd_%i", "save-passwd", E_BCONF_MAP_BOOL }, + { "transport_url_%i", "url", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, + { NULL }, +}; + +static e_bconf_map_t account_map[] = { + { "account_name_%i", "name", E_BCONF_MAP_STRING }, + { "source_enabled_%i", "enabled", E_BCONF_MAP_BOOL }, + { NULL, "identity", E_BCONF_MAP_CHILD, identity_map }, + { NULL, "source", E_BCONF_MAP_CHILD, source_map }, + { NULL, "transport", E_BCONF_MAP_CHILD, transport_map }, + { "account_drafts_folder_uri_%i", "drafts-folder", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, + { "account_sent_folder_uri_%i", "sent-folder", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, + { NULL, "auto-cc", E_BCONF_MAP_CHILD, cc_map }, + { NULL, "auto-bcc", E_BCONF_MAP_CHILD, bcc_map }, + { NULL, "pgp", E_BCONF_MAP_CHILD, pgp_map }, + { NULL, "smime", E_BCONF_MAP_CHILD, smime_map }, + { NULL }, +}; + +/* /Mail/Signatures/ * */ +static e_bconf_map_t signature_format_map[] = { + { "text/plain", }, + { "text/html", }, + { NULL } +}; + +static e_bconf_map_t signature_map[] = { + { "name_%i", "name", E_BCONF_MAP_STRING }, + { "html_%i", "format", E_BCONF_MAP_ENUM, signature_format_map }, + { "filename_%i", "filename", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, + { "script_%i", "script", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, + { NULL }, +}; + +/* ********************************************************************** */ +/* Tables for bonobo conf -> gconf conversion */ +/* ********************************************************************** */ + +static e_gconf_map_t mail_accounts_map[] = { + /* /Mail/Accounts - most entries are processed via the xml blob routine */ + /* This also works because the initial uid mapping is 1:1 with the list order */ + { "default_account", "mail/default_account", E_GCONF_MAP_SIMPLESTRING }, + { 0 }, +}; + +static e_gconf_map_t mail_display_map[] = { + /* /Mail/Display */ + { "side_bar_search", "mail/display/side_bar_search", E_GCONF_MAP_BOOL }, + { "thread_list", "mail/display/thread_list", E_GCONF_MAP_BOOL }, + { "thread_subject", "mail/display/thread_subject", E_GCONF_MAP_BOOL }, + { "hide_deleted", "mail/display/show_deleted", E_GCONF_MAP_BOOLNOT }, + { "preview_pane", "mail/display/show_preview", E_GCONF_MAP_BOOL }, + { "paned_size", "mail/display/paned_size", E_GCONF_MAP_INT }, + { "seen_timeout", "mail/display/mark_seen_timeout", E_GCONF_MAP_INT }, + { "do_seen_timeout", "mail/display/mark_seen", E_GCONF_MAP_BOOL }, + { "http_images", "mail/display/load_http_images", E_GCONF_MAP_INT }, + { "citation_highlight", "mail/display/mark_citations", E_GCONF_MAP_BOOL }, + { "citation_color", "mail/display/citation_colour", E_GCONF_MAP_COLOUR }, + { 0 }, +}; + +static e_gconf_map_t mail_format_map[] = { + /* /Mail/Format */ + { "message_display_style", "mail/display/message_style", E_GCONF_MAP_INT }, + { "send_html", "mail/composer/send_html", E_GCONF_MAP_BOOL }, + { "default_reply_style", "mail/format/reply_style", E_GCONF_MAP_INT }, + { "default_forward_style", "mail/format/forward_style", E_GCONF_MAP_INT }, + { "default_charset", "mail/composer/charset", E_GCONF_MAP_STRING }, + { "confirm_unwanted_html", "mail/prompts/unwanted_html", E_GCONF_MAP_BOOL }, + { 0 }, +}; + +static e_gconf_map_t mail_trash_map[] = { + /* /Mail/Trash */ + { "empty_on_exit", "mail/trash/empty_on_exit", E_GCONF_MAP_BOOL }, + { 0 }, +}; + +static e_gconf_map_t mail_prompts_map[] = { + /* /Mail/Prompts */ + { "confirm_expunge", "mail/prompts/expunge", E_GCONF_MAP_BOOL }, + { "empty_subject", "mail/prompts/empty_subject", E_GCONF_MAP_BOOL }, + { "only_bcc", "mail/prompts/only_bcc", E_GCONF_MAP_BOOL }, + { 0 } +}; + +static e_gconf_map_t mail_filters_map[] = { + /* /Mail/Filters */ + { "log", "mail/filters/log", E_GCONF_MAP_BOOL }, + { "log_path", "mail/filters/logfile", E_GCONF_MAP_STRING }, + { 0 } +}; + +static e_gconf_map_t mail_notify_map[] = { + /* /Mail/Notify */ + { "new_mail_notification", "mail/notify/type", E_GCONF_MAP_INT }, + { "new_mail_notification_sound_file", "mail/notify/sound", E_GCONF_MAP_STRING }, + { 0 } +}; + +static e_gconf_map_t mail_filesel_map[] = { + /* /Mail/Filesel */ + { "last_filesel_dir", "mail/save_dir", E_GCONF_MAP_STRING }, + { 0 } +}; + +static e_gconf_map_t mail_composer_map[] = { + /* /Mail/Composer */ + { "ViewFrom", "mail/composer/view/From", E_GCONF_MAP_BOOL }, + { "ViewReplyTo", "mail/composer/view/ReplyTo", E_GCONF_MAP_BOOL }, + { "ViewCC", "mail/composer/view/Cc", E_GCONF_MAP_BOOL }, + { "ViewBCC", "mail/composer/view/Bcc", E_GCONF_MAP_BOOL }, + { "ViewSubject", "mail/composer/view/Subject", E_GCONF_MAP_BOOL }, + { 0 }, +}; + +/* ********************************************************************** */ + +static e_gconf_map_t importer_elm_map[] = { + /* /Importer/Elm */ + { "mail", "importer/elm/mail", E_GCONF_MAP_BOOL }, + { "mail-imported", "importer/elm/mail-imported", E_GCONF_MAP_BOOL }, + { 0 }, +}; + +static e_gconf_map_t importer_pine_map[] = { + /* /Importer/Pine */ + { "mail", "importer/elm/mail", E_GCONF_MAP_BOOL }, + { "address", "importer/elm/address", E_GCONF_MAP_BOOL }, + { 0 }, +}; + +static e_gconf_map_t importer_netscape_map[] = { + /* /Importer/Netscape */ + { "mail", "importer/netscape/mail", E_GCONF_MAP_BOOL }, + { "settings", "importer/netscape/settings", E_GCONF_MAP_BOOL }, + { "filters", "importer/netscape/filters", E_GCONF_MAP_BOOL }, + { 0 }, +}; + +/* ********************************************************************** */ + +static e_gconf_map_list_t gconf_remap_list[] = { + { "/Mail/Accounts", mail_accounts_map }, + { "/Mail/Display", mail_display_map }, + { "/Mail/Format", mail_format_map }, + { "/Mail/Trash", mail_trash_map }, + { "/Mail/Prompts", mail_prompts_map }, + { "/Mail/Filters", mail_filters_map }, + { "/Mail/Notify", mail_notify_map }, + { "/Mail/Filesel", mail_filesel_map }, + { "/Mail/Composer", mail_composer_map }, + + { "/Importer/Elm", importer_elm_map }, + { "/Importer/Pine", importer_pine_map }, + { "/Importer/Netscape", importer_netscape_map }, + + { 0 }, +}; + +static struct { + char *label; + char *colour; +} label_default[5] = { + { N_("Important"), "#EF2929" }, /* red */ + { N_("Work"), "#F57900" }, /* orange */ + { N_("Personal"), "#4E9A06" }, /* green */ + { N_("To Do"), "#3465A4" }, /* blue */ + { N_("Later"), "#75507B" } /* purple */ +}; + +/* remaps mail config from bconf to gconf */ +static gboolean +bconf_import(GConfClient *gconf, xmlDocPtr config_xmldb) +{ + xmlNodePtr source; + char labx[16], colx[16]; + char *val, *lab, *col; + GSList *list, *l; + int i; + + e_bconf_import(gconf, config_xmldb, gconf_remap_list); + + /* Labels: + label string + label colour as integer + -> label string:# colour as hex */ + source = e_bconf_get_path(config_xmldb, "/Mail/Labels"); + if (source) { + list = NULL; + for (i = 0; i < 5; i++) { + sprintf(labx, "label_%d", i); + sprintf(colx, "color_%d", i); + lab = e_bconf_get_string(source, labx); + if ((col = e_bconf_get_value(source, colx))) { + sprintf(colx, "#%06x", atoi(col) & 0xffffff); + g_free(col); + } else + strcpy(colx, label_default[i].colour); + + val = g_strdup_printf("%s:%s", lab ? lab : label_default[i].label, colx); + list = g_slist_append(list, val); + g_free(lab); + } + + gconf_client_set_list(gconf, "/apps/evolution/mail/labels", GCONF_VALUE_STRING, list, NULL); + while (list) { + l = list->next; + g_free(list->data); + g_slist_free_1(list); + list = l; + } + } else { + g_warning("could not find /Mail/Labels in old config database, skipping"); + } + + /* Accounts: The flat bonobo-config structure is remapped to a list of xml blobs. Upgrades as necessary */ + e_bconf_import_xml_blob(gconf, config_xmldb, account_map, "/Mail/Accounts", + "/apps/evolution/mail/accounts", "account", "uid"); + + /* Same for signatures */ + e_bconf_import_xml_blob(gconf, config_xmldb, signature_map, "/Mail/Signatures", + "/apps/evolution/mail/signatures", "signature", NULL); + + return TRUE; +} + +static gboolean +em_migrate_1_2(const char *data_dir, xmlDocPtr config_xmldb, xmlDocPtr filters, xmlDocPtr vfolders, GError **error) +{ + GConfClient *gconf; + + gconf = gconf_client_get_default(); + bconf_import(gconf, config_xmldb); + g_object_unref(gconf); + + em_upgrade_xml_1_2(filters); + em_upgrade_xml_1_2(vfolders); + + return TRUE; +} + +/* 1.4 upgrade functions */ + +#define EM_MIGRATE_SESSION_TYPE (em_migrate_session_get_type ()) +#define EM_MIGRATE_SESSION(obj) (CAMEL_CHECK_CAST((obj), EM_MIGRATE_SESSION_TYPE, EMMigrateSession)) +#define EM_MIGRATE_SESSION_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), EM_MIGRATE_SESSION_TYPE, EMMigrateSessionClass)) +#define EM_MIGRATE_IS_SESSION(o) (CAMEL_CHECK_TYPE((o), EM_MIGRATE_SESSION_TYPE)) + +typedef struct _EMMigrateSession { + CamelSession parent_object; + + CamelStore *store; /* new folder tree store */ + char *srcdir; /* old folder tree path */ +} EMMigrateSession; + +typedef struct _EMMigrateSessionClass { + CamelSessionClass parent_class; + +} EMMigrateSessionClass; + +static CamelType em_migrate_session_get_type (void); +static CamelSession *em_migrate_session_new (const char *path); + +static void +class_init (EMMigrateSessionClass *klass) +{ + ; +} + +static CamelType +em_migrate_session_get_type (void) +{ + static CamelType type = CAMEL_INVALID_TYPE; + + if (type == CAMEL_INVALID_TYPE) { + type = camel_type_register ( + camel_session_get_type (), + "EMMigrateSession", + sizeof (EMMigrateSession), + sizeof (EMMigrateSessionClass), + (CamelObjectClassInitFunc) class_init, + NULL, + NULL, + NULL); + } + + return type; +} + +static CamelSession * +em_migrate_session_new (const char *path) +{ + CamelSession *session; + + session = CAMEL_SESSION (camel_object_new (EM_MIGRATE_SESSION_TYPE)); + + camel_session_construct (session, path); + + return session; +} + + +#endif /* !G_OS_WIN32 */ + +static GtkWidget *window; +static GtkLabel *label; +static GtkProgressBar *progress; + +static void +em_migrate_setup_progress_dialog (const char *desc) +{ + GtkWidget *vbox, *hbox, *w; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title ((GtkWindow *) window, _("Migrating...")); + gtk_window_set_modal ((GtkWindow *) window, TRUE); + gtk_container_set_border_width ((GtkContainer *) window, 6); + + vbox = gtk_vbox_new (FALSE, 6); + gtk_widget_show (vbox); + gtk_container_add ((GtkContainer *) window, vbox); + + 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); + + hbox = gtk_hbox_new (FALSE, 6); + gtk_widget_show (hbox); + gtk_box_pack_start_defaults ((GtkBox *) vbox, hbox); + + label = (GtkLabel *) gtk_label_new (""); + gtk_widget_show ((GtkWidget *) label); + gtk_box_pack_start_defaults ((GtkBox *) hbox, (GtkWidget *) label); + + progress = (GtkProgressBar *) gtk_progress_bar_new (); + gtk_widget_show ((GtkWidget *) progress); + gtk_box_pack_start_defaults ((GtkBox *) hbox, (GtkWidget *) progress); + + gtk_widget_show (window); +} + +static void +em_migrate_close_progress_dialog (void) +{ + gtk_widget_destroy ((GtkWidget *) window); +} + +static void +em_migrate_set_folder_name (const char *folder_name) +{ + char *text; + + 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 (); +} + +static void +em_migrate_set_progress (double percent) +{ + char text[5]; + + snprintf (text, sizeof (text), "%d%%", (int) (percent * 100.0f)); + + gtk_progress_bar_set_fraction (progress, percent); + gtk_progress_bar_set_text (progress, text); + + while (gtk_events_pending ()) + gtk_main_iteration (); +} + +#ifndef G_OS_WIN32 + +static gboolean +is_mail_folder (const char *metadata) +{ + xmlNodePtr node; + xmlDocPtr doc; + char *type; + + if (!(doc = xmlParseFile (metadata))) { + g_warning ("Cannot parse `%s'", metadata); + return FALSE; + } + + if (!(node = xmlDocGetRootElement (doc))) { + g_warning ("`%s' corrupt: document contains no root node", metadata); + xmlFreeDoc (doc); + return FALSE; + } + + if (!node->name || strcmp ((char *)node->name, "efolder") != 0) { + g_warning ("`%s' corrupt: root node is not 'efolder'", metadata); + xmlFreeDoc (doc); + return FALSE; + } + + node = node->children; + while (node != NULL) { + if (node->name && !strcmp ((char *)node->name, "type")) { + type = (char *)xmlNodeGetContent (node); + if (!strcmp ((char *)type, "mail")) { + xmlFreeDoc (doc); + xmlFree (type); + + return TRUE; + } + + xmlFree (type); + + break; + } + + node = node->next; + } + + xmlFreeDoc (doc); + + return FALSE; +} + +static gboolean +get_local_et_expanded (const char *dirname) +{ + xmlNodePtr node; + xmlDocPtr doc; + struct stat st; + char *buf, *p; + int thread_list; + + buf = g_strdup_printf ("%s/evolution/config/file:%s", g_get_home_dir (), dirname); + p = buf + strlen (g_get_home_dir ()) + strlen ("/evolution/config/file:"); + e_filename_make_safe (p); + + if (stat (buf, &st) == -1) { + g_free (buf); + return FALSE; + } + + if (!(doc = xmlParseFile (buf))) { + g_free (buf); + return FALSE; + } + + g_free (buf); + + if (!(node = xmlDocGetRootElement (doc)) || strcmp ((char *)node->name, "expanded_state") != 0) { + xmlFreeDoc (doc); + return FALSE; + } + + if (!(buf = (char *)xmlGetProp (node, (const unsigned char *)"default"))) { + xmlFreeDoc (doc); + return FALSE; + } + + thread_list = strcmp (buf, "0") == 0 ? 0 : 1; + xmlFree (buf); + + xmlFreeDoc (doc); + + return thread_list; +} + +static char * +get_local_store_uri (const char *dirname, char **namep, int *indexp) +{ + char *protocol, *name, *metadata, *tmp; + int index; + struct stat st; + xmlNodePtr node; + xmlDocPtr doc; + + metadata = g_build_filename(dirname, "local-metadata.xml", NULL); + + /* in 1.4, any errors are treated as defaults, this function cannot fail */ + + /* defaults */ + name = "mbox"; + protocol = "mbox"; + index = TRUE; + + if (stat (metadata, &st) == -1 || !S_ISREG (st.st_mode)) + goto nofile; + + doc = xmlParseFile(metadata); + if (doc == NULL) + goto nofile; + + node = doc->children; + if (strcmp((char *)node->name, "folderinfo")) + goto dodefault; + + for (node = node->children; node; node = node->next) { + if (node->name && !strcmp ((char *)node->name, "folder")) { + tmp = (char *)xmlGetProp (node, (const unsigned char *)"type"); + if (tmp) { + protocol = alloca(strlen(tmp)+1); + strcpy(protocol, tmp); + xmlFree(tmp); + } + tmp = (char *)xmlGetProp (node, (const unsigned char *)"name"); + if (tmp) { + name = alloca(strlen(tmp)+1); + strcpy(name, tmp); + xmlFree(tmp); + } + tmp = (char *)xmlGetProp (node, (const unsigned char *)"index"); + if (tmp) { + index = atoi(tmp); + xmlFree(tmp); + } + } + } +dodefault: + xmlFreeDoc (doc); +nofile: + g_free(metadata); + + *namep = g_strdup(name); + *indexp = index; + + return g_strdup_printf("%s:%s", protocol, dirname); +} + +#endif /* !G_OS_WIN32 */ + +enum { + CP_UNIQUE = 0, + CP_OVERWRITE, + CP_APPEND, +}; + +static int open_flags[3] = { + O_WRONLY | O_CREAT | O_TRUNC, + O_WRONLY | O_CREAT | O_TRUNC, + O_WRONLY | O_CREAT | O_APPEND, +}; + +static gboolean +cp (const char *src, const char *dest, gboolean show_progress, int mode) +{ + unsigned char readbuf[65536]; + ssize_t nread, nwritten; + int errnosav, readfd, writefd; + size_t total = 0; + struct stat st; + struct utimbuf ut; + + /* if the dest file exists and has content, abort - we don't + * want to corrupt their existing data */ + if (g_stat (dest, &st) == 0 && st.st_size > 0 && mode == CP_UNIQUE) { + errno = EEXIST; + return FALSE; + } + + if (g_stat (src, &st) == -1 + || (readfd = g_open (src, O_RDONLY | O_BINARY, 0)) == -1) + return FALSE; + + if ((writefd = g_open (dest, open_flags[mode] | O_BINARY, 0666)) == -1) { + errnosav = errno; + close (readfd); + errno = errnosav; + return FALSE; + } + + do { + do { + nread = read (readfd, readbuf, sizeof (readbuf)); + } while (nread == -1 && errno == EINTR); + + if (nread == 0) + break; + else if (nread < 0) + goto exception; + + do { + nwritten = write (writefd, readbuf, nread); + } while (nwritten == -1 && errno == EINTR); + + if (nwritten < nread) + goto exception; + + total += nwritten; + if (show_progress) + em_migrate_set_progress (((double) total) / ((double) st.st_size)); + } while (total < st.st_size); + + if (fsync (writefd) == -1) + goto exception; + + close (readfd); + if (close (writefd) == -1) + goto failclose; + + ut.actime = st.st_atime; + ut.modtime = st.st_mtime; + utime (dest, &ut); + chmod (dest, st.st_mode); + + return TRUE; + + exception: + + errnosav = errno; + close (readfd); + close (writefd); + errno = errnosav; + + failclose: + + errnosav = errno; + unlink (dest); + errno = errnosav; + + return FALSE; +} + +#ifndef G_OS_WIN32 + +static gboolean +cp_r (const char *src, const char *dest, const char *pattern, int mode) +{ + GString *srcpath, *destpath; + struct dirent *dent; + size_t slen, dlen; + struct stat st; + DIR *dir; + + if (g_mkdir_with_parents (dest, 0777) == -1) + return FALSE; + + if (!(dir = opendir (src))) + return FALSE; + + srcpath = g_string_new (src); + g_string_append_c (srcpath, '/'); + slen = srcpath->len; + + destpath = g_string_new (dest); + g_string_append_c (destpath, '/'); + dlen = destpath->len; + + while ((dent = readdir (dir))) { + if (!strcmp (dent->d_name, ".") || !strcmp (dent->d_name, "..")) + continue; + + g_string_truncate (srcpath, slen); + g_string_truncate (destpath, dlen); + + g_string_append (srcpath, dent->d_name); + g_string_append (destpath, dent->d_name); + + if (stat (srcpath->str, &st) == -1) + continue; + + if (S_ISDIR (st.st_mode)) { + cp_r (srcpath->str, destpath->str, pattern, mode); + } else if (!pattern || !strcmp (dent->d_name, pattern)) { + cp (srcpath->str, destpath->str, FALSE, mode); + } + } + + closedir (dir); + + g_string_free (destpath, TRUE); + g_string_free (srcpath, TRUE); + + return TRUE; +} + +static void +mbox_build_filename (GString *path, const char *toplevel_dir, const char *full_name) +{ + const char *start, *inptr = full_name; + int subdirs = 0; + + while (*inptr != '\0') { + if (*inptr == '/') + subdirs++; + inptr++; + } + + g_string_assign(path, toplevel_dir); + g_string_append_c (path, '/'); + + inptr = full_name; + while (*inptr != '\0') { + start = inptr; + while (*inptr != '/' && *inptr != '\0') + inptr++; + + g_string_append_len (path, start, inptr - start); + + if (*inptr == '/') { + g_string_append (path, ".sbd/"); + inptr++; + + /* strip extranaeous '/'s */ + while (*inptr == '/') + inptr++; + } + } +} + +static gboolean +em_migrate_folder(EMMigrateSession *session, const char *dirname, const char *full_name, GError **error) +{ + CamelFolder *old_folder = NULL, *new_folder = NULL; + CamelStore *local_store = NULL; + CamelException ex; + char *name, *uri; + GPtrArray *uids; + struct stat st; + gboolean thread_list; + int index, i; + GString *src, *dest; + gboolean success = FALSE; + + camel_exception_init (&ex); + + src = g_string_new(""); + + g_string_printf(src, "%s/folder-metadata.xml", dirname); + if (stat (src->str, &st) == -1 + || !S_ISREG (st.st_mode) + || !is_mail_folder(src->str)) { + /* Not an evolution mail folder */ + g_string_free(src, TRUE); + return TRUE; + } + + dest = g_string_new(""); + uri = get_local_store_uri(dirname, &name, &index); + em_migrate_set_folder_name (full_name); + thread_list = get_local_et_expanded (dirname); + + /* Manually copy local mbox files, its much faster */ + if (!strncmp (uri, "mbox:", 5)) { + static char *meta_ext[] = { ".summary", ".ibex.index", ".ibex.index.data" }; + size_t slen, dlen; + FILE *fp; + char *p; + int mode; + + g_string_printf (src, "%s/%s", uri + 5, name); + mbox_build_filename (dest, ((CamelService *)session->store)->url->path, full_name); + p = strrchr (dest->str, '/'); + *p = '\0'; + + slen = src->len; + dlen = dest->len; + + if (g_mkdir_with_parents (dest->str, 0777) == -1 && errno != EEXIST) { + g_set_error ( + error, E_SHELL_MIGRATE_ERROR, + E_SHELL_MIGRATE_ERROR_FAILED, + _("Unable to create new folder `%s': %s"), + dest->str, g_strerror (errno)); + goto fatal; + } + + *p = '/'; + mode = CP_UNIQUE; + retry_copy: + if (!cp (src->str, dest->str, TRUE, mode)) { + if (errno == EEXIST) { + int save = errno; + + switch (e_error_run(NULL, "mail:ask-migrate-existing", src->str, dest->str, NULL)) { + case GTK_RESPONSE_ACCEPT: + mode = CP_OVERWRITE; + goto retry_copy; + case GTK_RESPONSE_OK: + mode = CP_APPEND; + goto retry_copy; + case GTK_RESPONSE_REJECT: + goto ignore; + } + + errno = save; + } + g_set_error ( + error, E_SHELL_MIGRATE_ERROR, + E_SHELL_MIGRATE_ERROR_FAILED, + _("Unable to copy folder `%s' to `%s': %s"), + src->str, dest->str, g_strerror (errno)); + goto fatal; + } + ignore: + + /* create a .cmeta file specifying to index and/or thread the folder */ + g_string_truncate (dest, dlen); + g_string_append (dest, ".cmeta"); + if ((fp = fopen (dest->str, "w")) != NULL) { + int fd = fileno (fp); + + /* write the magic string */ + if (fwrite ("CLMD", 4, 1, fp) != 1) + goto cmeta_err; + + /* write the version (1) */ + if (camel_file_util_encode_uint32 (fp, 1) == -1) + goto cmeta_err; + + /* write the meta count */ + if (camel_file_util_encode_uint32 (fp, thread_list ? 1 : 0) == -1) + goto cmeta_err; + + if (!thread_list) { + if (camel_file_util_encode_string (fp, "evolution:thread_list") == -1) + goto cmeta_err; + + if (camel_file_util_encode_string (fp, !thread_list ? "1" : "0") == -1) + goto cmeta_err; + } + + /* write the prop count (only prop is the index prop) */ + if (camel_file_util_encode_uint32 (fp, 1) == -1) + goto cmeta_err; + + /* write the index prop tag (== CAMEL_FOLDER_ARG_LAST|CAMEL_ARG_BOO) */ + if (camel_file_util_encode_uint32 (fp, CAMEL_FOLDER_ARG_LAST|CAMEL_ARG_BOO) == -1) + goto cmeta_err; + + /* write the index prop value */ + if (camel_file_util_encode_uint32 (fp, 1) == -1) + goto cmeta_err; + + fflush (fp); + + if (fsync (fd) == -1) { + cmeta_err: + fclose (fp); + unlink (dest->str); + } else { + fclose (fp); + } + } + + /* copy over the metadata files */ + for (i = 0; i < sizeof(meta_ext)/sizeof(meta_ext[0]); i++) { + g_string_truncate (src, slen); + g_string_truncate (dest, dlen); + + g_string_append (src, meta_ext[i]); + g_string_append (dest, meta_ext[i]); + cp (src->str, dest->str, FALSE, CP_OVERWRITE); + } + } else { + guint32 flags = CAMEL_STORE_FOLDER_CREATE; + + if (!(local_store = camel_session_get_store ((CamelSession *) session, uri, &ex)) + || !(old_folder = camel_store_get_folder (local_store, name, 0, &ex))) + goto fatal; + + flags |= (index ? CAMEL_STORE_FOLDER_BODY_INDEX : 0); + if (!(new_folder = camel_store_get_folder (session->store, full_name, flags, &ex))) + goto fatal; + + if (!thread_list) { + camel_object_meta_set (new_folder, "evolution:thread_list", !thread_list ? "1" : "0"); + camel_object_state_write (new_folder); + } + + uids = camel_folder_get_uids (old_folder); + for (i = 0; i < uids->len; i++) { + CamelMimeMessage *message; + CamelMessageInfo *info; + + if (!(info = camel_folder_get_message_info (old_folder, uids->pdata[i]))) + continue; + + if (!(message = camel_folder_get_message (old_folder, uids->pdata[i], &ex))) { + camel_folder_free_message_info (old_folder, info); + camel_folder_free_uids (old_folder, uids); + goto fatal; + } + + camel_folder_append_message (new_folder, message, info, NULL, &ex); + camel_folder_free_message_info (old_folder, info); + camel_object_unref (message); + + if (camel_exception_is_set (&ex)) + break; + + em_migrate_set_progress (((double) i + 1) / ((double) uids->len)); + } + + camel_folder_free_uids (old_folder, uids); + + if (camel_exception_is_set (&ex)) + goto fatal; + } + success = TRUE; +fatal: + g_free (uri); + g_free (name); + g_string_free(src, TRUE); + g_string_free(dest, TRUE); + if (local_store) + camel_object_unref(local_store); + if (old_folder) + camel_object_unref(old_folder); + if (new_folder) + camel_object_unref(new_folder); + + if (camel_exception_is_set (&ex)) { + g_set_error ( + error, E_SHELL_MIGRATE_ERROR, + E_SHELL_MIGRATE_ERROR_FAILED, + "%s", camel_exception_get_description (&ex)); + camel_exception_clear (&ex); + } + + return success; +} + +static gboolean +em_migrate_dir (EMMigrateSession *session, const char *dirname, const char *full_name, GError **error) +{ + char *path; + DIR *dir; + struct stat st; + struct dirent *dent; + gboolean success = TRUE; + + if (!em_migrate_folder(session, dirname, full_name, error)) + return FALSE; + + /* no subfolders, not readable, don't care */ + path = g_strdup_printf ("%s/subfolders", dirname); + if (stat (path, &st) == -1 || !S_ISDIR (st.st_mode)) { + g_free (path); + return TRUE; + } + + if (!(dir = opendir (path))) { + g_free (path); + return TRUE; + } + + while (success && (dent = readdir (dir))) { + char *full_path; + char *name; + + if (dent->d_name[0] == '.') + continue; + + full_path = g_strdup_printf ("%s/%s", path, dent->d_name); + if (stat (full_path, &st) == -1 || !S_ISDIR (st.st_mode)) { + g_free (full_path); + continue; + } + + name = g_strdup_printf ("%s/%s", full_name, dent->d_name); + success = em_migrate_dir (session, full_path, name, error); + g_free (full_path); + g_free (name); + } + + closedir (dir); + + g_free (path); + + return success; +} + +static gboolean +em_migrate_local_folders_1_4 (EMMigrateSession *session, GError **error) +{ + struct dirent *dent; + struct stat st; + DIR *dir; + gboolean success = TRUE; + + if (!(dir = opendir (session->srcdir))) { + g_set_error ( + error, E_SHELL_MIGRATE_ERROR, + E_SHELL_MIGRATE_ERROR_FAILED, + _("Unable to scan for existing mailboxes at " + "`%s': %s"), session->srcdir, g_strerror (errno)); + return FALSE; + } + + 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 (success && (dent = readdir (dir))) { + char *full_path; + + if (dent->d_name[0] == '.') + continue; + + full_path = g_strdup_printf ("%s/%s", session->srcdir, dent->d_name); + if (stat (full_path, &st) == -1 || !S_ISDIR (st.st_mode)) { + g_free (full_path); + continue; + } + + success = em_migrate_dir (session, full_path, dent->d_name, error); + g_free (full_path); + } + + closedir (dir); + + em_migrate_close_progress_dialog (); + + return success; +} + +static char * +upgrade_xml_uris_1_4 (const char *uri) +{ + char *path, *prefix, *p; + CamelURL *url; + + if (!strncmp (uri, "file:", 5)) { + url = camel_url_new (uri, NULL); + camel_url_set_protocol (url, "email"); + camel_url_set_user (url, "local"); + camel_url_set_host (url, "local"); + + prefix = g_build_filename (g_get_home_dir (), "evolution", "local", NULL); + if (strncmp (url->path, prefix, strlen (prefix)) != 0) { + /* uri is busticated - user probably copied from another user's home directory */ + camel_url_free (url); + g_free (prefix); + + return g_strdup (uri); + } + path = g_strdup (url->path + strlen (prefix)); + g_free (prefix); + + /* modify the path in-place */ + p = path + strlen (path) - 12; + while (p > path) { + if (!strncmp (p, "/subfolders/", 12)) + memmove (p, p + 11, strlen (p + 11) + 1); + + p--; + } + + camel_url_set_path (url, path); + g_free (path); + + path = camel_url_to_string (url, 0); + camel_url_free (url); + + return path; + } else { + return em_uri_from_camel (uri); + } +} + +static void +upgrade_vfolder_sources_1_4 (xmlDocPtr doc) +{ + xmlNodePtr root, node; + + if (!doc || !(root = xmlDocGetRootElement (doc))) + return; + + if (!root->name || strcmp ((char *)root->name, "filteroptions") != 0) { + /* root node is not , nothing to upgrade */ + return; + } + + if (!(node = xml_find_node (root, "ruleset"))) { + /* no ruleset node, nothing to upgrade */ + return; + } + + node = node->children; + while (node != NULL) { + if (node->name && !strcmp ((char *)node->name, "rule")) { + xmlNodePtr sources; + char *src; + + if (!(src = (char *)xmlGetProp (node, (const unsigned char *)"source"))) + src = (char *)xmlStrdup ((const unsigned char *)"local"); /* default to all local folders? */ + + xmlSetProp (node, (const unsigned char *)"source", (const unsigned char *)"incoming"); + + if (!(sources = xml_find_node (node, "sources"))) + sources = xmlNewChild (node, NULL, (const unsigned char *)"sources", NULL); + + xmlSetProp (sources, (const unsigned char *)"with", (unsigned char *)src); + xmlFree (src); + } + + node = node->next; + } +} + +static char * +get_nth_sig (int id) +{ + ESignatureList *list; + ESignature *sig; + EIterator *iter; + char *uid = NULL; + int i = 0; + + list = e_get_signature_list (); + iter = e_list_get_iterator ((EList *) list); + + while (e_iterator_is_valid (iter) && i < id) { + e_iterator_next (iter); + i++; + } + + if (i == id && e_iterator_is_valid (iter)) { + sig = (ESignature *) e_iterator_get (iter); + uid = g_strdup (sig->uid); + } + + g_object_unref (iter); + + return uid; +} + +static void +em_upgrade_accounts_1_4 (void) +{ + EAccountList *accounts; + EIterator *iter; + + if (!(accounts = e_get_account_list ())) + return; + + iter = e_list_get_iterator ((EList *) accounts); + while (e_iterator_is_valid (iter)) { + EAccount *account = (EAccount *) e_iterator_get (iter); + char *url; + + if (account->drafts_folder_uri) { + url = upgrade_xml_uris_1_4 (account->drafts_folder_uri); + g_free (account->drafts_folder_uri); + account->drafts_folder_uri = url; + } + + if (account->sent_folder_uri) { + url = upgrade_xml_uris_1_4 (account->sent_folder_uri); + g_free (account->sent_folder_uri); + account->sent_folder_uri = url; + } + + if (account->id->sig_uid && !strncmp (account->id->sig_uid, "::", 2)) { + int sig_id; + + sig_id = strtol (account->id->sig_uid + 2, NULL, 10); + g_free (account->id->sig_uid); + account->id->sig_uid = get_nth_sig (sig_id); + } + + e_iterator_next (iter); + } + + g_object_unref (iter); + + e_account_list_save (accounts); +} + +static gboolean +em_migrate_pop_uid_caches_1_4 (const char *data_dir, GError **error) +{ + GString *oldpath, *newpath; + struct dirent *dent; + size_t olen, nlen; + char *cache_dir; + DIR *dir; + gboolean success = TRUE; + + /* Sigh, too many unique strings to translate, for cases which shouldn't ever happen */ + + /* open the old cache dir */ + cache_dir = g_build_filename (g_get_home_dir (), "evolution", "mail", "pop3", NULL); + if (!(dir = opendir (cache_dir))) { + if (errno == ENOENT) { + g_free(cache_dir); + return TRUE; + } + + g_set_error ( + error, E_SHELL_MIGRATE_ERROR, + E_SHELL_MIGRATE_ERROR_FAILED, + _("Unable to open old POP keep-on-server data " + "`%s': %s"), cache_dir, g_strerror (errno)); + g_free (cache_dir); + return FALSE; + } + + oldpath = g_string_new (cache_dir); + g_string_append_c (oldpath, '/'); + olen = oldpath->len; + g_free (cache_dir); + + cache_dir = g_build_filename (data_dir, "pop", NULL); + if (g_mkdir_with_parents (cache_dir, 0777) == -1) { + g_set_error ( + error, E_SHELL_MIGRATE_ERROR, + E_SHELL_MIGRATE_ERROR_FAILED, + _("Unable to create POP3 keep-on-server data " + "directory `%s': %s"), cache_dir, + g_strerror (errno)); + g_string_free (oldpath, TRUE); + g_free (cache_dir); + closedir (dir); + return FALSE; + } + + newpath = g_string_new (cache_dir); + g_string_append_c (newpath, '/'); + nlen = newpath->len; + g_free (cache_dir); + + while (success && (dent = readdir (dir))) { + if (strncmp (dent->d_name, "cache-pop:__", 12) != 0) + continue; + + g_string_truncate (oldpath, olen); + g_string_truncate (newpath, nlen); + + g_string_append (oldpath, dent->d_name); + g_string_append (newpath, dent->d_name + 12); + + /* strip the trailing '_' */ + g_string_truncate (newpath, newpath->len - 1); + + if (g_mkdir_with_parents (newpath->str, 0777) == -1 + || !cp(oldpath->str, (g_string_append(newpath, "/uid-cache"))->str, FALSE, CP_UNIQUE)) { + g_set_error ( + error, E_SHELL_MIGRATE_ERROR, + E_SHELL_MIGRATE_ERROR_FAILED, + _("Unable to copy POP3 keep-on-server data " + "`%s': %s"), oldpath->str, + g_strerror (errno)); + success = FALSE; + } + + } + + g_string_free (oldpath, TRUE); + g_string_free (newpath, TRUE); + + closedir (dir); + + return success; +} + +static gboolean +em_migrate_imap_caches_1_4 (const char *data_dir, GError **error) +{ + char *src, *dest; + struct stat st; + + src = g_build_filename (g_get_home_dir (), "evolution", "mail", "imap", NULL); + if (stat (src, &st) == -1 || !S_ISDIR (st.st_mode)) { + g_free (src); + return TRUE; + } + + dest = g_build_filename (data_dir, "imap", NULL); + + /* we don't care if this fails, it's only a cache... */ + cp_r (src, dest, "summary", CP_OVERWRITE); + + g_free (dest); + g_free (src); + + return TRUE; +} + +static gboolean +em_migrate_folder_expand_state_1_4 (const char *data_dir, GError **error) +{ + GString *srcpath, *destpath; + size_t slen, dlen, rlen; + char *evo14_mbox_root; + struct dirent *dent; + struct stat st; + DIR *dir; + + srcpath = g_string_new (g_get_home_dir ()); + g_string_append (srcpath, "/evolution/config"); + if (stat (srcpath->str, &st) == -1 || !S_ISDIR (st.st_mode)) { + g_string_free (srcpath, TRUE); + return TRUE; + } + + destpath = g_string_new (data_dir); + g_string_append (destpath, "/config"); + if (g_mkdir_with_parents (destpath->str, 0777) == -1 || !(dir = opendir (srcpath->str))) { + g_string_free (destpath, TRUE); + g_string_free (srcpath, TRUE); + return TRUE; + } + + g_string_append (srcpath, "/et-expanded-"); + slen = srcpath->len; + g_string_append (destpath, "/et-expanded-"); + dlen = destpath->len; + + evo14_mbox_root = g_build_filename (g_get_home_dir (), "evolution", "local", NULL); + e_filename_make_safe (evo14_mbox_root); + rlen = strlen (evo14_mbox_root); + evo14_mbox_root = g_realloc (evo14_mbox_root, rlen + 2); + evo14_mbox_root[rlen++] = '_'; + evo14_mbox_root[rlen] = '\0'; + + while ((dent = readdir (dir))) { + char *full_name, *inptr, *buf = NULL; + const char *filename; + GString *new; + + if (strncmp (dent->d_name, "et-expanded-", 12) != 0) + continue; + + if (!strncmp (dent->d_name + 12, "file:", 5)) { + /* need to munge the filename */ + inptr = dent->d_name + 17; + + if (!strncmp (inptr, evo14_mbox_root, rlen)) { + /* this should always be the case afaik... */ + inptr += rlen; + new = g_string_new ("mbox:"); + g_string_append_printf (new, "%s/local#", data_dir); + + full_name = g_strdup (inptr); + inptr = full_name + strlen (full_name) - 12; + while (inptr > full_name) { + if (!strncmp (inptr, "_subfolders_", 12)) + memmove (inptr, inptr + 11, strlen (inptr + 11) + 1); + + inptr--; + } + + g_string_append (new, full_name); + g_free (full_name); + + filename = buf = new->str; + g_string_free (new, FALSE); + e_filename_make_safe (buf); + } else { + /* but just in case... */ + filename = dent->d_name + 12; + } + } else { + /* no munging needed */ + filename = dent->d_name + 12; + } + + g_string_append (srcpath, dent->d_name + 12); + g_string_append (destpath, filename); + g_free (buf); + + cp (srcpath->str, destpath->str, FALSE, CP_UNIQUE); + + g_string_truncate (srcpath, slen); + g_string_truncate (destpath, dlen); + } + + closedir (dir); + + g_free (evo14_mbox_root); + g_string_free (destpath, TRUE); + g_string_free (srcpath, TRUE); + + return TRUE; +} + +static gboolean +em_migrate_folder_view_settings_1_4 (const char *data_dir, GError **error) +{ + GString *srcpath, *destpath; + size_t slen, dlen, rlen; + char *evo14_mbox_root; + struct dirent *dent; + struct stat st; + DIR *dir; + + srcpath = g_string_new (g_get_home_dir ()); + g_string_append (srcpath, "/evolution/views/mail"); + if (stat (srcpath->str, &st) == -1 || !S_ISDIR (st.st_mode)) { + g_string_free (srcpath, TRUE); + return TRUE; + } + + destpath = g_string_new (data_dir); + g_string_append (destpath, "/views"); + if (g_mkdir_with_parents (destpath->str, 0777) == -1 || !(dir = opendir (srcpath->str))) { + g_string_free (destpath, TRUE); + g_string_free (srcpath, TRUE); + return TRUE; + } + + g_string_append_c (srcpath, '/'); + slen = srcpath->len; + g_string_append_c (destpath, '/'); + dlen = destpath->len; + + evo14_mbox_root = g_build_filename (g_get_home_dir (), "evolution", "local", NULL); + e_filename_make_safe (evo14_mbox_root); + rlen = strlen (evo14_mbox_root); + evo14_mbox_root = g_realloc (evo14_mbox_root, rlen + 2); + evo14_mbox_root[rlen++] = '_'; + evo14_mbox_root[rlen] = '\0'; + + while ((dent = readdir (dir))) { + char *full_name, *inptr, *buf = NULL; + const char *filename, *ext; + size_t prelen = 0; + GString *new; + + if (dent->d_name[0] == '.') + continue; + + if (!(ext = strrchr (dent->d_name, '.'))) + continue; + + if (!strcmp (ext, ".galview") || !strcmp ((char *)dent->d_name, "galview.xml")) { + /* just copy the file */ + filename = dent->d_name; + goto copy; + } else if (strcmp (ext, ".xml") != 0) { + continue; + } + + if (!strncmp ((const char *)dent->d_name, "current_view-", 13)) { + prelen = 13; + } else if (!strncmp ((const char *)dent->d_name, "custom_view-", 12)) { + prelen = 12; + } else { + /* huh? wtf is this file? */ + continue; + } + + if (!strncmp (dent->d_name + prelen, "file:", 5)) { + /* need to munge the filename */ + inptr = dent->d_name + prelen + 5; + + if (!strncmp (inptr, evo14_mbox_root, rlen)) { + /* this should always be the case afaik... */ + inptr += rlen; + new = g_string_new ("mbox:"); + g_string_append_printf (new, "%s/local#", data_dir); + + full_name = g_strdup (inptr); + inptr = full_name + strlen (full_name) - 12; + while (inptr > full_name) { + if (!strncmp (inptr, "_subfolders_", 12)) + memmove (inptr, inptr + 11, strlen (inptr + 11) + 1); + + inptr--; + } + + g_string_append (new, full_name); + g_free (full_name); + + filename = buf = new->str; + g_string_free (new, FALSE); + e_filename_make_safe (buf); + } else { + /* but just in case... */ + filename = dent->d_name + prelen; + } + } else { + /* no munging needed */ + filename = dent->d_name + prelen; + } + + copy: + g_string_append (srcpath, dent->d_name); + if (prelen > 0) + g_string_append_len (destpath, dent->d_name, prelen); + g_string_append (destpath, filename); + g_free (buf); + + cp (srcpath->str, destpath->str, FALSE, CP_UNIQUE); + + g_string_truncate (srcpath, slen); + g_string_truncate (destpath, dlen); + } + + closedir (dir); + + g_free (evo14_mbox_root); + g_string_free (destpath, TRUE); + g_string_free (srcpath, TRUE); + + return TRUE; +} + +#define SUBFOLDER_DIR_NAME "subfolders" +#define SUBFOLDER_DIR_NAME_LEN 10 + +static char * +e_path_to_physical (const char *prefix, const char *vpath) +{ + const char *p, *newp; + char *dp; + char *ppath; + int ppath_len; + int prefix_len; + + while (*vpath == '/') + vpath++; + if (!prefix) + prefix = ""; + + /* Calculate the length of the real path. */ + ppath_len = strlen (vpath); + ppath_len++; /* For the ending zero. */ + + prefix_len = strlen (prefix); + ppath_len += prefix_len; + ppath_len++; /* For the separating slash. */ + + /* Take account of the fact that we need to translate every + * separator into `subfolders/'. + */ + p = vpath; + while (1) { + newp = strchr (p, '/'); + if (newp == NULL) + break; + + ppath_len += SUBFOLDER_DIR_NAME_LEN; + ppath_len++; /* For the separating slash. */ + + /* Skip consecutive slashes. */ + while (*newp == '/') + newp++; + + p = newp; + }; + + ppath = g_malloc (ppath_len); + dp = ppath; + + memcpy (dp, prefix, prefix_len); + dp += prefix_len; + *(dp++) = '/'; + + /* Copy the mangled path. */ + p = vpath; + while (1) { + newp = strchr (p, '/'); + if (newp == NULL) { + strcpy (dp, p); + break; + } + + memcpy (dp, p, newp - p + 1); /* `+ 1' to copy the slash too. */ + dp += newp - p + 1; + + memcpy (dp, SUBFOLDER_DIR_NAME, SUBFOLDER_DIR_NAME_LEN); + dp += SUBFOLDER_DIR_NAME_LEN; + + *(dp++) = '/'; + + /* Skip consecutive slashes. */ + while (*newp == '/') + newp++; + + p = newp; + } + + return ppath; +} + +static gboolean +em_migrate_imap_cmeta_1_4(const char *data_dir, GError **error) +{ + GConfClient *gconf; + GSList *paths, *p; + EAccountList *accounts; + const EAccount *account; + + if (!(accounts = e_get_account_list ())) + return TRUE; + + gconf = gconf_client_get_default(); + paths = gconf_client_get_list(gconf, "/apps/evolution/shell/offline/folder_paths", GCONF_VALUE_STRING, NULL); + for (p = paths;p;p = g_slist_next(p)) { + char *name, *path; + + name = p->data; + if (*name) + name++; + path = strchr(name, '/'); + if (path) { + *path++ = 0; + account = e_account_list_find(accounts, E_ACCOUNT_FIND_NAME, name); + if (account && !strncmp(account->source->url, "imap:", 5)) { + CamelURL *url = camel_url_new(account->source->url, NULL); + + if (url) { + char *dir, *base; + + base = g_strdup_printf("%s/imap/%s@%s/folders", + data_dir, + url->user?url->user:"", + url->host?url->host:""); + + dir = e_path_to_physical(base, path); + if (g_mkdir_with_parents(dir, 0777) == 0) { + char *cmeta; + FILE *fp; + + cmeta = g_build_filename(dir, "cmeta", NULL); + fp = fopen(cmeta, "w"); + if (fp) { + /* header/version */ + fwrite("CLMD", 4, 1, fp); + camel_file_util_encode_uint32(fp, 1); + /* meta count, do we have any metadata? */ + camel_file_util_encode_uint32(fp, 0); + /* prop count */ + camel_file_util_encode_uint32(fp, 1); + /* sync offline property */ + camel_file_util_encode_uint32(fp, CAMEL_DISCO_FOLDER_OFFLINE_SYNC); + camel_file_util_encode_uint32(fp, 1); + fclose(fp); + } else { + g_warning("couldn't create imap folder cmeta file '%s'", cmeta); + } + g_free(cmeta); + } else { + g_warning("couldn't create imap folder directory '%s'", dir); + } + g_free(dir); + g_free(base); + camel_url_free(url); + } + } else + g_warning("can't find offline folder '%s' '%s'", name, path); + } + g_free(p->data); + } + g_slist_free(paths); + g_object_unref(gconf); + + /* we couldn't care less if this doesn't work */ + + return TRUE; +} + +static void +remove_system_searches(xmlDocPtr searches) +{ + xmlNodePtr node; + + /* in pre 2.0, system searches were stored in the user + * searches.xml file with the source set to 'demand'. In 2.0+ + * the system searches are stored in the system + * searchtypes.xml file instead */ + + node = xmlDocGetRootElement(searches); + if (!node->name || strcmp((char *)node->name, "filteroptions")) + return; + + if (!(node = xml_find_node(node, "ruleset"))) + return; + + node = node->children; + while (node != NULL) { + xmlNodePtr nnode = node->next; + + if (node->name && !strcmp ((char *)node->name, "rule")) { + char *src; + + src = (char *)xmlGetProp(node, (unsigned char *)"source"); + if (src && !strcmp((char *)src, "demand")) { + xmlUnlinkNode(node); + xmlFreeNodeList(node); + } + xmlFree (src); + } + + node = nnode; + } +} + +static gboolean +em_migrate_1_4 (const char *data_dir, xmlDocPtr filters, xmlDocPtr vfolders, GError **error) +{ + EMMigrateSession *session; + CamelException lex; + struct stat st; + gchar *path; + xmlDocPtr searches; + + camel_init (data_dir, TRUE); + camel_provider_init(); + session = (EMMigrateSession *) em_migrate_session_new (data_dir); + + session->srcdir = g_build_filename (g_get_home_dir (), "evolution", "local", NULL); + + path = g_strdup_printf ("mbox:%s/.evolution/mail/local", g_get_home_dir ()); + if (stat (path + 5, &st) == -1) { + if (errno != ENOENT || g_mkdir_with_parents (path + 5, 0777) == -1) { + g_set_error ( + error, E_SHELL_MIGRATE_ERROR, + E_SHELL_MIGRATE_ERROR_FAILED, + _("Failed to create local mail storage " + "`%s': %s"), path + 5, g_strerror (errno)); + g_free (session->srcdir); + camel_object_unref (session); + g_free (path); + return FALSE; + } + } + + camel_exception_init (&lex); + if (!(session->store = camel_session_get_store ((CamelSession *) session, path, &lex))) { + g_set_error ( + error, E_SHELL_MIGRATE_ERROR, + E_SHELL_MIGRATE_ERROR_FAILED, + _("Failed to create local mail storage `%s': %s"), + path, lex.desc); + g_free (session->srcdir); + camel_object_unref (session); + camel_exception_clear (&lex); + g_free (path); + return FALSE; + } + g_free (path); + + if (!em_migrate_local_folders_1_4 (session, error)) + return FALSE; + + camel_object_unref (session->store); + g_free (session->srcdir); + + camel_object_unref (session); + + em_upgrade_accounts_1_4(); + + upgrade_xml_uris(filters, upgrade_xml_uris_1_4); + upgrade_vfolder_sources_1_4(vfolders); + upgrade_xml_uris(vfolders, upgrade_xml_uris_1_4); + + path = g_build_filename(g_get_home_dir(), "evolution", NULL); + searches = emm_load_xml(path, "searches.xml"); + g_free(path); + if (searches) { + remove_system_searches(searches); + emm_save_xml(searches, data_dir, "searches.xml"); + xmlFreeDoc(searches); + } + + if (!em_migrate_pop_uid_caches_1_4 (data_dir, error)) + return FALSE; + + /* these are non-fatal */ + em_migrate_imap_caches_1_4 (data_dir, error); + g_clear_error (error); + em_migrate_folder_expand_state_1_4 (data_dir, error); + g_clear_error (error); + em_migrate_folder_view_settings_1_4 (data_dir, error); + g_clear_error (error); + em_migrate_imap_cmeta_1_4 (data_dir, error); + g_clear_error (error); + + return TRUE; +} + +static void +em_update_accounts_2_11 (void) +{ + EAccountList *accounts; + EIterator *iter; + gboolean changed = FALSE; + + if (!(accounts = e_get_account_list ())) + return; + + iter = e_list_get_iterator ((EList *) accounts); + while (e_iterator_is_valid (iter)) { + EAccount *account = (EAccount *) e_iterator_get (iter); + + if (g_str_has_prefix (account->source->url, "spool://")) { + if (g_file_test (account->source->url + 8, G_FILE_TEST_IS_DIR)) { + char *str = g_strdup_printf ("spooldir://%s", account->source->url + 8); + + g_free (account->source->url); + account->source->url = str; + changed = TRUE; + } + } + + e_iterator_next (iter); + } + + g_object_unref (iter); + + if (changed) + e_account_list_save (accounts); +} + +#endif /* !G_OS_WIN32 */ + +static gboolean +emm_setup_initial(const gchar *data_dir) +{ + GDir *dir; + const char *d; + char *local = NULL, *base; + const gchar * const *language_names; + + /* special-case - this means brand new install of evolution */ + /* FIXME: create default folders and stuff... */ + + d(printf("Setting up initial mail tree\n")); + + base = g_build_filename(data_dir, "local", NULL); + if (g_mkdir_with_parents(base, 0777) == -1 && errno != EEXIST) { + g_free(base); + return FALSE; + } + + /* e.g. try en-AU then en, etc */ + language_names = g_get_language_names (); + while (*language_names != NULL) { + local = g_build_filename ( + EVOLUTION_PRIVDATADIR, "default", + *language_names, "mail", "local", NULL); + if (g_file_test (local, G_FILE_TEST_EXISTS)) + break; + g_free (local); + language_names++; + } + + /* Make sure we found one. */ + g_return_val_if_fail (*language_names != NULL, FALSE); + + dir = g_dir_open(local, 0, NULL); + if (dir) { + while ((d = g_dir_read_name(dir))) { + char *src, *dest; + + src = g_build_filename(local, d, NULL); + dest = g_build_filename(base, d, NULL); + + cp(src, dest, FALSE, CP_UNIQUE); + g_free(dest); + g_free(src); + } + g_dir_close(dir); + } + + g_free(local); + g_free(base); + + return TRUE; +} + +static gboolean +is_in_plugs_list (GSList *list, const gchar *value) +{ + GSList *l; + + for (l = list; l; l = l->next) { + if (l->data && !strcmp (l->data, value)) + return TRUE; + } + + return FALSE; +} + +/* + * em_update_message_notify_settings_2_21 + * DBus plugin and sound email notification was merged to mail-notification plugin, + * so move these options to new locations. + */ +static void +em_update_message_notify_settings_2_21 (void) +{ + GConfClient *client; + GConfValue *is_key; + gboolean dbus, status; + GSList *list; + gchar *str; + gint val; + + client = gconf_client_get_default (); + + is_key = gconf_client_get (client, "/apps/evolution/eplugin/mail-notification/dbus-enabled", NULL); + if (is_key) { + /* already migrated, so do not migrate again */ + gconf_value_free (is_key); + g_object_unref (client); + + return; + } + + gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/status-blink-icon", + gconf_client_get_bool (client, "/apps/evolution/mail/notification/blink-status-icon", NULL), NULL); + gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/status-notification", + gconf_client_get_bool (client, "/apps/evolution/mail/notification/notification", NULL), NULL); + + list = gconf_client_get_list (client, "/apps/evolution/eplugin/disabled", GCONF_VALUE_STRING, NULL); + dbus = !is_in_plugs_list (list, "org.gnome.evolution.new_mail_notify"); + status = !is_in_plugs_list (list, "org.gnome.evolution.mail_notification"); + + gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/dbus-enabled", dbus, NULL); + gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/status-enabled", status, NULL); + + if (!status) { + /* enable this plugin, because it holds all those other things */ + GSList *plugins, *l; + + plugins = e_plugin_list_plugins (); + + for (l = plugins; l; l = l->next) { + EPlugin *p = l->data; + + if (p && p->id && !strcmp (p->id, "org.gnome.evolution.mail_notification")) { + e_plugin_enable (p, 1); + break; + } + } + + g_slist_foreach (plugins, (GFunc)g_object_unref, NULL); + g_slist_free (plugins); + } + + g_slist_foreach (list, (GFunc) g_free, NULL); + g_slist_free (list); + + val = gconf_client_get_int (client, "/apps/evolution/mail/notify/type", NULL); + gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/sound-enabled", val == 1 || val == 2, NULL); + gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/sound-beep", val == 0 || val == 1, NULL); + + str = gconf_client_get_string (client, "/apps/evolution/mail/notify/sound", NULL); + gconf_client_set_string (client, "/apps/evolution/eplugin/mail-notification/sound-file", str ? str : "", NULL); + g_free (str); + + g_object_unref (client); +} + +/* fixing typo in SpamAssassin name */ +static void +em_update_sa_junk_setting_2_23 (void) +{ + GConfClient *client; + GConfValue *key; + + client = gconf_client_get_default (); + + key = gconf_client_get (client, "/apps/evolution/mail/junk/default_plugin", NULL); + if (key) { + const char *str = gconf_value_get_string (key); + + if (str && strcmp (str, "Spamassasin") == 0) + gconf_client_set_string (client, "/apps/evolution/mail/junk/default_plugin", "SpamAssassin", NULL); + + gconf_value_free (key); + g_object_unref (client); + + return; + } + + 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); + if (folder != NULL) + camel_folder_summary_migrate_infos (folder->summary); + migrate_folders(store, fi->child, acc, ex); + fi = fi->next; + } +} + +static CamelStore * +setup_local_store (EShellBackend *shell_backend, + EMMigrateSession *session) +{ + CamelURL *url; + const gchar *data_dir; + char *tmp; + CamelStore *store; + + url = camel_url_new("mbox:", NULL); + data_dir = e_shell_backend_get_data_dir (shell_backend); + tmp = g_build_filename (data_dir, "local", NULL); + camel_url_set_path(url, tmp); + g_free(tmp); + tmp = camel_url_to_string(url, 0); + store = (CamelStore *)camel_session_get_service(CAMEL_SESSION (session), tmp, CAMEL_PROVIDER_STORE, NULL); + g_free(tmp); + + return store; + +} +static void +migrate_to_db (EShellBackend *shell_backend) +{ + EMMigrateSession *session; + EAccountList *accounts; + EIterator *iter; + int i=0, len; + CamelStore *store = NULL; + CamelFolderInfo *info; + const gchar *data_dir; + + if (!(accounts = e_get_account_list ())) + return; + + iter = e_list_get_iterator ((EList *) accounts); + len = e_list_length ((EList *) accounts); + + data_dir = e_shell_backend_get_data_dir (shell_backend); + session = (EMMigrateSession *) em_migrate_session_new (data_dir); + 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 (shell_backend, session); + 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); + e_mail_shell_backend_load_store_by_uri ( + shell_backend, service->url, name); + + store = (CamelStore *) camel_session_get_service (CAMEL_SESSION (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:%s: failed to get folder infos \n", G_STRLOC, G_STRFUNC); + 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 (); + + g_object_unref (session); +} + +gboolean +e_mail_shell_backend_migrate (EShellBackend *shell_backend, + gint major, + gint minor, + gint micro, + GError **error) +{ + struct stat st; + const gchar *data_dir; + gchar *path; + + /* make sure ~/.evolution/mail exists */ + data_dir = e_shell_backend_get_data_dir (shell_backend); + if (g_stat (data_dir, &st) == -1) { + if (errno != ENOENT || g_mkdir_with_parents (data_dir, 0777) == -1) { + g_set_error ( + error, E_SHELL_MIGRATE_ERROR, + E_SHELL_MIGRATE_ERROR_FAILED, + _("Unable to create local mail folders at " + "`%s': %s"), data_dir, g_strerror (errno)); + return FALSE; + } + } + + if (major == 0) + return emm_setup_initial (data_dir); + + if (major == 1 && minor < 5) { +#ifndef G_OS_WIN32 + xmlDocPtr config_xmldb = NULL, filters, vfolders; + + path = g_build_filename (g_get_home_dir (), "evolution", NULL); + if (minor <= 2 && !(config_xmldb = emm_load_xml (path, "config.xmldb"))) { + g_set_error ( + error, E_SHELL_MIGRATE_ERROR, + E_SHELL_MIGRATE_ERROR_FAILED, + _("Unable to read settings from previous " + "Evolution install, `evolution/config.xmldb' " + "does not exist or is corrupt.")); + return FALSE; + } + filters = emm_load_xml (path, "filters.xml"); + vfolders = emm_load_xml (path, "vfolders.xml"); + g_free (path); + + if (minor == 0) { + if (!em_migrate_1_0 (data_dir, config_xmldb, filters, vfolders, error)) { + xmlFreeDoc (config_xmldb); + xmlFreeDoc (filters); + xmlFreeDoc (vfolders); + return FALSE; + } + } + + if (minor <= 2) { + if (!em_migrate_1_2 (data_dir, config_xmldb, filters, vfolders, error)) { + xmlFreeDoc (config_xmldb); + xmlFreeDoc (filters); + xmlFreeDoc (vfolders); + return FALSE; + } + + xmlFreeDoc (config_xmldb); + } + + if (minor <= 4) { + if (!em_migrate_1_4 (data_dir, filters, vfolders, error)) { + xmlFreeDoc (filters); + xmlFreeDoc (vfolders); + return FALSE; + } + } + + if (filters) { + emm_save_xml (filters, path, "filters.xml"); + xmlFreeDoc (filters); + } + + if (vfolders) { + emm_save_xml (vfolders, path, "vfolders.xml"); + xmlFreeDoc (vfolders); + } + + g_free (path); +#else + g_error ("Upgrading from ancient versions not supported on Windows"); +#endif + } + + if (major < 2 || (major == 2 && minor < 12)) { +#ifndef G_OS_WIN32 + em_update_accounts_2_11 (); +#else + g_error ("Upgrading from ancient versions not supported on Windows"); +#endif + } + + + if (major < 2 || (major == 2 && minor < 22)) + em_update_message_notify_settings_2_21 (); + + if (major < 2 || (major == 2 && minor < 24)) { + em_update_sa_junk_setting_2_23 (); + migrate_to_db (shell_backend); + } + + return TRUE; +} diff --git a/mail/e-mail-shell-migrate.h b/mail/e-mail-shell-migrate.h new file mode 100644 index 0000000000..498f60cf8d --- /dev/null +++ b/mail/e-mail-shell-migrate.h @@ -0,0 +1,38 @@ +/* + * e-mail-shell-migrate.h + * + * 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 + * + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef E_MAIL_SHELL_MODULE_MIGRATE_H +#define E_MAIL_SHELL_MODULE_MIGRATE_H + +#include +#include + +G_BEGIN_DECLS + +gboolean e_mail_shell_migrate (EShellBackend *shell_backend, + gint major, + gint minor, + gint micro, + GError **error); + +G_END_DECLS + +#endif /* E_MAIL_SHELL_MODULE_MIGRATE_H */ diff --git a/mail/e-mail-shell-module-migrate.c b/mail/e-mail-shell-module-migrate.c deleted file mode 100644 index ac09eec42f..0000000000 --- a/mail/e-mail-shell-module-migrate.c +++ /dev/null @@ -1,2988 +0,0 @@ -/* - * e-mail-shell-module-migrate.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 - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#include "e-mail-shell-module-migrate.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include "e-util/e-account-utils.h" -#include "e-util/e-bconf-map.h" -#include "e-util/e-error.h" -#include "e-util/e-util-private.h" -#include "e-util/e-plugin.h" -#include "e-util/e-signature-utils.h" - -#include "e-mail-shell-module.h" -#include "shell/e-shell-migrate.h" - -#include "mail-config.h" -#include "em-utils.h" - -#define d(x) x - -#ifndef G_OS_WIN32 -/* No versions previous to 2.8 or thereabouts have been available on - * Windows, so don't bother with upgrade support from earlier versions - * on Win32. Do try to support upgrades from 2.12 and later to the - * current version. - */ - -/* upgrade helper functions */ -static xmlDocPtr -emm_load_xml (const char *dirname, const char *filename) -{ - xmlDocPtr doc; - struct stat st; - char *path; - - path = g_strdup_printf ("%s/%s", dirname, filename); - if (stat (path, &st) == -1 || !(doc = xmlParseFile (path))) { - g_free (path); - return NULL; - } - - g_free (path); - - return doc; -} - -static int -emm_save_xml (xmlDocPtr doc, const char *dirname, const char *filename) -{ - char *path; - int retval; - - path = g_strdup_printf ("%s/%s", dirname, filename); - retval = e_xml_save_file (path, doc); - g_free (path); - - return retval; -} - -static xmlNodePtr -xml_find_node (xmlNodePtr parent, const char *name) -{ - xmlNodePtr node; - - node = parent->children; - while (node != NULL) { - if (node->name && !strcmp ((char *)node->name, name)) - return node; - - node = node->next; - } - - return NULL; -} - -static void -upgrade_xml_uris (xmlDocPtr doc, char * (* upgrade_uri) (const char *uri)) -{ - xmlNodePtr root, node; - char *uri, *new; - - if (!doc || !(root = xmlDocGetRootElement (doc))) - return; - - if (!root->name || strcmp ((char *)root->name, "filteroptions") != 0) { - /* root node is not , nothing to upgrade */ - return; - } - - if (!(node = xml_find_node (root, "ruleset"))) { - /* no ruleset node, nothing to upgrade */ - return; - } - - node = node->children; - while (node != NULL) { - if (node->name && !strcmp ((char *)node->name, "rule")) { - xmlNodePtr actionset, part, val, n; - - if ((actionset = xml_find_node (node, "actionset"))) { - /* filters.xml */ - part = actionset->children; - while (part != NULL) { - if (part->name && !strcmp ((char *)part->name, "part")) { - val = part->children; - while (val != NULL) { - if (val->name && !strcmp ((char *)val->name, "value")) { - char *type; - - type = (char *)xmlGetProp (val, (const unsigned char *)"type"); - if (type && !strcmp ((char *)type, "folder")) { - if ((n = xml_find_node (val, "folder"))) { - uri = (char *)xmlGetProp (n, (const unsigned char *)"uri"); - new = upgrade_uri (uri); - xmlFree (uri); - - xmlSetProp (n, (const unsigned char *)"uri", (unsigned char *)new); - g_free (new); - } - } - - xmlFree (type); - } - - val = val->next; - } - } - - part = part->next; - } - } else if ((actionset = xml_find_node (node, "sources"))) { - /* vfolders.xml */ - n = actionset->children; - while (n != NULL) { - if (n->name && !strcmp ((char *)n->name, "folder")) { - uri = (char *)xmlGetProp (n, (const unsigned char *)"uri"); - new = upgrade_uri (uri); - xmlFree (uri); - - xmlSetProp (n, (const unsigned char *)"uri", (unsigned char *)new); - g_free (new); - } - - n = n->next; - } - } - } - - node = node->next; - } -} - -/* 1.0 upgrade functions & data */ - -/* as much info as we have on a given account */ -struct _account_info_1_0 { - char *name; - char *uri; - char *base_uri; - union { - struct { - /* for imap */ - char *namespace; - char *namespace_full; - guint32 capabilities; - GHashTable *folders; - char dir_sep; - } imap; - } u; -}; - -struct _imap_folder_info_1_0 { - char *folder; - /* encoded? decoded? canonicalised? */ - char dir_sep; -}; - -static GHashTable *accounts_1_0 = NULL; -static GHashTable *accounts_name_1_0 = NULL; - -static void -imap_folder_info_1_0_free (struct _imap_folder_info_1_0 *fi) -{ - g_free(fi->folder); - g_free(fi); -} - -static void -account_info_1_0_free (struct _account_info_1_0 *ai) -{ - g_free(ai->name); - g_free(ai->uri); - g_free(ai->base_uri); - g_free(ai->u.imap.namespace); - g_free(ai->u.imap.namespace_full); - g_hash_table_destroy(ai->u.imap.folders); - g_free(ai); -} - -static char * -get_base_uri(const char *val) -{ - const char *tmp; - - tmp = strchr(val, ':'); - if (tmp) { - tmp++; - if (strncmp(tmp, "//", 2) == 0) - tmp += 2; - tmp = strchr(tmp, '/'); - } - - if (tmp) - return g_strndup(val, tmp-val); - else - return g_strdup(val); -} - -static char * -upgrade_xml_uris_1_0 (const char *uri) -{ - char *out = NULL; - - /* upgrades camel uri's */ - if (strncmp (uri, "imap:", 5) == 0) { - char *base_uri, dir_sep, *folder, *p; - struct _account_info_1_0 *ai; - - /* add namespace, canonicalise dir_sep to / */ - base_uri = get_base_uri (uri); - ai = g_hash_table_lookup (accounts_1_0, base_uri); - - if (ai == NULL) { - g_free (base_uri); - return NULL; - } - - dir_sep = ai->u.imap.dir_sep; - if (dir_sep == 0) { - /* no dir_sep listed, try get it from the namespace, if set */ - if (ai->u.imap.namespace != NULL) { - p = ai->u.imap.namespace; - while ((dir_sep = *p++)) { - if (dir_sep < '0' - || (dir_sep > '9' && dir_sep < 'A') - || (dir_sep > 'Z' && dir_sep < 'a') - || (dir_sep > 'z')) { - break; - } - p++; - } - } - - /* give up ... */ - if (dir_sep == 0) { - g_free (base_uri); - return NULL; - } - } - - folder = g_strdup (uri + strlen (base_uri) + 1); - - /* Add the namespace before the mailbox name, unless the mailbox is INBOX */ - if (ai->u.imap.namespace && strcmp ((char *)folder, "INBOX") != 0) - out = g_strdup_printf ("%s/%s/%s", base_uri, ai->u.imap.namespace, folder); - else - out = g_strdup_printf ("%s/%s", base_uri, folder); - - p = out; - while (*p) { - if (*p == dir_sep) - *p = '/'; - p++; - } - - g_free (folder); - g_free (base_uri); - } else if (strncmp (uri, "exchange:", 9) == 0) { - char *base_uri, *folder, *p; - - /* exchange://user@host/exchange/ * -> exchange://user@host/personal/ * */ - /* Any url encoding (%xx) in the folder name is also removed */ - base_uri = get_base_uri (uri); - uri += strlen (base_uri) + 1; - if (strncmp (uri, "exchange/", 9) == 0) { - folder = e_bconf_url_decode (uri + 9); - p = strchr (folder, '/'); - out = g_strdup_printf ("%s/personal%s", base_uri, p ? p : "/"); - g_free (folder); - } - } else if (strncmp (uri, "exchanget:", 10) == 0) { - /* these should be converted in the accounts table when it is loaded */ - g_warning ("exchanget: uri not converted: '%s'", uri); - } - - return out; -} - -static char * -parse_lsub (const char *lsub, char *dir_sep) -{ - static int comp; - static regex_t pat; - regmatch_t match[3]; - char *m = "^\\* LSUB \\([^)]*\\) \"?([^\" ]+)\"? \"?(.*)\"?$"; - - if (!comp) { - if (regcomp (&pat, m, REG_EXTENDED|REG_ICASE) == -1) { - g_warning ("reg comp '%s' failed: %s", m, g_strerror (errno)); - return NULL; - } - comp = 1; - } - - if (regexec (&pat, lsub, 3, match, 0) == 0) { - if (match[1].rm_so != -1 && match[2].rm_so != -1) { - if (dir_sep) - *dir_sep = (match[1].rm_eo - match[1].rm_so == 1) ? lsub[match[1].rm_so] : 0; - return g_strndup (lsub + match[2].rm_so, match[2].rm_eo - match[2].rm_so); - } - } - - return NULL; -} - -static gboolean -read_imap_storeinfo (struct _account_info_1_0 *si) -{ - FILE *storeinfo; - guint32 tmp; - char *buf, *folder, dir_sep, *path, *name, *p; - struct _imap_folder_info_1_0 *fi; - - si->u.imap.folders = g_hash_table_new_full ( - g_str_hash, g_str_equal, - (GDestroyNotify) NULL, - (GDestroyNotify) imap_folder_info_1_0_free); - - /* get details from uri first */ - name = strstr (si->uri, ";override_namespace"); - if (name) { - name = strstr (si->uri, ";namespace="); - if (name) { - char *end; - - name += strlen (";namespace="); - if (*name == '\"') { - name++; - end = strchr (name, '\"'); - } else { - end = strchr (name, ';'); - } - - if (end) { - /* try get the dir_sep from the namespace */ - si->u.imap.namespace = g_strndup (name, end-name); - - p = si->u.imap.namespace; - while ((dir_sep = *p++)) { - if (dir_sep < '0' - || (dir_sep > '9' && dir_sep < 'A') - || (dir_sep > 'Z' && dir_sep < 'a') - || (dir_sep > 'z')) { - si->u.imap.dir_sep = dir_sep; - break; - } - p++; - } - } - } - } - - /* now load storeinfo if it exists */ - path = g_build_filename (g_get_home_dir (), "evolution", "mail", "imap", si->base_uri + 7, "storeinfo", NULL); - storeinfo = fopen (path, "r"); - g_free (path); - if (storeinfo == NULL) { - g_warning ("could not find imap store info '%s'", path); - return FALSE; - } - - /* ignore version */ - camel_file_util_decode_uint32 (storeinfo, &tmp); - camel_file_util_decode_uint32 (storeinfo, &si->u.imap.capabilities); - g_free (si->u.imap.namespace); - camel_file_util_decode_string (storeinfo, &si->u.imap.namespace); - camel_file_util_decode_uint32 (storeinfo, &tmp); - si->u.imap.dir_sep = tmp; - /* strip trailing dir_sep or / */ - if (si->u.imap.namespace - && (si->u.imap.namespace[strlen (si->u.imap.namespace) - 1] == si->u.imap.dir_sep - || si->u.imap.namespace[strlen (si->u.imap.namespace) - 1] == '/')) { - si->u.imap.namespace[strlen (si->u.imap.namespace) - 1] = 0; - } - - d(printf ("namespace '%s' dir_sep '%c'\n", si->u.imap.namespace, si->u.imap.dir_sep ? si->u.imap.dir_sep : '?')); - - while (camel_file_util_decode_string (storeinfo, &buf) == 0) { - folder = parse_lsub (buf, &dir_sep); - if (folder) { - fi = g_new0 (struct _imap_folder_info_1_0, 1); - fi->folder = folder; - fi->dir_sep = dir_sep; -#if d(!)0 - printf (" add folder '%s' ", folder); - if (dir_sep) - printf ("'%c'\n", dir_sep); - else - printf ("NIL\n"); -#endif - g_hash_table_insert (si->u.imap.folders, fi->folder, fi); - } else { - g_warning ("Could not parse LIST result '%s'\n", buf); - } - } - - fclose (storeinfo); - - return TRUE; -} - -static gboolean -load_accounts_1_0 (xmlDocPtr doc) -{ - xmlNodePtr source; - char *val, *tmp; - int count = 0, i; - char key[32]; - - if (!(source = e_bconf_get_path (doc, "/Mail/Accounts"))) - return TRUE; - - if ((val = e_bconf_get_value (source, "num"))) { - count = atoi (val); - xmlFree (val); - } - - /* load account upgrade info for each account */ - for (i = 0; i < count; i++) { - struct _account_info_1_0 *ai; - char *rawuri; - - sprintf (key, "source_url_%d", i); - if (!(rawuri = e_bconf_get_value (source, key))) - continue; - - ai = g_malloc0 (sizeof (struct _account_info_1_0)); - ai->uri = e_bconf_hex_decode (rawuri); - ai->base_uri = get_base_uri (ai->uri); - sprintf (key, "account_name_%d", i); - ai->name = e_bconf_get_string (source, key); - - d(printf("load account '%s'\n", ai->uri)); - - if (!strncmp (ai->uri, "imap:", 5)) { - read_imap_storeinfo (ai); - } else if (!strncmp (ai->uri, "exchange:", 9)) { - xmlNodePtr node; - - d(printf (" upgrade exchange account\n")); - /* small hack, poke the source_url into the transport_url for exchanget: transports - - this will be picked up later in the conversion */ - sprintf (key, "transport_url_%d", i); - node = e_bconf_get_entry (source, key); - if (node && (val = (char *)xmlGetProp (node, (const unsigned char *)"value"))) { - tmp = e_bconf_hex_decode (val); - xmlFree (val); - if (strncmp (tmp, "exchanget:", 10) == 0) - xmlSetProp (node, (const unsigned char *)"value", (unsigned char *)rawuri); - g_free (tmp); - } else { - d(printf (" couldn't find transport uri?\n")); - } - } - xmlFree (rawuri); - - g_hash_table_insert (accounts_1_0, ai->base_uri, ai); - if (ai->name) - g_hash_table_insert (accounts_name_1_0, ai->name, ai); - } - - return TRUE; -} - -static gboolean -em_migrate_1_0 (const char *data_dir, xmlDocPtr config_xmldb, xmlDocPtr filters, xmlDocPtr vfolders, GError **error) -{ - accounts_1_0 = g_hash_table_new_full ( - g_str_hash, g_str_equal, - (GDestroyNotify) NULL, - (GDestroyNotify) account_info_1_0_free); - accounts_name_1_0 = g_hash_table_new (g_str_hash, g_str_equal); - load_accounts_1_0 (config_xmldb); - - upgrade_xml_uris(filters, upgrade_xml_uris_1_0); - upgrade_xml_uris(vfolders, upgrade_xml_uris_1_0); - - g_hash_table_destroy (accounts_1_0); - g_hash_table_destroy (accounts_name_1_0); - - return TRUE; -} - -/* 1.2 upgrade functions */ -static gboolean -is_xml1encoded (const char *txt) -{ - const unsigned char *p; - int isxml1 = FALSE; - int is8bit = FALSE; - - p = (const unsigned char *)txt; - while (*p) { - if (p[0] == '\\' && p[1] == 'U' && p[2] == '+' - && isxdigit (p[3]) && isxdigit (p[4]) && isxdigit (p[5]) && isxdigit (p[6]) - && p[7] == '\\') { - isxml1 = TRUE; - p+=7; - } else if (p[0] >= 0x80) - is8bit = TRUE; - p++; - } - - /* check for invalid utf8 that needs cleaning */ - if (is8bit && !isxml1) - isxml1 = !g_utf8_validate (txt, -1, NULL); - - return isxml1; -} - -static char * -decode_xml1 (const char *txt) -{ - GString *out = g_string_new (""); - const unsigned char *p; - char *res; - - /* convert: - \U+XXXX\ -> utf8 - 8 bit characters -> utf8 (iso-8859-1) */ - - p = (const unsigned char *) txt; - while (*p) { - if (p[0] > 0x80 - || (p[0] == '\\' && p[1] == 'U' && p[2] == '+' - && isxdigit (p[3]) && isxdigit (p[4]) && isxdigit (p[5]) && isxdigit (p[6]) - && p[7] == '\\')) { - char utf8[8]; - gunichar u; - - if (p[0] == '\\') { - memcpy (utf8, p + 3, 4); - utf8[4] = 0; - u = strtoul (utf8, NULL, 16); - p+=7; - } else - u = p[0]; - utf8[g_unichar_to_utf8 (u, utf8)] = 0; - g_string_append (out, utf8); - } else { - g_string_append_c (out, *p); - } - p++; - } - - res = out->str; - g_string_free (out, FALSE); - - return res; -} - -static char * -utf8_reencode (const char *txt) -{ - GString *out = g_string_new (""); - gchar *p; - char *res; - - /* convert: - libxml1 8 bit utf8 converted to xml entities byte-by-byte chars -> utf8 */ - - p = (gchar *)txt; - - while (*p) { - g_string_append_c (out, (gchar)g_utf8_get_char ((const gchar *)p)); - p = (gchar *)g_utf8_next_char (p); - } - - res = out->str; - if (g_utf8_validate (res, -1, NULL)) { - g_string_free (out, FALSE); - return res; - } else { - g_string_free (out, TRUE); - return g_strdup (txt); - } -} - -static gboolean -upgrade_xml_1_2_rec (xmlNodePtr node) -{ - const char *value_tags[] = { "string", "address", "regex", "file", "command", NULL }; - const char *rule_tags[] = { "title", NULL }; - const char *item_props[] = { "name", NULL }; - struct { - const char *name; - const char **tags; - const char **props; - } tags[] = { - { "value", value_tags, NULL }, - { "rule", rule_tags, NULL }, - { "item", NULL, item_props }, - { 0 }, - }; - xmlNodePtr work; - int i,j; - char *txt, *tmp; - - /* upgrades the content of a node, if the node has a specific parent/node name */ - - for (i = 0; tags[i].name; i++) { - if (!strcmp ((char *)node->name, tags[i].name)) { - if (tags[i].tags != NULL) { - work = node->children; - while (work) { - for (j = 0; tags[i].tags[j]; j++) { - if (!strcmp ((char *)work->name, tags[i].tags[j])) { - txt = (char *)xmlNodeGetContent (work); - if (is_xml1encoded (txt)) { - tmp = decode_xml1 (txt); - d(printf ("upgrading xml node %s/%s '%s' -> '%s'\n", - tags[i].name, tags[i].tags[j], txt, tmp)); - xmlNodeSetContent (work, (unsigned char *)tmp); - g_free (tmp); - } - xmlFree (txt); - } - } - work = work->next; - } - break; - } - - if (tags[i].props != NULL) { - for (j = 0; tags[i].props[j]; j++) { - txt = (char *)xmlGetProp (node, (unsigned char *)tags[i].props[j]); - tmp = utf8_reencode (txt); - d(printf ("upgrading xml property %s on node %s '%s' -> '%s'\n", - tags[i].props[j], tags[i].name, txt, tmp)); - xmlSetProp (node, (const unsigned char *)tags[i].props[j], (unsigned char *)tmp); - g_free (tmp); - xmlFree (txt); - } - } - } - } - - node = node->children; - while (node) { - upgrade_xml_1_2_rec (node); - node = node->next; - } - - return TRUE; -} - -static gboolean -em_upgrade_xml_1_2 (xmlDocPtr doc) -{ - xmlNodePtr root; - - if (!doc || !(root = xmlDocGetRootElement (doc))) - return TRUE; - - return upgrade_xml_1_2_rec (root); -} - -/* ********************************************************************** */ -/* Tables for converting flat bonobo conf -> gconf xml blob */ -/* ********************************************************************** */ - -/* Mail/Accounts/ * */ -static e_bconf_map_t cc_map[] = { - { "account_always_cc_%i", "always", E_BCONF_MAP_BOOL }, - { "account_always_cc_addrs_%i", "recipients", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, - { NULL }, -}; - -static e_bconf_map_t bcc_map[] = { - { "account_always_cc_%i", "always", E_BCONF_MAP_BOOL }, - { "account_always_bcc_addrs_%i", "recipients", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, - { NULL }, -}; - -static e_bconf_map_t pgp_map[] = { - { "account_pgp_encrypt_to_self_%i", "encrypt-to-self", E_BCONF_MAP_BOOL }, - { "account_pgp_always_trust_%i", "always-trust", E_BCONF_MAP_BOOL }, - { "account_pgp_always_sign_%i", "always-sign", E_BCONF_MAP_BOOL }, - { "account_pgp_no_imip_sign_%i", "no-imip-sign", E_BCONF_MAP_BOOL }, - { "account_pgp_key_%i", "key-id", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, - { NULL }, -}; - -static e_bconf_map_t smime_map[] = { - { "account_smime_encrypt_to_self_%i", "encrypt-to-self", E_BCONF_MAP_BOOL }, - { "account_smime_always_sign_%i", "always-sign", E_BCONF_MAP_BOOL }, - { "account_smime_key_%i", "key-id", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, - { NULL }, -}; - -static e_bconf_map_t identity_sig_map[] = { - { "identity_autogenerated_signature_%i", "auto", E_BCONF_MAP_BOOL }, - { "identity_def_signature_%i", "default", E_BCONF_MAP_LONG }, - { NULL }, -}; - -static e_bconf_map_t identity_map[] = { - { "identity_name_%i", "name", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, - { "identity_address_%i", "addr-spec", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, - { "identity_reply_to_%i", "reply-to", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, - { "identity_organization_%i", "organization", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, - { NULL, "signature", E_BCONF_MAP_CHILD, identity_sig_map }, - { NULL }, -}; - -static e_bconf_map_t source_map[] = { - { "source_save_passwd_%i", "save-passwd", E_BCONF_MAP_BOOL }, - { "source_keep_on_server_%i", "keep-on-server", E_BCONF_MAP_BOOL }, - { "source_auto_check_%i", "auto-check", E_BCONF_MAP_BOOL }, - { "source_auto_check_time_%i", "auto-check-timeout", E_BCONF_MAP_LONG }, - { "source_url_%i", "url", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, - { NULL }, -}; - -static e_bconf_map_t transport_map[] = { - { "transport_save_passwd_%i", "save-passwd", E_BCONF_MAP_BOOL }, - { "transport_url_%i", "url", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, - { NULL }, -}; - -static e_bconf_map_t account_map[] = { - { "account_name_%i", "name", E_BCONF_MAP_STRING }, - { "source_enabled_%i", "enabled", E_BCONF_MAP_BOOL }, - { NULL, "identity", E_BCONF_MAP_CHILD, identity_map }, - { NULL, "source", E_BCONF_MAP_CHILD, source_map }, - { NULL, "transport", E_BCONF_MAP_CHILD, transport_map }, - { "account_drafts_folder_uri_%i", "drafts-folder", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, - { "account_sent_folder_uri_%i", "sent-folder", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, - { NULL, "auto-cc", E_BCONF_MAP_CHILD, cc_map }, - { NULL, "auto-bcc", E_BCONF_MAP_CHILD, bcc_map }, - { NULL, "pgp", E_BCONF_MAP_CHILD, pgp_map }, - { NULL, "smime", E_BCONF_MAP_CHILD, smime_map }, - { NULL }, -}; - -/* /Mail/Signatures/ * */ -static e_bconf_map_t signature_format_map[] = { - { "text/plain", }, - { "text/html", }, - { NULL } -}; - -static e_bconf_map_t signature_map[] = { - { "name_%i", "name", E_BCONF_MAP_STRING }, - { "html_%i", "format", E_BCONF_MAP_ENUM, signature_format_map }, - { "filename_%i", "filename", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, - { "script_%i", "script", E_BCONF_MAP_STRING|E_BCONF_MAP_CONTENT }, - { NULL }, -}; - -/* ********************************************************************** */ -/* Tables for bonobo conf -> gconf conversion */ -/* ********************************************************************** */ - -static e_gconf_map_t mail_accounts_map[] = { - /* /Mail/Accounts - most entries are processed via the xml blob routine */ - /* This also works because the initial uid mapping is 1:1 with the list order */ - { "default_account", "mail/default_account", E_GCONF_MAP_SIMPLESTRING }, - { 0 }, -}; - -static e_gconf_map_t mail_display_map[] = { - /* /Mail/Display */ - { "side_bar_search", "mail/display/side_bar_search", E_GCONF_MAP_BOOL }, - { "thread_list", "mail/display/thread_list", E_GCONF_MAP_BOOL }, - { "thread_subject", "mail/display/thread_subject", E_GCONF_MAP_BOOL }, - { "hide_deleted", "mail/display/show_deleted", E_GCONF_MAP_BOOLNOT }, - { "preview_pane", "mail/display/show_preview", E_GCONF_MAP_BOOL }, - { "paned_size", "mail/display/paned_size", E_GCONF_MAP_INT }, - { "seen_timeout", "mail/display/mark_seen_timeout", E_GCONF_MAP_INT }, - { "do_seen_timeout", "mail/display/mark_seen", E_GCONF_MAP_BOOL }, - { "http_images", "mail/display/load_http_images", E_GCONF_MAP_INT }, - { "citation_highlight", "mail/display/mark_citations", E_GCONF_MAP_BOOL }, - { "citation_color", "mail/display/citation_colour", E_GCONF_MAP_COLOUR }, - { 0 }, -}; - -static e_gconf_map_t mail_format_map[] = { - /* /Mail/Format */ - { "message_display_style", "mail/display/message_style", E_GCONF_MAP_INT }, - { "send_html", "mail/composer/send_html", E_GCONF_MAP_BOOL }, - { "default_reply_style", "mail/format/reply_style", E_GCONF_MAP_INT }, - { "default_forward_style", "mail/format/forward_style", E_GCONF_MAP_INT }, - { "default_charset", "mail/composer/charset", E_GCONF_MAP_STRING }, - { "confirm_unwanted_html", "mail/prompts/unwanted_html", E_GCONF_MAP_BOOL }, - { 0 }, -}; - -static e_gconf_map_t mail_trash_map[] = { - /* /Mail/Trash */ - { "empty_on_exit", "mail/trash/empty_on_exit", E_GCONF_MAP_BOOL }, - { 0 }, -}; - -static e_gconf_map_t mail_prompts_map[] = { - /* /Mail/Prompts */ - { "confirm_expunge", "mail/prompts/expunge", E_GCONF_MAP_BOOL }, - { "empty_subject", "mail/prompts/empty_subject", E_GCONF_MAP_BOOL }, - { "only_bcc", "mail/prompts/only_bcc", E_GCONF_MAP_BOOL }, - { 0 } -}; - -static e_gconf_map_t mail_filters_map[] = { - /* /Mail/Filters */ - { "log", "mail/filters/log", E_GCONF_MAP_BOOL }, - { "log_path", "mail/filters/logfile", E_GCONF_MAP_STRING }, - { 0 } -}; - -static e_gconf_map_t mail_notify_map[] = { - /* /Mail/Notify */ - { "new_mail_notification", "mail/notify/type", E_GCONF_MAP_INT }, - { "new_mail_notification_sound_file", "mail/notify/sound", E_GCONF_MAP_STRING }, - { 0 } -}; - -static e_gconf_map_t mail_filesel_map[] = { - /* /Mail/Filesel */ - { "last_filesel_dir", "mail/save_dir", E_GCONF_MAP_STRING }, - { 0 } -}; - -static e_gconf_map_t mail_composer_map[] = { - /* /Mail/Composer */ - { "ViewFrom", "mail/composer/view/From", E_GCONF_MAP_BOOL }, - { "ViewReplyTo", "mail/composer/view/ReplyTo", E_GCONF_MAP_BOOL }, - { "ViewCC", "mail/composer/view/Cc", E_GCONF_MAP_BOOL }, - { "ViewBCC", "mail/composer/view/Bcc", E_GCONF_MAP_BOOL }, - { "ViewSubject", "mail/composer/view/Subject", E_GCONF_MAP_BOOL }, - { 0 }, -}; - -/* ********************************************************************** */ - -static e_gconf_map_t importer_elm_map[] = { - /* /Importer/Elm */ - { "mail", "importer/elm/mail", E_GCONF_MAP_BOOL }, - { "mail-imported", "importer/elm/mail-imported", E_GCONF_MAP_BOOL }, - { 0 }, -}; - -static e_gconf_map_t importer_pine_map[] = { - /* /Importer/Pine */ - { "mail", "importer/elm/mail", E_GCONF_MAP_BOOL }, - { "address", "importer/elm/address", E_GCONF_MAP_BOOL }, - { 0 }, -}; - -static e_gconf_map_t importer_netscape_map[] = { - /* /Importer/Netscape */ - { "mail", "importer/netscape/mail", E_GCONF_MAP_BOOL }, - { "settings", "importer/netscape/settings", E_GCONF_MAP_BOOL }, - { "filters", "importer/netscape/filters", E_GCONF_MAP_BOOL }, - { 0 }, -}; - -/* ********************************************************************** */ - -static e_gconf_map_list_t gconf_remap_list[] = { - { "/Mail/Accounts", mail_accounts_map }, - { "/Mail/Display", mail_display_map }, - { "/Mail/Format", mail_format_map }, - { "/Mail/Trash", mail_trash_map }, - { "/Mail/Prompts", mail_prompts_map }, - { "/Mail/Filters", mail_filters_map }, - { "/Mail/Notify", mail_notify_map }, - { "/Mail/Filesel", mail_filesel_map }, - { "/Mail/Composer", mail_composer_map }, - - { "/Importer/Elm", importer_elm_map }, - { "/Importer/Pine", importer_pine_map }, - { "/Importer/Netscape", importer_netscape_map }, - - { 0 }, -}; - -static struct { - char *label; - char *colour; -} label_default[5] = { - { N_("Important"), "#EF2929" }, /* red */ - { N_("Work"), "#F57900" }, /* orange */ - { N_("Personal"), "#4E9A06" }, /* green */ - { N_("To Do"), "#3465A4" }, /* blue */ - { N_("Later"), "#75507B" } /* purple */ -}; - -/* remaps mail config from bconf to gconf */ -static gboolean -bconf_import(GConfClient *gconf, xmlDocPtr config_xmldb) -{ - xmlNodePtr source; - char labx[16], colx[16]; - char *val, *lab, *col; - GSList *list, *l; - int i; - - e_bconf_import(gconf, config_xmldb, gconf_remap_list); - - /* Labels: - label string + label colour as integer - -> label string:# colour as hex */ - source = e_bconf_get_path(config_xmldb, "/Mail/Labels"); - if (source) { - list = NULL; - for (i = 0; i < 5; i++) { - sprintf(labx, "label_%d", i); - sprintf(colx, "color_%d", i); - lab = e_bconf_get_string(source, labx); - if ((col = e_bconf_get_value(source, colx))) { - sprintf(colx, "#%06x", atoi(col) & 0xffffff); - g_free(col); - } else - strcpy(colx, label_default[i].colour); - - val = g_strdup_printf("%s:%s", lab ? lab : label_default[i].label, colx); - list = g_slist_append(list, val); - g_free(lab); - } - - gconf_client_set_list(gconf, "/apps/evolution/mail/labels", GCONF_VALUE_STRING, list, NULL); - while (list) { - l = list->next; - g_free(list->data); - g_slist_free_1(list); - list = l; - } - } else { - g_warning("could not find /Mail/Labels in old config database, skipping"); - } - - /* Accounts: The flat bonobo-config structure is remapped to a list of xml blobs. Upgrades as necessary */ - e_bconf_import_xml_blob(gconf, config_xmldb, account_map, "/Mail/Accounts", - "/apps/evolution/mail/accounts", "account", "uid"); - - /* Same for signatures */ - e_bconf_import_xml_blob(gconf, config_xmldb, signature_map, "/Mail/Signatures", - "/apps/evolution/mail/signatures", "signature", NULL); - - return TRUE; -} - -static gboolean -em_migrate_1_2(const char *data_dir, xmlDocPtr config_xmldb, xmlDocPtr filters, xmlDocPtr vfolders, GError **error) -{ - GConfClient *gconf; - - gconf = gconf_client_get_default(); - bconf_import(gconf, config_xmldb); - g_object_unref(gconf); - - em_upgrade_xml_1_2(filters); - em_upgrade_xml_1_2(vfolders); - - return TRUE; -} - -/* 1.4 upgrade functions */ - -#define EM_MIGRATE_SESSION_TYPE (em_migrate_session_get_type ()) -#define EM_MIGRATE_SESSION(obj) (CAMEL_CHECK_CAST((obj), EM_MIGRATE_SESSION_TYPE, EMMigrateSession)) -#define EM_MIGRATE_SESSION_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), EM_MIGRATE_SESSION_TYPE, EMMigrateSessionClass)) -#define EM_MIGRATE_IS_SESSION(o) (CAMEL_CHECK_TYPE((o), EM_MIGRATE_SESSION_TYPE)) - -typedef struct _EMMigrateSession { - CamelSession parent_object; - - CamelStore *store; /* new folder tree store */ - char *srcdir; /* old folder tree path */ -} EMMigrateSession; - -typedef struct _EMMigrateSessionClass { - CamelSessionClass parent_class; - -} EMMigrateSessionClass; - -static CamelType em_migrate_session_get_type (void); -static CamelSession *em_migrate_session_new (const char *path); - -static void -class_init (EMMigrateSessionClass *klass) -{ - ; -} - -static CamelType -em_migrate_session_get_type (void) -{ - static CamelType type = CAMEL_INVALID_TYPE; - - if (type == CAMEL_INVALID_TYPE) { - type = camel_type_register ( - camel_session_get_type (), - "EMMigrateSession", - sizeof (EMMigrateSession), - sizeof (EMMigrateSessionClass), - (CamelObjectClassInitFunc) class_init, - NULL, - NULL, - NULL); - } - - return type; -} - -static CamelSession * -em_migrate_session_new (const char *path) -{ - CamelSession *session; - - session = CAMEL_SESSION (camel_object_new (EM_MIGRATE_SESSION_TYPE)); - - camel_session_construct (session, path); - - return session; -} - - -#endif /* !G_OS_WIN32 */ - -static GtkWidget *window; -static GtkLabel *label; -static GtkProgressBar *progress; - -static void -em_migrate_setup_progress_dialog (const char *desc) -{ - GtkWidget *vbox, *hbox, *w; - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title ((GtkWindow *) window, _("Migrating...")); - gtk_window_set_modal ((GtkWindow *) window, TRUE); - gtk_container_set_border_width ((GtkContainer *) window, 6); - - vbox = gtk_vbox_new (FALSE, 6); - gtk_widget_show (vbox); - gtk_container_add ((GtkContainer *) window, vbox); - - 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); - - hbox = gtk_hbox_new (FALSE, 6); - gtk_widget_show (hbox); - gtk_box_pack_start_defaults ((GtkBox *) vbox, hbox); - - label = (GtkLabel *) gtk_label_new (""); - gtk_widget_show ((GtkWidget *) label); - gtk_box_pack_start_defaults ((GtkBox *) hbox, (GtkWidget *) label); - - progress = (GtkProgressBar *) gtk_progress_bar_new (); - gtk_widget_show ((GtkWidget *) progress); - gtk_box_pack_start_defaults ((GtkBox *) hbox, (GtkWidget *) progress); - - gtk_widget_show (window); -} - -static void -em_migrate_close_progress_dialog (void) -{ - gtk_widget_destroy ((GtkWidget *) window); -} - -static void -em_migrate_set_folder_name (const char *folder_name) -{ - char *text; - - 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 (); -} - -static void -em_migrate_set_progress (double percent) -{ - char text[5]; - - snprintf (text, sizeof (text), "%d%%", (int) (percent * 100.0f)); - - gtk_progress_bar_set_fraction (progress, percent); - gtk_progress_bar_set_text (progress, text); - - while (gtk_events_pending ()) - gtk_main_iteration (); -} - -#ifndef G_OS_WIN32 - -static gboolean -is_mail_folder (const char *metadata) -{ - xmlNodePtr node; - xmlDocPtr doc; - char *type; - - if (!(doc = xmlParseFile (metadata))) { - g_warning ("Cannot parse `%s'", metadata); - return FALSE; - } - - if (!(node = xmlDocGetRootElement (doc))) { - g_warning ("`%s' corrupt: document contains no root node", metadata); - xmlFreeDoc (doc); - return FALSE; - } - - if (!node->name || strcmp ((char *)node->name, "efolder") != 0) { - g_warning ("`%s' corrupt: root node is not 'efolder'", metadata); - xmlFreeDoc (doc); - return FALSE; - } - - node = node->children; - while (node != NULL) { - if (node->name && !strcmp ((char *)node->name, "type")) { - type = (char *)xmlNodeGetContent (node); - if (!strcmp ((char *)type, "mail")) { - xmlFreeDoc (doc); - xmlFree (type); - - return TRUE; - } - - xmlFree (type); - - break; - } - - node = node->next; - } - - xmlFreeDoc (doc); - - return FALSE; -} - -static gboolean -get_local_et_expanded (const char *dirname) -{ - xmlNodePtr node; - xmlDocPtr doc; - struct stat st; - char *buf, *p; - int thread_list; - - buf = g_strdup_printf ("%s/evolution/config/file:%s", g_get_home_dir (), dirname); - p = buf + strlen (g_get_home_dir ()) + strlen ("/evolution/config/file:"); - e_filename_make_safe (p); - - if (stat (buf, &st) == -1) { - g_free (buf); - return FALSE; - } - - if (!(doc = xmlParseFile (buf))) { - g_free (buf); - return FALSE; - } - - g_free (buf); - - if (!(node = xmlDocGetRootElement (doc)) || strcmp ((char *)node->name, "expanded_state") != 0) { - xmlFreeDoc (doc); - return FALSE; - } - - if (!(buf = (char *)xmlGetProp (node, (const unsigned char *)"default"))) { - xmlFreeDoc (doc); - return FALSE; - } - - thread_list = strcmp (buf, "0") == 0 ? 0 : 1; - xmlFree (buf); - - xmlFreeDoc (doc); - - return thread_list; -} - -static char * -get_local_store_uri (const char *dirname, char **namep, int *indexp) -{ - char *protocol, *name, *metadata, *tmp; - int index; - struct stat st; - xmlNodePtr node; - xmlDocPtr doc; - - metadata = g_build_filename(dirname, "local-metadata.xml", NULL); - - /* in 1.4, any errors are treated as defaults, this function cannot fail */ - - /* defaults */ - name = "mbox"; - protocol = "mbox"; - index = TRUE; - - if (stat (metadata, &st) == -1 || !S_ISREG (st.st_mode)) - goto nofile; - - doc = xmlParseFile(metadata); - if (doc == NULL) - goto nofile; - - node = doc->children; - if (strcmp((char *)node->name, "folderinfo")) - goto dodefault; - - for (node = node->children; node; node = node->next) { - if (node->name && !strcmp ((char *)node->name, "folder")) { - tmp = (char *)xmlGetProp (node, (const unsigned char *)"type"); - if (tmp) { - protocol = alloca(strlen(tmp)+1); - strcpy(protocol, tmp); - xmlFree(tmp); - } - tmp = (char *)xmlGetProp (node, (const unsigned char *)"name"); - if (tmp) { - name = alloca(strlen(tmp)+1); - strcpy(name, tmp); - xmlFree(tmp); - } - tmp = (char *)xmlGetProp (node, (const unsigned char *)"index"); - if (tmp) { - index = atoi(tmp); - xmlFree(tmp); - } - } - } -dodefault: - xmlFreeDoc (doc); -nofile: - g_free(metadata); - - *namep = g_strdup(name); - *indexp = index; - - return g_strdup_printf("%s:%s", protocol, dirname); -} - -#endif /* !G_OS_WIN32 */ - -enum { - CP_UNIQUE = 0, - CP_OVERWRITE, - CP_APPEND, -}; - -static int open_flags[3] = { - O_WRONLY | O_CREAT | O_TRUNC, - O_WRONLY | O_CREAT | O_TRUNC, - O_WRONLY | O_CREAT | O_APPEND, -}; - -static gboolean -cp (const char *src, const char *dest, gboolean show_progress, int mode) -{ - unsigned char readbuf[65536]; - ssize_t nread, nwritten; - int errnosav, readfd, writefd; - size_t total = 0; - struct stat st; - struct utimbuf ut; - - /* if the dest file exists and has content, abort - we don't - * want to corrupt their existing data */ - if (g_stat (dest, &st) == 0 && st.st_size > 0 && mode == CP_UNIQUE) { - errno = EEXIST; - return FALSE; - } - - if (g_stat (src, &st) == -1 - || (readfd = g_open (src, O_RDONLY | O_BINARY, 0)) == -1) - return FALSE; - - if ((writefd = g_open (dest, open_flags[mode] | O_BINARY, 0666)) == -1) { - errnosav = errno; - close (readfd); - errno = errnosav; - return FALSE; - } - - do { - do { - nread = read (readfd, readbuf, sizeof (readbuf)); - } while (nread == -1 && errno == EINTR); - - if (nread == 0) - break; - else if (nread < 0) - goto exception; - - do { - nwritten = write (writefd, readbuf, nread); - } while (nwritten == -1 && errno == EINTR); - - if (nwritten < nread) - goto exception; - - total += nwritten; - if (show_progress) - em_migrate_set_progress (((double) total) / ((double) st.st_size)); - } while (total < st.st_size); - - if (fsync (writefd) == -1) - goto exception; - - close (readfd); - if (close (writefd) == -1) - goto failclose; - - ut.actime = st.st_atime; - ut.modtime = st.st_mtime; - utime (dest, &ut); - chmod (dest, st.st_mode); - - return TRUE; - - exception: - - errnosav = errno; - close (readfd); - close (writefd); - errno = errnosav; - - failclose: - - errnosav = errno; - unlink (dest); - errno = errnosav; - - return FALSE; -} - -#ifndef G_OS_WIN32 - -static gboolean -cp_r (const char *src, const char *dest, const char *pattern, int mode) -{ - GString *srcpath, *destpath; - struct dirent *dent; - size_t slen, dlen; - struct stat st; - DIR *dir; - - if (g_mkdir_with_parents (dest, 0777) == -1) - return FALSE; - - if (!(dir = opendir (src))) - return FALSE; - - srcpath = g_string_new (src); - g_string_append_c (srcpath, '/'); - slen = srcpath->len; - - destpath = g_string_new (dest); - g_string_append_c (destpath, '/'); - dlen = destpath->len; - - while ((dent = readdir (dir))) { - if (!strcmp (dent->d_name, ".") || !strcmp (dent->d_name, "..")) - continue; - - g_string_truncate (srcpath, slen); - g_string_truncate (destpath, dlen); - - g_string_append (srcpath, dent->d_name); - g_string_append (destpath, dent->d_name); - - if (stat (srcpath->str, &st) == -1) - continue; - - if (S_ISDIR (st.st_mode)) { - cp_r (srcpath->str, destpath->str, pattern, mode); - } else if (!pattern || !strcmp (dent->d_name, pattern)) { - cp (srcpath->str, destpath->str, FALSE, mode); - } - } - - closedir (dir); - - g_string_free (destpath, TRUE); - g_string_free (srcpath, TRUE); - - return TRUE; -} - -static void -mbox_build_filename (GString *path, const char *toplevel_dir, const char *full_name) -{ - const char *start, *inptr = full_name; - int subdirs = 0; - - while (*inptr != '\0') { - if (*inptr == '/') - subdirs++; - inptr++; - } - - g_string_assign(path, toplevel_dir); - g_string_append_c (path, '/'); - - inptr = full_name; - while (*inptr != '\0') { - start = inptr; - while (*inptr != '/' && *inptr != '\0') - inptr++; - - g_string_append_len (path, start, inptr - start); - - if (*inptr == '/') { - g_string_append (path, ".sbd/"); - inptr++; - - /* strip extranaeous '/'s */ - while (*inptr == '/') - inptr++; - } - } -} - -static gboolean -em_migrate_folder(EMMigrateSession *session, const char *dirname, const char *full_name, GError **error) -{ - CamelFolder *old_folder = NULL, *new_folder = NULL; - CamelStore *local_store = NULL; - CamelException ex; - char *name, *uri; - GPtrArray *uids; - struct stat st; - gboolean thread_list; - int index, i; - GString *src, *dest; - gboolean success = FALSE; - - camel_exception_init (&ex); - - src = g_string_new(""); - - g_string_printf(src, "%s/folder-metadata.xml", dirname); - if (stat (src->str, &st) == -1 - || !S_ISREG (st.st_mode) - || !is_mail_folder(src->str)) { - /* Not an evolution mail folder */ - g_string_free(src, TRUE); - return TRUE; - } - - dest = g_string_new(""); - uri = get_local_store_uri(dirname, &name, &index); - em_migrate_set_folder_name (full_name); - thread_list = get_local_et_expanded (dirname); - - /* Manually copy local mbox files, its much faster */ - if (!strncmp (uri, "mbox:", 5)) { - static char *meta_ext[] = { ".summary", ".ibex.index", ".ibex.index.data" }; - size_t slen, dlen; - FILE *fp; - char *p; - int mode; - - g_string_printf (src, "%s/%s", uri + 5, name); - mbox_build_filename (dest, ((CamelService *)session->store)->url->path, full_name); - p = strrchr (dest->str, '/'); - *p = '\0'; - - slen = src->len; - dlen = dest->len; - - if (g_mkdir_with_parents (dest->str, 0777) == -1 && errno != EEXIST) { - g_set_error ( - error, E_SHELL_MIGRATE_ERROR, - E_SHELL_MIGRATE_ERROR_FAILED, - _("Unable to create new folder `%s': %s"), - dest->str, g_strerror (errno)); - goto fatal; - } - - *p = '/'; - mode = CP_UNIQUE; - retry_copy: - if (!cp (src->str, dest->str, TRUE, mode)) { - if (errno == EEXIST) { - int save = errno; - - switch (e_error_run(NULL, "mail:ask-migrate-existing", src->str, dest->str, NULL)) { - case GTK_RESPONSE_ACCEPT: - mode = CP_OVERWRITE; - goto retry_copy; - case GTK_RESPONSE_OK: - mode = CP_APPEND; - goto retry_copy; - case GTK_RESPONSE_REJECT: - goto ignore; - } - - errno = save; - } - g_set_error ( - error, E_SHELL_MIGRATE_ERROR, - E_SHELL_MIGRATE_ERROR_FAILED, - _("Unable to copy folder `%s' to `%s': %s"), - src->str, dest->str, g_strerror (errno)); - goto fatal; - } - ignore: - - /* create a .cmeta file specifying to index and/or thread the folder */ - g_string_truncate (dest, dlen); - g_string_append (dest, ".cmeta"); - if ((fp = fopen (dest->str, "w")) != NULL) { - int fd = fileno (fp); - - /* write the magic string */ - if (fwrite ("CLMD", 4, 1, fp) != 1) - goto cmeta_err; - - /* write the version (1) */ - if (camel_file_util_encode_uint32 (fp, 1) == -1) - goto cmeta_err; - - /* write the meta count */ - if (camel_file_util_encode_uint32 (fp, thread_list ? 1 : 0) == -1) - goto cmeta_err; - - if (!thread_list) { - if (camel_file_util_encode_string (fp, "evolution:thread_list") == -1) - goto cmeta_err; - - if (camel_file_util_encode_string (fp, !thread_list ? "1" : "0") == -1) - goto cmeta_err; - } - - /* write the prop count (only prop is the index prop) */ - if (camel_file_util_encode_uint32 (fp, 1) == -1) - goto cmeta_err; - - /* write the index prop tag (== CAMEL_FOLDER_ARG_LAST|CAMEL_ARG_BOO) */ - if (camel_file_util_encode_uint32 (fp, CAMEL_FOLDER_ARG_LAST|CAMEL_ARG_BOO) == -1) - goto cmeta_err; - - /* write the index prop value */ - if (camel_file_util_encode_uint32 (fp, 1) == -1) - goto cmeta_err; - - fflush (fp); - - if (fsync (fd) == -1) { - cmeta_err: - fclose (fp); - unlink (dest->str); - } else { - fclose (fp); - } - } - - /* copy over the metadata files */ - for (i = 0; i < sizeof(meta_ext)/sizeof(meta_ext[0]); i++) { - g_string_truncate (src, slen); - g_string_truncate (dest, dlen); - - g_string_append (src, meta_ext[i]); - g_string_append (dest, meta_ext[i]); - cp (src->str, dest->str, FALSE, CP_OVERWRITE); - } - } else { - guint32 flags = CAMEL_STORE_FOLDER_CREATE; - - if (!(local_store = camel_session_get_store ((CamelSession *) session, uri, &ex)) - || !(old_folder = camel_store_get_folder (local_store, name, 0, &ex))) - goto fatal; - - flags |= (index ? CAMEL_STORE_FOLDER_BODY_INDEX : 0); - if (!(new_folder = camel_store_get_folder (session->store, full_name, flags, &ex))) - goto fatal; - - if (!thread_list) { - camel_object_meta_set (new_folder, "evolution:thread_list", !thread_list ? "1" : "0"); - camel_object_state_write (new_folder); - } - - uids = camel_folder_get_uids (old_folder); - for (i = 0; i < uids->len; i++) { - CamelMimeMessage *message; - CamelMessageInfo *info; - - if (!(info = camel_folder_get_message_info (old_folder, uids->pdata[i]))) - continue; - - if (!(message = camel_folder_get_message (old_folder, uids->pdata[i], &ex))) { - camel_folder_free_message_info (old_folder, info); - camel_folder_free_uids (old_folder, uids); - goto fatal; - } - - camel_folder_append_message (new_folder, message, info, NULL, &ex); - camel_folder_free_message_info (old_folder, info); - camel_object_unref (message); - - if (camel_exception_is_set (&ex)) - break; - - em_migrate_set_progress (((double) i + 1) / ((double) uids->len)); - } - - camel_folder_free_uids (old_folder, uids); - - if (camel_exception_is_set (&ex)) - goto fatal; - } - success = TRUE; -fatal: - g_free (uri); - g_free (name); - g_string_free(src, TRUE); - g_string_free(dest, TRUE); - if (local_store) - camel_object_unref(local_store); - if (old_folder) - camel_object_unref(old_folder); - if (new_folder) - camel_object_unref(new_folder); - - if (camel_exception_is_set (&ex)) { - g_set_error ( - error, E_SHELL_MIGRATE_ERROR, - E_SHELL_MIGRATE_ERROR_FAILED, - "%s", camel_exception_get_description (&ex)); - camel_exception_clear (&ex); - } - - return success; -} - -static gboolean -em_migrate_dir (EMMigrateSession *session, const char *dirname, const char *full_name, GError **error) -{ - char *path; - DIR *dir; - struct stat st; - struct dirent *dent; - gboolean success = TRUE; - - if (!em_migrate_folder(session, dirname, full_name, error)) - return FALSE; - - /* no subfolders, not readable, don't care */ - path = g_strdup_printf ("%s/subfolders", dirname); - if (stat (path, &st) == -1 || !S_ISDIR (st.st_mode)) { - g_free (path); - return TRUE; - } - - if (!(dir = opendir (path))) { - g_free (path); - return TRUE; - } - - while (success && (dent = readdir (dir))) { - char *full_path; - char *name; - - if (dent->d_name[0] == '.') - continue; - - full_path = g_strdup_printf ("%s/%s", path, dent->d_name); - if (stat (full_path, &st) == -1 || !S_ISDIR (st.st_mode)) { - g_free (full_path); - continue; - } - - name = g_strdup_printf ("%s/%s", full_name, dent->d_name); - success = em_migrate_dir (session, full_path, name, error); - g_free (full_path); - g_free (name); - } - - closedir (dir); - - g_free (path); - - return success; -} - -static gboolean -em_migrate_local_folders_1_4 (EMMigrateSession *session, GError **error) -{ - struct dirent *dent; - struct stat st; - DIR *dir; - gboolean success = TRUE; - - if (!(dir = opendir (session->srcdir))) { - g_set_error ( - error, E_SHELL_MIGRATE_ERROR, - E_SHELL_MIGRATE_ERROR_FAILED, - _("Unable to scan for existing mailboxes at " - "`%s': %s"), session->srcdir, g_strerror (errno)); - return FALSE; - } - - 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 (success && (dent = readdir (dir))) { - char *full_path; - - if (dent->d_name[0] == '.') - continue; - - full_path = g_strdup_printf ("%s/%s", session->srcdir, dent->d_name); - if (stat (full_path, &st) == -1 || !S_ISDIR (st.st_mode)) { - g_free (full_path); - continue; - } - - success = em_migrate_dir (session, full_path, dent->d_name, error); - g_free (full_path); - } - - closedir (dir); - - em_migrate_close_progress_dialog (); - - return success; -} - -static char * -upgrade_xml_uris_1_4 (const char *uri) -{ - char *path, *prefix, *p; - CamelURL *url; - - if (!strncmp (uri, "file:", 5)) { - url = camel_url_new (uri, NULL); - camel_url_set_protocol (url, "email"); - camel_url_set_user (url, "local"); - camel_url_set_host (url, "local"); - - prefix = g_build_filename (g_get_home_dir (), "evolution", "local", NULL); - if (strncmp (url->path, prefix, strlen (prefix)) != 0) { - /* uri is busticated - user probably copied from another user's home directory */ - camel_url_free (url); - g_free (prefix); - - return g_strdup (uri); - } - path = g_strdup (url->path + strlen (prefix)); - g_free (prefix); - - /* modify the path in-place */ - p = path + strlen (path) - 12; - while (p > path) { - if (!strncmp (p, "/subfolders/", 12)) - memmove (p, p + 11, strlen (p + 11) + 1); - - p--; - } - - camel_url_set_path (url, path); - g_free (path); - - path = camel_url_to_string (url, 0); - camel_url_free (url); - - return path; - } else { - return em_uri_from_camel (uri); - } -} - -static void -upgrade_vfolder_sources_1_4 (xmlDocPtr doc) -{ - xmlNodePtr root, node; - - if (!doc || !(root = xmlDocGetRootElement (doc))) - return; - - if (!root->name || strcmp ((char *)root->name, "filteroptions") != 0) { - /* root node is not , nothing to upgrade */ - return; - } - - if (!(node = xml_find_node (root, "ruleset"))) { - /* no ruleset node, nothing to upgrade */ - return; - } - - node = node->children; - while (node != NULL) { - if (node->name && !strcmp ((char *)node->name, "rule")) { - xmlNodePtr sources; - char *src; - - if (!(src = (char *)xmlGetProp (node, (const unsigned char *)"source"))) - src = (char *)xmlStrdup ((const unsigned char *)"local"); /* default to all local folders? */ - - xmlSetProp (node, (const unsigned char *)"source", (const unsigned char *)"incoming"); - - if (!(sources = xml_find_node (node, "sources"))) - sources = xmlNewChild (node, NULL, (const unsigned char *)"sources", NULL); - - xmlSetProp (sources, (const unsigned char *)"with", (unsigned char *)src); - xmlFree (src); - } - - node = node->next; - } -} - -static char * -get_nth_sig (int id) -{ - ESignatureList *list; - ESignature *sig; - EIterator *iter; - char *uid = NULL; - int i = 0; - - list = e_get_signature_list (); - iter = e_list_get_iterator ((EList *) list); - - while (e_iterator_is_valid (iter) && i < id) { - e_iterator_next (iter); - i++; - } - - if (i == id && e_iterator_is_valid (iter)) { - sig = (ESignature *) e_iterator_get (iter); - uid = g_strdup (sig->uid); - } - - g_object_unref (iter); - - return uid; -} - -static void -em_upgrade_accounts_1_4 (void) -{ - EAccountList *accounts; - EIterator *iter; - - if (!(accounts = e_get_account_list ())) - return; - - iter = e_list_get_iterator ((EList *) accounts); - while (e_iterator_is_valid (iter)) { - EAccount *account = (EAccount *) e_iterator_get (iter); - char *url; - - if (account->drafts_folder_uri) { - url = upgrade_xml_uris_1_4 (account->drafts_folder_uri); - g_free (account->drafts_folder_uri); - account->drafts_folder_uri = url; - } - - if (account->sent_folder_uri) { - url = upgrade_xml_uris_1_4 (account->sent_folder_uri); - g_free (account->sent_folder_uri); - account->sent_folder_uri = url; - } - - if (account->id->sig_uid && !strncmp (account->id->sig_uid, "::", 2)) { - int sig_id; - - sig_id = strtol (account->id->sig_uid + 2, NULL, 10); - g_free (account->id->sig_uid); - account->id->sig_uid = get_nth_sig (sig_id); - } - - e_iterator_next (iter); - } - - g_object_unref (iter); - - e_account_list_save (accounts); -} - -static gboolean -em_migrate_pop_uid_caches_1_4 (const char *data_dir, GError **error) -{ - GString *oldpath, *newpath; - struct dirent *dent; - size_t olen, nlen; - char *cache_dir; - DIR *dir; - gboolean success = TRUE; - - /* Sigh, too many unique strings to translate, for cases which shouldn't ever happen */ - - /* open the old cache dir */ - cache_dir = g_build_filename (g_get_home_dir (), "evolution", "mail", "pop3", NULL); - if (!(dir = opendir (cache_dir))) { - if (errno == ENOENT) { - g_free(cache_dir); - return TRUE; - } - - g_set_error ( - error, E_SHELL_MIGRATE_ERROR, - E_SHELL_MIGRATE_ERROR_FAILED, - _("Unable to open old POP keep-on-server data " - "`%s': %s"), cache_dir, g_strerror (errno)); - g_free (cache_dir); - return FALSE; - } - - oldpath = g_string_new (cache_dir); - g_string_append_c (oldpath, '/'); - olen = oldpath->len; - g_free (cache_dir); - - cache_dir = g_build_filename (data_dir, "pop", NULL); - if (g_mkdir_with_parents (cache_dir, 0777) == -1) { - g_set_error ( - error, E_SHELL_MIGRATE_ERROR, - E_SHELL_MIGRATE_ERROR_FAILED, - _("Unable to create POP3 keep-on-server data " - "directory `%s': %s"), cache_dir, - g_strerror (errno)); - g_string_free (oldpath, TRUE); - g_free (cache_dir); - closedir (dir); - return FALSE; - } - - newpath = g_string_new (cache_dir); - g_string_append_c (newpath, '/'); - nlen = newpath->len; - g_free (cache_dir); - - while (success && (dent = readdir (dir))) { - if (strncmp (dent->d_name, "cache-pop:__", 12) != 0) - continue; - - g_string_truncate (oldpath, olen); - g_string_truncate (newpath, nlen); - - g_string_append (oldpath, dent->d_name); - g_string_append (newpath, dent->d_name + 12); - - /* strip the trailing '_' */ - g_string_truncate (newpath, newpath->len - 1); - - if (g_mkdir_with_parents (newpath->str, 0777) == -1 - || !cp(oldpath->str, (g_string_append(newpath, "/uid-cache"))->str, FALSE, CP_UNIQUE)) { - g_set_error ( - error, E_SHELL_MIGRATE_ERROR, - E_SHELL_MIGRATE_ERROR_FAILED, - _("Unable to copy POP3 keep-on-server data " - "`%s': %s"), oldpath->str, - g_strerror (errno)); - success = FALSE; - } - - } - - g_string_free (oldpath, TRUE); - g_string_free (newpath, TRUE); - - closedir (dir); - - return success; -} - -static gboolean -em_migrate_imap_caches_1_4 (const char *data_dir, GError **error) -{ - char *src, *dest; - struct stat st; - - src = g_build_filename (g_get_home_dir (), "evolution", "mail", "imap", NULL); - if (stat (src, &st) == -1 || !S_ISDIR (st.st_mode)) { - g_free (src); - return TRUE; - } - - dest = g_build_filename (data_dir, "imap", NULL); - - /* we don't care if this fails, it's only a cache... */ - cp_r (src, dest, "summary", CP_OVERWRITE); - - g_free (dest); - g_free (src); - - return TRUE; -} - -static gboolean -em_migrate_folder_expand_state_1_4 (const char *data_dir, GError **error) -{ - GString *srcpath, *destpath; - size_t slen, dlen, rlen; - char *evo14_mbox_root; - struct dirent *dent; - struct stat st; - DIR *dir; - - srcpath = g_string_new (g_get_home_dir ()); - g_string_append (srcpath, "/evolution/config"); - if (stat (srcpath->str, &st) == -1 || !S_ISDIR (st.st_mode)) { - g_string_free (srcpath, TRUE); - return TRUE; - } - - destpath = g_string_new (data_dir); - g_string_append (destpath, "/config"); - if (g_mkdir_with_parents (destpath->str, 0777) == -1 || !(dir = opendir (srcpath->str))) { - g_string_free (destpath, TRUE); - g_string_free (srcpath, TRUE); - return TRUE; - } - - g_string_append (srcpath, "/et-expanded-"); - slen = srcpath->len; - g_string_append (destpath, "/et-expanded-"); - dlen = destpath->len; - - evo14_mbox_root = g_build_filename (g_get_home_dir (), "evolution", "local", NULL); - e_filename_make_safe (evo14_mbox_root); - rlen = strlen (evo14_mbox_root); - evo14_mbox_root = g_realloc (evo14_mbox_root, rlen + 2); - evo14_mbox_root[rlen++] = '_'; - evo14_mbox_root[rlen] = '\0'; - - while ((dent = readdir (dir))) { - char *full_name, *inptr, *buf = NULL; - const char *filename; - GString *new; - - if (strncmp (dent->d_name, "et-expanded-", 12) != 0) - continue; - - if (!strncmp (dent->d_name + 12, "file:", 5)) { - /* need to munge the filename */ - inptr = dent->d_name + 17; - - if (!strncmp (inptr, evo14_mbox_root, rlen)) { - /* this should always be the case afaik... */ - inptr += rlen; - new = g_string_new ("mbox:"); - g_string_append_printf (new, "%s/local#", data_dir); - - full_name = g_strdup (inptr); - inptr = full_name + strlen (full_name) - 12; - while (inptr > full_name) { - if (!strncmp (inptr, "_subfolders_", 12)) - memmove (inptr, inptr + 11, strlen (inptr + 11) + 1); - - inptr--; - } - - g_string_append (new, full_name); - g_free (full_name); - - filename = buf = new->str; - g_string_free (new, FALSE); - e_filename_make_safe (buf); - } else { - /* but just in case... */ - filename = dent->d_name + 12; - } - } else { - /* no munging needed */ - filename = dent->d_name + 12; - } - - g_string_append (srcpath, dent->d_name + 12); - g_string_append (destpath, filename); - g_free (buf); - - cp (srcpath->str, destpath->str, FALSE, CP_UNIQUE); - - g_string_truncate (srcpath, slen); - g_string_truncate (destpath, dlen); - } - - closedir (dir); - - g_free (evo14_mbox_root); - g_string_free (destpath, TRUE); - g_string_free (srcpath, TRUE); - - return TRUE; -} - -static gboolean -em_migrate_folder_view_settings_1_4 (const char *data_dir, GError **error) -{ - GString *srcpath, *destpath; - size_t slen, dlen, rlen; - char *evo14_mbox_root; - struct dirent *dent; - struct stat st; - DIR *dir; - - srcpath = g_string_new (g_get_home_dir ()); - g_string_append (srcpath, "/evolution/views/mail"); - if (stat (srcpath->str, &st) == -1 || !S_ISDIR (st.st_mode)) { - g_string_free (srcpath, TRUE); - return TRUE; - } - - destpath = g_string_new (data_dir); - g_string_append (destpath, "/views"); - if (g_mkdir_with_parents (destpath->str, 0777) == -1 || !(dir = opendir (srcpath->str))) { - g_string_free (destpath, TRUE); - g_string_free (srcpath, TRUE); - return TRUE; - } - - g_string_append_c (srcpath, '/'); - slen = srcpath->len; - g_string_append_c (destpath, '/'); - dlen = destpath->len; - - evo14_mbox_root = g_build_filename (g_get_home_dir (), "evolution", "local", NULL); - e_filename_make_safe (evo14_mbox_root); - rlen = strlen (evo14_mbox_root); - evo14_mbox_root = g_realloc (evo14_mbox_root, rlen + 2); - evo14_mbox_root[rlen++] = '_'; - evo14_mbox_root[rlen] = '\0'; - - while ((dent = readdir (dir))) { - char *full_name, *inptr, *buf = NULL; - const char *filename, *ext; - size_t prelen = 0; - GString *new; - - if (dent->d_name[0] == '.') - continue; - - if (!(ext = strrchr (dent->d_name, '.'))) - continue; - - if (!strcmp (ext, ".galview") || !strcmp ((char *)dent->d_name, "galview.xml")) { - /* just copy the file */ - filename = dent->d_name; - goto copy; - } else if (strcmp (ext, ".xml") != 0) { - continue; - } - - if (!strncmp ((const char *)dent->d_name, "current_view-", 13)) { - prelen = 13; - } else if (!strncmp ((const char *)dent->d_name, "custom_view-", 12)) { - prelen = 12; - } else { - /* huh? wtf is this file? */ - continue; - } - - if (!strncmp (dent->d_name + prelen, "file:", 5)) { - /* need to munge the filename */ - inptr = dent->d_name + prelen + 5; - - if (!strncmp (inptr, evo14_mbox_root, rlen)) { - /* this should always be the case afaik... */ - inptr += rlen; - new = g_string_new ("mbox:"); - g_string_append_printf (new, "%s/local#", data_dir); - - full_name = g_strdup (inptr); - inptr = full_name + strlen (full_name) - 12; - while (inptr > full_name) { - if (!strncmp (inptr, "_subfolders_", 12)) - memmove (inptr, inptr + 11, strlen (inptr + 11) + 1); - - inptr--; - } - - g_string_append (new, full_name); - g_free (full_name); - - filename = buf = new->str; - g_string_free (new, FALSE); - e_filename_make_safe (buf); - } else { - /* but just in case... */ - filename = dent->d_name + prelen; - } - } else { - /* no munging needed */ - filename = dent->d_name + prelen; - } - - copy: - g_string_append (srcpath, dent->d_name); - if (prelen > 0) - g_string_append_len (destpath, dent->d_name, prelen); - g_string_append (destpath, filename); - g_free (buf); - - cp (srcpath->str, destpath->str, FALSE, CP_UNIQUE); - - g_string_truncate (srcpath, slen); - g_string_truncate (destpath, dlen); - } - - closedir (dir); - - g_free (evo14_mbox_root); - g_string_free (destpath, TRUE); - g_string_free (srcpath, TRUE); - - return TRUE; -} - -#define SUBFOLDER_DIR_NAME "subfolders" -#define SUBFOLDER_DIR_NAME_LEN 10 - -static char * -e_path_to_physical (const char *prefix, const char *vpath) -{ - const char *p, *newp; - char *dp; - char *ppath; - int ppath_len; - int prefix_len; - - while (*vpath == '/') - vpath++; - if (!prefix) - prefix = ""; - - /* Calculate the length of the real path. */ - ppath_len = strlen (vpath); - ppath_len++; /* For the ending zero. */ - - prefix_len = strlen (prefix); - ppath_len += prefix_len; - ppath_len++; /* For the separating slash. */ - - /* Take account of the fact that we need to translate every - * separator into `subfolders/'. - */ - p = vpath; - while (1) { - newp = strchr (p, '/'); - if (newp == NULL) - break; - - ppath_len += SUBFOLDER_DIR_NAME_LEN; - ppath_len++; /* For the separating slash. */ - - /* Skip consecutive slashes. */ - while (*newp == '/') - newp++; - - p = newp; - }; - - ppath = g_malloc (ppath_len); - dp = ppath; - - memcpy (dp, prefix, prefix_len); - dp += prefix_len; - *(dp++) = '/'; - - /* Copy the mangled path. */ - p = vpath; - while (1) { - newp = strchr (p, '/'); - if (newp == NULL) { - strcpy (dp, p); - break; - } - - memcpy (dp, p, newp - p + 1); /* `+ 1' to copy the slash too. */ - dp += newp - p + 1; - - memcpy (dp, SUBFOLDER_DIR_NAME, SUBFOLDER_DIR_NAME_LEN); - dp += SUBFOLDER_DIR_NAME_LEN; - - *(dp++) = '/'; - - /* Skip consecutive slashes. */ - while (*newp == '/') - newp++; - - p = newp; - } - - return ppath; -} - -static gboolean -em_migrate_imap_cmeta_1_4(const char *data_dir, GError **error) -{ - GConfClient *gconf; - GSList *paths, *p; - EAccountList *accounts; - const EAccount *account; - - if (!(accounts = e_get_account_list ())) - return TRUE; - - gconf = gconf_client_get_default(); - paths = gconf_client_get_list(gconf, "/apps/evolution/shell/offline/folder_paths", GCONF_VALUE_STRING, NULL); - for (p = paths;p;p = g_slist_next(p)) { - char *name, *path; - - name = p->data; - if (*name) - name++; - path = strchr(name, '/'); - if (path) { - *path++ = 0; - account = e_account_list_find(accounts, E_ACCOUNT_FIND_NAME, name); - if (account && !strncmp(account->source->url, "imap:", 5)) { - CamelURL *url = camel_url_new(account->source->url, NULL); - - if (url) { - char *dir, *base; - - base = g_strdup_printf("%s/imap/%s@%s/folders", - data_dir, - url->user?url->user:"", - url->host?url->host:""); - - dir = e_path_to_physical(base, path); - if (g_mkdir_with_parents(dir, 0777) == 0) { - char *cmeta; - FILE *fp; - - cmeta = g_build_filename(dir, "cmeta", NULL); - fp = fopen(cmeta, "w"); - if (fp) { - /* header/version */ - fwrite("CLMD", 4, 1, fp); - camel_file_util_encode_uint32(fp, 1); - /* meta count, do we have any metadata? */ - camel_file_util_encode_uint32(fp, 0); - /* prop count */ - camel_file_util_encode_uint32(fp, 1); - /* sync offline property */ - camel_file_util_encode_uint32(fp, CAMEL_DISCO_FOLDER_OFFLINE_SYNC); - camel_file_util_encode_uint32(fp, 1); - fclose(fp); - } else { - g_warning("couldn't create imap folder cmeta file '%s'", cmeta); - } - g_free(cmeta); - } else { - g_warning("couldn't create imap folder directory '%s'", dir); - } - g_free(dir); - g_free(base); - camel_url_free(url); - } - } else - g_warning("can't find offline folder '%s' '%s'", name, path); - } - g_free(p->data); - } - g_slist_free(paths); - g_object_unref(gconf); - - /* we couldn't care less if this doesn't work */ - - return TRUE; -} - -static void -remove_system_searches(xmlDocPtr searches) -{ - xmlNodePtr node; - - /* in pre 2.0, system searches were stored in the user - * searches.xml file with the source set to 'demand'. In 2.0+ - * the system searches are stored in the system - * searchtypes.xml file instead */ - - node = xmlDocGetRootElement(searches); - if (!node->name || strcmp((char *)node->name, "filteroptions")) - return; - - if (!(node = xml_find_node(node, "ruleset"))) - return; - - node = node->children; - while (node != NULL) { - xmlNodePtr nnode = node->next; - - if (node->name && !strcmp ((char *)node->name, "rule")) { - char *src; - - src = (char *)xmlGetProp(node, (unsigned char *)"source"); - if (src && !strcmp((char *)src, "demand")) { - xmlUnlinkNode(node); - xmlFreeNodeList(node); - } - xmlFree (src); - } - - node = nnode; - } -} - -static gboolean -em_migrate_1_4 (const char *data_dir, xmlDocPtr filters, xmlDocPtr vfolders, GError **error) -{ - EMMigrateSession *session; - CamelException lex; - struct stat st; - gchar *path; - xmlDocPtr searches; - - camel_init (data_dir, TRUE); - camel_provider_init(); - session = (EMMigrateSession *) em_migrate_session_new (data_dir); - - session->srcdir = g_build_filename (g_get_home_dir (), "evolution", "local", NULL); - - path = g_strdup_printf ("mbox:%s/.evolution/mail/local", g_get_home_dir ()); - if (stat (path + 5, &st) == -1) { - if (errno != ENOENT || g_mkdir_with_parents (path + 5, 0777) == -1) { - g_set_error ( - error, E_SHELL_MIGRATE_ERROR, - E_SHELL_MIGRATE_ERROR_FAILED, - _("Failed to create local mail storage " - "`%s': %s"), path + 5, g_strerror (errno)); - g_free (session->srcdir); - camel_object_unref (session); - g_free (path); - return FALSE; - } - } - - camel_exception_init (&lex); - if (!(session->store = camel_session_get_store ((CamelSession *) session, path, &lex))) { - g_set_error ( - error, E_SHELL_MIGRATE_ERROR, - E_SHELL_MIGRATE_ERROR_FAILED, - _("Failed to create local mail storage `%s': %s"), - path, lex.desc); - g_free (session->srcdir); - camel_object_unref (session); - camel_exception_clear (&lex); - g_free (path); - return FALSE; - } - g_free (path); - - if (!em_migrate_local_folders_1_4 (session, error)) - return FALSE; - - camel_object_unref (session->store); - g_free (session->srcdir); - - camel_object_unref (session); - - em_upgrade_accounts_1_4(); - - upgrade_xml_uris(filters, upgrade_xml_uris_1_4); - upgrade_vfolder_sources_1_4(vfolders); - upgrade_xml_uris(vfolders, upgrade_xml_uris_1_4); - - path = g_build_filename(g_get_home_dir(), "evolution", NULL); - searches = emm_load_xml(path, "searches.xml"); - g_free(path); - if (searches) { - remove_system_searches(searches); - emm_save_xml(searches, data_dir, "searches.xml"); - xmlFreeDoc(searches); - } - - if (!em_migrate_pop_uid_caches_1_4 (data_dir, error)) - return FALSE; - - /* these are non-fatal */ - em_migrate_imap_caches_1_4 (data_dir, error); - g_clear_error (error); - em_migrate_folder_expand_state_1_4 (data_dir, error); - g_clear_error (error); - em_migrate_folder_view_settings_1_4 (data_dir, error); - g_clear_error (error); - em_migrate_imap_cmeta_1_4 (data_dir, error); - g_clear_error (error); - - return TRUE; -} - -static void -em_update_accounts_2_11 (void) -{ - EAccountList *accounts; - EIterator *iter; - gboolean changed = FALSE; - - if (!(accounts = e_get_account_list ())) - return; - - iter = e_list_get_iterator ((EList *) accounts); - while (e_iterator_is_valid (iter)) { - EAccount *account = (EAccount *) e_iterator_get (iter); - - if (g_str_has_prefix (account->source->url, "spool://")) { - if (g_file_test (account->source->url + 8, G_FILE_TEST_IS_DIR)) { - char *str = g_strdup_printf ("spooldir://%s", account->source->url + 8); - - g_free (account->source->url); - account->source->url = str; - changed = TRUE; - } - } - - e_iterator_next (iter); - } - - g_object_unref (iter); - - if (changed) - e_account_list_save (accounts); -} - -#endif /* !G_OS_WIN32 */ - -static gboolean -emm_setup_initial(const gchar *data_dir) -{ - GDir *dir; - const char *d; - char *local = NULL, *base; - const gchar * const *language_names; - - /* special-case - this means brand new install of evolution */ - /* FIXME: create default folders and stuff... */ - - d(printf("Setting up initial mail tree\n")); - - base = g_build_filename(data_dir, "local", NULL); - if (g_mkdir_with_parents(base, 0777) == -1 && errno != EEXIST) { - g_free(base); - return FALSE; - } - - /* e.g. try en-AU then en, etc */ - language_names = g_get_language_names (); - while (*language_names != NULL) { - local = g_build_filename ( - EVOLUTION_PRIVDATADIR, "default", - *language_names, "mail", "local", NULL); - if (g_file_test (local, G_FILE_TEST_EXISTS)) - break; - g_free (local); - language_names++; - } - - /* Make sure we found one. */ - g_return_val_if_fail (*language_names != NULL, FALSE); - - dir = g_dir_open(local, 0, NULL); - if (dir) { - while ((d = g_dir_read_name(dir))) { - char *src, *dest; - - src = g_build_filename(local, d, NULL); - dest = g_build_filename(base, d, NULL); - - cp(src, dest, FALSE, CP_UNIQUE); - g_free(dest); - g_free(src); - } - g_dir_close(dir); - } - - g_free(local); - g_free(base); - - return TRUE; -} - -static gboolean -is_in_plugs_list (GSList *list, const gchar *value) -{ - GSList *l; - - for (l = list; l; l = l->next) { - if (l->data && !strcmp (l->data, value)) - return TRUE; - } - - return FALSE; -} - -/* - * em_update_message_notify_settings_2_21 - * DBus plugin and sound email notification was merged to mail-notification plugin, - * so move these options to new locations. - */ -static void -em_update_message_notify_settings_2_21 (void) -{ - GConfClient *client; - GConfValue *is_key; - gboolean dbus, status; - GSList *list; - gchar *str; - gint val; - - client = gconf_client_get_default (); - - is_key = gconf_client_get (client, "/apps/evolution/eplugin/mail-notification/dbus-enabled", NULL); - if (is_key) { - /* already migrated, so do not migrate again */ - gconf_value_free (is_key); - g_object_unref (client); - - return; - } - - gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/status-blink-icon", - gconf_client_get_bool (client, "/apps/evolution/mail/notification/blink-status-icon", NULL), NULL); - gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/status-notification", - gconf_client_get_bool (client, "/apps/evolution/mail/notification/notification", NULL), NULL); - - list = gconf_client_get_list (client, "/apps/evolution/eplugin/disabled", GCONF_VALUE_STRING, NULL); - dbus = !is_in_plugs_list (list, "org.gnome.evolution.new_mail_notify"); - status = !is_in_plugs_list (list, "org.gnome.evolution.mail_notification"); - - gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/dbus-enabled", dbus, NULL); - gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/status-enabled", status, NULL); - - if (!status) { - /* enable this plugin, because it holds all those other things */ - GSList *plugins, *l; - - plugins = e_plugin_list_plugins (); - - for (l = plugins; l; l = l->next) { - EPlugin *p = l->data; - - if (p && p->id && !strcmp (p->id, "org.gnome.evolution.mail_notification")) { - e_plugin_enable (p, 1); - break; - } - } - - g_slist_foreach (plugins, (GFunc)g_object_unref, NULL); - g_slist_free (plugins); - } - - g_slist_foreach (list, (GFunc) g_free, NULL); - g_slist_free (list); - - val = gconf_client_get_int (client, "/apps/evolution/mail/notify/type", NULL); - gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/sound-enabled", val == 1 || val == 2, NULL); - gconf_client_set_bool (client, "/apps/evolution/eplugin/mail-notification/sound-beep", val == 0 || val == 1, NULL); - - str = gconf_client_get_string (client, "/apps/evolution/mail/notify/sound", NULL); - gconf_client_set_string (client, "/apps/evolution/eplugin/mail-notification/sound-file", str ? str : "", NULL); - g_free (str); - - g_object_unref (client); -} - -/* fixing typo in SpamAssassin name */ -static void -em_update_sa_junk_setting_2_23 (void) -{ - GConfClient *client; - GConfValue *key; - - client = gconf_client_get_default (); - - key = gconf_client_get (client, "/apps/evolution/mail/junk/default_plugin", NULL); - if (key) { - const char *str = gconf_value_get_string (key); - - if (str && strcmp (str, "Spamassasin") == 0) - gconf_client_set_string (client, "/apps/evolution/mail/junk/default_plugin", "SpamAssassin", NULL); - - gconf_value_free (key); - g_object_unref (client); - - return; - } - - 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); - if (folder != NULL) - camel_folder_summary_migrate_infos (folder->summary); - migrate_folders(store, fi->child, acc, ex); - fi = fi->next; - } -} - -static CamelStore * -setup_local_store (EShellModule *shell_module, - EMMigrateSession *session) -{ - CamelURL *url; - const gchar *data_dir; - char *tmp; - CamelStore *store; - - url = camel_url_new("mbox:", NULL); - data_dir = e_shell_module_get_data_dir (shell_module); - tmp = g_build_filename (data_dir, "local", NULL); - camel_url_set_path(url, tmp); - g_free(tmp); - tmp = camel_url_to_string(url, 0); - store = (CamelStore *)camel_session_get_service(CAMEL_SESSION (session), tmp, CAMEL_PROVIDER_STORE, NULL); - g_free(tmp); - - return store; - -} -static void -migrate_to_db (EShellModule *shell_module) -{ - EMMigrateSession *session; - EAccountList *accounts; - EIterator *iter; - int i=0, len; - CamelStore *store = NULL; - CamelFolderInfo *info; - const gchar *data_dir; - - if (!(accounts = e_get_account_list ())) - return; - - iter = e_list_get_iterator ((EList *) accounts); - len = e_list_length ((EList *) accounts); - - data_dir = e_shell_module_get_data_dir (shell_module); - session = (EMMigrateSession *) em_migrate_session_new (data_dir); - 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 (shell_module, session); - 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); - e_mail_shell_module_load_store_by_uri ( - shell_module, service->url, name); - - store = (CamelStore *) camel_session_get_service (CAMEL_SESSION (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:%s: failed to get folder infos \n", G_STRLOC, G_STRFUNC); - 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 (); - - g_object_unref (session); -} - -gboolean -e_mail_shell_module_migrate (EShellModule *shell_module, - gint major, - gint minor, - gint micro, - GError **error) -{ - struct stat st; - const gchar *data_dir; - gchar *path; - - /* make sure ~/.evolution/mail exists */ - data_dir = e_shell_module_get_data_dir (shell_module); - if (g_stat (data_dir, &st) == -1) { - if (errno != ENOENT || g_mkdir_with_parents (data_dir, 0777) == -1) { - g_set_error ( - error, E_SHELL_MIGRATE_ERROR, - E_SHELL_MIGRATE_ERROR_FAILED, - _("Unable to create local mail folders at " - "`%s': %s"), data_dir, g_strerror (errno)); - return FALSE; - } - } - - if (major == 0) - return emm_setup_initial (data_dir); - - if (major == 1 && minor < 5) { -#ifndef G_OS_WIN32 - xmlDocPtr config_xmldb = NULL, filters, vfolders; - - path = g_build_filename (g_get_home_dir (), "evolution", NULL); - if (minor <= 2 && !(config_xmldb = emm_load_xml (path, "config.xmldb"))) { - g_set_error ( - error, E_SHELL_MIGRATE_ERROR, - E_SHELL_MIGRATE_ERROR_FAILED, - _("Unable to read settings from previous " - "Evolution install, `evolution/config.xmldb' " - "does not exist or is corrupt.")); - return FALSE; - } - filters = emm_load_xml (path, "filters.xml"); - vfolders = emm_load_xml (path, "vfolders.xml"); - g_free (path); - - if (minor == 0) { - if (!em_migrate_1_0 (data_dir, config_xmldb, filters, vfolders, error)) { - xmlFreeDoc (config_xmldb); - xmlFreeDoc (filters); - xmlFreeDoc (vfolders); - return FALSE; - } - } - - if (minor <= 2) { - if (!em_migrate_1_2 (data_dir, config_xmldb, filters, vfolders, error)) { - xmlFreeDoc (config_xmldb); - xmlFreeDoc (filters); - xmlFreeDoc (vfolders); - return FALSE; - } - - xmlFreeDoc (config_xmldb); - } - - if (minor <= 4) { - if (!em_migrate_1_4 (data_dir, filters, vfolders, error)) { - xmlFreeDoc (filters); - xmlFreeDoc (vfolders); - return FALSE; - } - } - - if (filters) { - emm_save_xml (filters, path, "filters.xml"); - xmlFreeDoc (filters); - } - - if (vfolders) { - emm_save_xml (vfolders, path, "vfolders.xml"); - xmlFreeDoc (vfolders); - } - - g_free (path); -#else - g_error ("Upgrading from ancient versions not supported on Windows"); -#endif - } - - if (major < 2 || (major == 2 && minor < 12)) { -#ifndef G_OS_WIN32 - em_update_accounts_2_11 (); -#else - g_error ("Upgrading from ancient versions not supported on Windows"); -#endif - } - - - if (major < 2 || (major == 2 && minor < 22)) - em_update_message_notify_settings_2_21 (); - - if (major < 2 || (major == 2 && minor < 24)) { - em_update_sa_junk_setting_2_23 (); - migrate_to_db (shell_module); - } - - return TRUE; -} diff --git a/mail/e-mail-shell-module-migrate.h b/mail/e-mail-shell-module-migrate.h deleted file mode 100644 index e9ec2115c0..0000000000 --- a/mail/e-mail-shell-module-migrate.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * e-mail-shell-module-migrate.h - * - * 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 - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_MAIL_SHELL_MODULE_MIGRATE_H -#define E_MAIL_SHELL_MODULE_MIGRATE_H - -#include -#include - -G_BEGIN_DECLS - -gboolean e_mail_shell_module_migrate (EShellModule *shell_module, - gint major, - gint minor, - gint micro, - GError **error); - -G_END_DECLS - -#endif /* E_MAIL_SHELL_MODULE_MIGRATE_H */ diff --git a/mail/e-mail-shell-module-settings.c b/mail/e-mail-shell-module-settings.c deleted file mode 100644 index 94bfd1ac11..0000000000 --- a/mail/e-mail-shell-module-settings.c +++ /dev/null @@ -1,521 +0,0 @@ -/* - * e-mail-shell-module-settings.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 - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#include "e-mail-shell-module-settings.h" - -#include -#include - -#include "e-util/e-signature-list.h" -#include "mail/e-mail-label-list-store.h" -#include "mail/mail-session.h" - -void -e_mail_shell_module_init_settings (EShell *shell) -{ - EShellSettings *shell_settings; - gpointer object; - - shell_settings = e_shell_get_shell_settings (shell); - - /* XXX Default values should match the GConf schema. - * Yes it's redundant, but we're stuck with GConf. */ - - /*** Global Objects ***/ - - e_shell_settings_install_property ( - g_param_spec_object ( - "mail-label-list-store", - NULL, - NULL, - E_TYPE_MAIL_LABEL_LIST_STORE, - G_PARAM_READWRITE)); - - object = e_mail_label_list_store_new (); - e_shell_settings_set_object ( - shell_settings, "mail-label-list-store", object); - g_object_unref (object); - - e_shell_settings_install_property ( - g_param_spec_pointer ( - "mail-session", - NULL, - NULL, - G_PARAM_READWRITE)); - - camel_object_ref (session); - e_shell_settings_set_pointer ( - shell_settings, "mail-session", session); - - /*** Mail Preferences ***/ - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "mail-address-compress", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-address-compress", - "/apps/evolution/mail/display/address_compress"); - - e_shell_settings_install_property ( - g_param_spec_int ( - "mail-address-count", - NULL, - NULL, - G_MININT, - G_MAXINT, - 0, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-address-count", - "/apps/evolution/mail/display/address_count"); - - e_shell_settings_install_property ( - g_param_spec_string ( - "mail-charset-default", - NULL, - NULL, - NULL, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-charset-default", - "/apps/evolution/mail/display/charset"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "mail-check-for-junk", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-check-for-junk", - "/apps/evolution/mail/junk/check_incoming"); - - e_shell_settings_install_property ( - g_param_spec_string ( - "mail-citation-color", - NULL, - NULL, - "#737373", - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-citation-color", - "/apps/evolution/mail/display/citation_colour"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "mail-confirm-expunge", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-confirm-expunge", - "/apps/evolution/mail/prompts/expunge"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "mail-confirm-unwanted-html", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-confirm-unwanted-html", - "/apps/evolution/mail/prompts/unwanted_html"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "mail-empty-trash-on-exit", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-empty-trash-on-exit", - "/apps/evolution/mail/trash/empty_on_exit"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "mail-enable-search-folders", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-enable-search-folders", - "/apps/evolution/mail/display/enable_vfolders"); - - e_shell_settings_install_property ( - g_param_spec_string ( - "mail-font-monospace", - NULL, - NULL, - "", - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-font-monospace", - "/apps/evolution/mail/display/fonts/monospace"); - - e_shell_settings_install_property ( - g_param_spec_string ( - "mail-font-variable", - NULL, - NULL, - "", - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-font-variable", - "/apps/evolution/mail/display/fonts/variable"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "mail-force-message-limit", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-force-message-limit", - "/apps/evolution/mail/display/force_message_limit"); - - /* This value corresponds to MailConfigForwardStyle enum. */ - e_shell_settings_install_property ( - g_param_spec_int ( - "mail-forward-style", - NULL, - NULL, - 0, - G_MAXINT, - 0, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-forward-style", - "/apps/evolution/mail/format/forward_style"); - - /* This value corresponds to MailConfigHTTPMode enum. */ - e_shell_settings_install_property ( - g_param_spec_int ( - "mail-image-loading-policy", - NULL, - NULL, - 0, - G_MAXINT, - 0, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-image-loading-policy", - "/apps/evolution/mail/display/load_http_images"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "mail-magic-spacebar", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-magic-spacebar", - "/apps/evolution/mail/display/magic_spacebar"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "mail-mark-citations", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-mark-citations", - "/apps/evolution/mail/display/mark_citations"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "mail-mark-seen", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-mark-seen", - "/apps/evolution/mail/display/mark_seen"); - - e_shell_settings_install_property ( - g_param_spec_int ( - "mail-mark-seen-timeout", - NULL, - NULL, - G_MININT, - G_MAXINT, - 0, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-mark-seen-timeout", - "/apps/evolution/mail/display/mark_seen_timeout"); - - e_shell_settings_install_property ( - g_param_spec_int ( - "mail-message-text-part-limit", - NULL, - NULL, - G_MININT, - G_MAXINT, - 0, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-message-text-part-limit", - "/apps/evolution/mail/display/message_text_part_limit"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "mail-only-local-photos", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-only-local-photos", - "/apps/evolution/mail/display/photo_local"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "mail-prompt-delete-in-vfolder", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-prompt-delete-in-vfolder", - "/apps/evolution/mail/prompts/delete_in_vfolder"); - - /* This value corresponds to MailConfigReplyStyle enum, - * but the ordering of the combo box items in preferences - * has changed. We use transformation functions there. */ - e_shell_settings_install_property ( - g_param_spec_int ( - "mail-reply-style", - NULL, - NULL, - 0, - G_MAXINT, - 0, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-reply-style", - "/apps/evolution/mail/format/reply_style"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "mail-show-animated-images", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-show-animated-images", - "/apps/evolution/mail/display/animated_images"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "mail-show-sender-photo", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-show-sender-photo", - "/apps/evolution/mail/display/sender_photo"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "mail-use-custom-fonts", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "mail-use-custom-fonts", - "/apps/evolution/mail/display/fonts/use_custom"); - - - /*** Composer Preferences ***/ - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "composer-format-html", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "composer-format-html", - "/apps/evolution/mail/composer/send_html"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "composer-inline-spelling", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "composer-inline-spelling", - "/apps/evolution/mail/composer/inline_spelling"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "composer-magic-links", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "composer-magic-links", - "/apps/evolution/mail/composer/magic_links"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "composer-magic-smileys", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "composer-magic-smileys", - "/apps/evolution/mail/composer/magic_smileys"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "composer-outlook-filenames", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "composer-outlook-filenames", - "/apps/evolution/mail/composer/outlook_filenames"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "composer-prompt-only-bcc", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "composer-prompt-only-bcc", - "/apps/evolution/mail/prompts/only_bcc"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "composer-prompt-empty-subject", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "composer-prompt-empty-subject", - "/apps/evolution/mail/prompts/empty_subject"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "composer-reply-start-bottom", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "composer-reply-start-bottom", - "/apps/evolution/mail/composer/reply_start_bottom"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "composer-request-receipt", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "composer-request-receipt", - "/apps/evolution/mail/composer/request_receipt"); - - e_shell_settings_install_property ( - g_param_spec_string ( - "composer-spell-color", - NULL, - NULL, - "#ff0000", - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "composer-spell-color", - "/apps/evolution/mail/composer/spell_color"); - - e_shell_settings_install_property ( - g_param_spec_boolean ( - "composer-top-signature", - NULL, - NULL, - FALSE, - G_PARAM_READWRITE)); - - e_shell_settings_bind_to_gconf ( - shell_settings, "composer-top-signature", - "/apps/evolution/mail/composer/top_signature"); -} diff --git a/mail/e-mail-shell-module-settings.h b/mail/e-mail-shell-module-settings.h deleted file mode 100644 index a5528463c7..0000000000 --- a/mail/e-mail-shell-module-settings.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * e-mail-shell-module-settings.h - * - * 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 - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_MAIL_SHELL_MODULE_SETTINGS_H -#define E_MAIL_SHELL_MODULE_SETTINGS_H - -#include - -G_BEGIN_DECLS - -void e_mail_shell_module_init_settings (EShell *shell); - -G_END_DECLS - -#endif /* E_MAIL_SHELL_MODULE_SETTINGS_H */ diff --git a/mail/e-mail-shell-module.c b/mail/e-mail-shell-module.c deleted file mode 100644 index 4a0fcf0b38..0000000000 --- a/mail/e-mail-shell-module.c +++ /dev/null @@ -1,1166 +0,0 @@ -/* - * e-mail-shell-module.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 - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#include -#include -#include -#include -#include - -#include "e-util/e-account-utils.h" -#include "e-util/e-binding.h" -#include "e-util/e-import.h" -#include "e-util/e-util.h" -#include "shell/e-shell.h" -#include "shell/e-shell-window.h" -#include "composer/e-msg-composer.h" -#include "widgets/misc/e-preferences-window.h" - -#include "e-mail-shell-view.h" -#include "e-mail-shell-module.h" -#include "e-mail-shell-module-migrate.h" -#include "e-mail-shell-module-settings.h" - -#include "e-attachment-handler-mail.h" -#include "e-mail-browser.h" -#include "e-mail-reader.h" -#include "em-account-prefs.h" -#include "em-composer-prefs.h" -#include "em-composer-utils.h" -#include "em-config.h" -#include "em-event.h" -#include "em-folder-tree-model.h" -#include "em-folder-utils.h" -#include "em-format-hook.h" -#include "em-format-html-display.h" -#include "em-junk-hook.h" -#include "em-mailer-prefs.h" -#include "em-network-prefs.h" -#include "em-utils.h" -#include "mail-config.h" -#include "mail-folder-cache.h" -#include "mail-mt.h" -#include "mail-ops.h" -#include "mail-send-recv.h" -#include "mail-session.h" -#include "mail-vfolder.h" -#include "importers/mail-importer.h" - -#define MODULE_NAME "mail" -#define MODULE_ALIASES "" -#define MODULE_SCHEMES "mailto:email" -#define MODULE_SORT_ORDER 200 - -typedef struct _StoreInfo StoreInfo; - -/* XXX Temporary */ -CamelStore *vfolder_store; - -struct _StoreInfo { - CamelStore *store; - gint ref_count; - gchar *name; - - /* Keep a reference to these so they remain around for the session. */ - CamelFolder *vtrash; - CamelFolder *vjunk; - - /* Initialization callback. */ - void (*done) (CamelStore *store, - CamelFolderInfo *info, - gpointer user_data); - gpointer done_user_data; - - guint removed : 1; -}; - -/* Module Entry Point */ -void e_shell_module_init (GTypeModule *type_module); - -/* The array elements correspond to EMailFolderType. */ -static struct { - gchar *name; - gchar *uri; - CamelFolder *folder; -} default_local_folders[] = { - { N_("Inbox") }, - { N_("Drafts") }, - { N_("Outbox") }, - { N_("Sent") }, - { N_("Templates") }, - { "Inbox" } /* "always local" inbox */ -}; - -/* XXX So many things need the shell module that it's - * just easier for now to make it globally available. - * We should fix this, though. */ -EShellModule *mail_shell_module = NULL; - -static GHashTable *store_hash; -static MailAsyncEvent *async_event; -static EMFolderTreeModel *folder_tree_model; -static CamelStore *local_store; - -static gint mail_sync_in_progress; -static guint mail_sync_timeout_source_id; - -extern gint camel_application_is_exiting; - -static StoreInfo * -store_info_new (CamelStore *store, - const gchar *name) -{ - CamelService *service; - StoreInfo *si; - - g_return_val_if_fail (CAMEL_IS_STORE (store), NULL); - - service = CAMEL_SERVICE (store); - - si = g_slice_new0 (StoreInfo); - si->ref_count = 1; - - if (name == NULL) - si->name = camel_service_get_name (service, TRUE); - else - si->name = g_strdup (name); - - si->store = store; - camel_object_ref (store); - - /* If these are vfolders then they need to be opened now, - * otherwise they won't keep track of all folders. */ - if (store->flags & CAMEL_STORE_VTRASH) - si->vtrash = camel_store_get_trash (store, NULL); - if (store->flags & CAMEL_STORE_VJUNK) - si->vjunk = camel_store_get_junk (store, NULL); - - return si; -} - -static StoreInfo * -store_info_ref (StoreInfo *si) -{ - g_return_val_if_fail (si != NULL, si); - g_return_val_if_fail (si->ref_count > 0, si); - - g_atomic_int_add (&si->ref_count, 1); - - return si; -} - -static void -store_info_unref (StoreInfo *si) -{ - g_return_if_fail (si != NULL); - g_return_if_fail (si->ref_count > 0); - - if (g_atomic_int_exchange_and_add (&si->ref_count, -1) > 1) - return; - - if (si->vtrash != NULL) - camel_object_unref (si->vtrash); - if (si->vjunk != NULL) - camel_object_unref (si->vjunk); - camel_object_unref (si->store); - g_free (si->name); - - g_slice_free (StoreInfo, si); -} - -static void -store_hash_free (StoreInfo *si) -{ - si->removed = 1; - store_info_unref (si); -} - -static gboolean -mail_shell_module_add_store_done (CamelStore *store, - CamelFolderInfo *info, - gpointer user_data) -{ - StoreInfo *si = user_data; - - if (si->done != NULL) - si->done (store, info, si); - - if (!si->removed) { - /* Let the counters know about the already-opened - * junk and trash folders. */ - if (si->vtrash != NULL) - mail_note_folder (si->vtrash); - if (si->vjunk != NULL) - mail_note_folder (si->vjunk); - } - - store_info_unref (si); - - return TRUE; -} - -static void -mail_shell_module_add_store (EShellModule *shell_module, - CamelStore *store, - const gchar *name, - void (*done) (CamelStore *store, - CamelFolderInfo *info, - gpointer user_data)) -{ - StoreInfo *si; - - si = store_info_new (store, name); - si->done = done; - g_hash_table_insert (store_hash, store, si); - - em_folder_tree_model_add_store (folder_tree_model, store, si->name); - - mail_note_store ( - shell_module, store, NULL, - mail_shell_module_add_store_done, store_info_ref (si)); -} - -static void -mail_shell_module_add_local_store_done (CamelStore *store, - CamelFolderInfo *info, - gpointer unused) -{ - gint ii; - - for (ii = 0; ii < G_N_ELEMENTS (default_local_folders); ii++) { - if (default_local_folders[ii].folder != NULL) - mail_note_folder (default_local_folders[ii].folder); - } -} - -static void -mail_shell_module_add_local_store (EShellModule *shell_module, - CamelStore *local_store, - const gchar *name) -{ - mail_shell_module_add_store ( - shell_module, local_store, name, - mail_shell_module_add_local_store_done); -} - -static void -mail_shell_module_init_hooks (void) -{ - e_plugin_hook_register_type (em_config_hook_get_type ()); - e_plugin_hook_register_type (em_event_hook_get_type ()); - e_plugin_hook_register_type (em_junk_hook_get_type ()); - - /* EMFormat classes must be registered before EMFormatHook. */ - em_format_hook_register_type (em_format_get_type ()); - em_format_hook_register_type (em_format_html_get_type ()); - em_format_hook_register_type (em_format_html_display_get_type ()); - e_plugin_hook_register_type (em_format_hook_get_type ()); - - em_junk_hook_register_type (emj_get_type ()); -} - -static void -mail_shell_module_init_importers (void) -{ - EImportClass *import_class; - EImportImporter *importer; - - import_class = g_type_class_ref (e_import_get_type ()); - - importer = mbox_importer_peek (); - e_import_class_add_importer (import_class, importer, NULL, NULL); - - importer = elm_importer_peek (); - e_import_class_add_importer (import_class, importer, NULL, NULL); - - importer = pine_importer_peek (); - e_import_class_add_importer (import_class, importer, NULL, NULL); -} - -static void -mail_shell_module_init_local_store (EShellModule *shell_module) -{ - CamelException ex; - CamelService *service; - CamelURL *url; - const gchar *data_dir; - gchar *temp; - gint ii; - - camel_exception_init (&ex); - - url = camel_url_new ("mbox:", NULL); - data_dir = e_shell_module_get_data_dir (shell_module); - temp = g_build_filename (data_dir, "local", NULL); - camel_url_set_path (url, temp); - g_free (temp); - - temp = camel_url_to_string (url, 0); - service = camel_session_get_service ( - session, temp, CAMEL_PROVIDER_STORE, &ex); - g_free (temp); - - if (service == NULL) - goto fail; - - for (ii = 0; ii < G_N_ELEMENTS (default_local_folders); ii++) { - /* FIXME Should this URI be account relative? */ - camel_url_set_fragment (url, default_local_folders[ii].name); - default_local_folders[ii].uri = camel_url_to_string (url, 0); - default_local_folders[ii].folder = camel_store_get_folder ( - CAMEL_STORE (service), default_local_folders[ii].name, - CAMEL_STORE_FOLDER_CREATE, &ex); - camel_exception_clear (&ex); - } - - camel_url_free (url); - - camel_object_ref (service); - g_object_ref (shell_module); - - mail_async_event_emit ( - async_event, MAIL_ASYNC_GUI, - (MailAsyncFunc) mail_shell_module_add_local_store, - shell_module, service, _("On This Computer")); - - local_store = CAMEL_STORE (service); - - return; - -fail: - g_warning ("Could not initialize local store/folder: %s", ex.desc); - - camel_exception_clear (&ex); - camel_url_free (url); -} - -static void -mail_shell_module_load_accounts (EShellModule *shell_module) -{ - EAccountList *account_list; - EIterator *iter; - - account_list = e_get_account_list (); - - for (iter = e_list_get_iterator ((EList *) account_list); - e_iterator_is_valid (iter); e_iterator_next (iter)) { - - EAccountService *service; - EAccount *account; - const gchar *name; - const gchar *url; - - account = (EAccount *) e_iterator_get (iter); - service = account->source; - name = account->name; - url = service->url; - - if (!account->enabled) - continue; - - if (url == NULL || *url == '\0') - continue; - - /* HACK: mbox URL's are handled by the local store setup - * above. Any that come through as account sources - * are really movemail sources! */ - if (g_str_has_prefix (url, "mbox:")) - continue; - - e_mail_shell_module_load_store_by_uri ( - shell_module, url, name); - } - - g_object_unref (iter); -} - -static void -mail_shell_module_mail_icon_cb (EShellWindow *shell_window, - const gchar *icon_name) -{ - GtkAction *action; - - action = e_shell_window_get_shell_view_action ( - shell_window, MODULE_NAME); - g_object_set (action, "icon-name", icon_name, NULL); -} - -static void -action_mail_folder_new_cb (GtkAction *action, - EShellWindow *shell_window) -{ - EMFolderTree *folder_tree = NULL; - EMailShellSidebar *mail_shell_sidebar; - EShellSidebar *shell_sidebar; - EShellView *shell_view; - const gchar *view_name; - - /* Take care not to unnecessarily load the mail shell view. */ - view_name = e_shell_window_get_active_view (shell_window); - if (g_strcmp0 (view_name, MODULE_NAME) != 0) - goto exit; - - shell_view = e_shell_window_get_shell_view (shell_window, view_name); - shell_sidebar = e_shell_view_get_shell_sidebar (shell_view); - - mail_shell_sidebar = E_MAIL_SHELL_SIDEBAR (shell_sidebar); - folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar); - -exit: - em_folder_utils_create_folder ( - NULL, folder_tree, GTK_WINDOW (shell_window)); -} - -static void -action_mail_message_new_cb (GtkAction *action, - EShellWindow *shell_window) -{ - GtkWindow *window = GTK_WINDOW (shell_window); - EMailShellSidebar *mail_shell_sidebar; - EShellSidebar *shell_sidebar; - EShellView *shell_view; - EMFolderTree *folder_tree; - const gchar *view_name; - gchar *uri = NULL; - - if (!em_utils_check_user_can_send_mail (window)) - return; - - /* Take care not to unnecessarily load the mail shell view. */ - view_name = e_shell_window_get_active_view (shell_window); - if (g_strcmp0 (view_name, MODULE_NAME) != 0) - goto exit; - - shell_view = e_shell_window_get_shell_view (shell_window, view_name); - shell_sidebar = e_shell_view_get_shell_sidebar (shell_view); - - mail_shell_sidebar = E_MAIL_SHELL_SIDEBAR (shell_sidebar); - folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar); - uri = em_folder_tree_get_selected_uri (folder_tree); - -exit: - em_utils_compose_new_message (uri); - - g_free (uri); -} - -static GtkActionEntry item_entries[] = { - - { "mail-message-new", - "mail-message-new", - NC_("New", "_Mail Message"), - "m", - N_("Compose a new mail message"), - G_CALLBACK (action_mail_message_new_cb) } -}; - -static GtkActionEntry source_entries[] = { - - { "mail-folder-new", - "folder-new", - NC_("New", "Mail _Folder"), - NULL, - N_("Create a new mail folder"), - G_CALLBACK (action_mail_folder_new_cb) } -}; - -static void -mail_shell_module_init_preferences (EShell *shell) -{ - GtkWidget *preferences_window; - - preferences_window = e_shell_get_preferences_window (shell); - - e_preferences_window_add_page ( - E_PREFERENCES_WINDOW (preferences_window), - "mail-accounts", - "preferences-mail-accounts", - _("Mail Accounts"), - em_account_prefs_new (), - 100); - - e_preferences_window_add_page ( - E_PREFERENCES_WINDOW (preferences_window), - "mail", - "preferences-mail", - _("Mail Preferences"), - em_mailer_prefs_new (shell), - 300); - - e_preferences_window_add_page ( - E_PREFERENCES_WINDOW (preferences_window), - "composer", - "preferences-composer", - _("Composer Preferences"), - em_composer_prefs_new (shell), - 400); - - e_preferences_window_add_page ( - E_PREFERENCES_WINDOW (preferences_window), - "system-network-proxy", - "preferences-system-network-proxy", - _("Network Preferences"), - em_network_prefs_new (), - 500); -} - -static void -mail_shell_module_sync_store_done_cb (CamelStore *store, - gpointer user_data) -{ - mail_sync_in_progress--; -} - -static void -mail_shell_module_sync_store_cb (CamelStore *store) -{ - if (!camel_application_is_exiting) { - mail_sync_in_progress++; - mail_sync_store ( - store, FALSE, - mail_shell_module_sync_store_done_cb, NULL); - } -} - -static gboolean -mail_shell_module_mail_sync (EShellModule *shell_module) -{ - if (camel_application_is_exiting) - return FALSE; - - if (mail_sync_in_progress) - goto exit; - - if (session == NULL || !camel_session_is_online (session)) - goto exit; - - e_mail_shell_module_stores_foreach ( - shell_module, (GHFunc) - mail_shell_module_sync_store_cb, NULL); - -exit: - return !camel_application_is_exiting; -} - -static void -mail_shell_module_notify_online_cb (EShell *shell, - GParamSpec *pspec, - EShellModule *shell_module) -{ - gboolean online; - - online = e_shell_get_online (shell); - camel_session_set_online (session, online); -} - -static void -mail_shell_module_handle_email_uri_cb (gchar *folder_uri, - CamelFolder *folder, - gpointer user_data) -{ - CamelURL *url = user_data; - const gchar *forward; - const gchar *reply; - const gchar *uid; - - if (folder == NULL) { - g_warning ("Could not open folder '%s'", folder_uri); - goto exit; - } - - forward = camel_url_get_param (url, "forward"); - reply = camel_url_get_param (url, "reply"); - uid = camel_url_get_param (url, "uid"); - - if (reply != NULL) { - gint mode; - - if (g_strcmp0 (reply, "all") == 0) - mode = REPLY_MODE_ALL; - else if (g_strcmp0 (reply, "list") == 0) - mode = REPLY_MODE_LIST; - else - mode = REPLY_MODE_SENDER; - - em_utils_reply_to_message (folder, uid, NULL, mode, NULL); - - } else if (forward != NULL) { - GPtrArray *uids; - - uids = g_ptr_array_new (); - g_ptr_array_add (uids, g_strdup (uid)); - - if (g_strcmp0 (forward, "attached") == 0) - em_utils_forward_attached (folder, uids, folder_uri); - else if (g_strcmp0 (forward, "inline") == 0) - em_utils_forward_inline (folder, uids, folder_uri); - else if (g_strcmp0 (forward, "quoted") == 0) - em_utils_forward_quoted (folder, uids, folder_uri); - else - em_utils_forward_messages (folder, uids, folder_uri); - - } else { - GtkWidget *browser; - - /* FIXME Should pass in the shell module. */ - browser = e_mail_browser_new (mail_shell_module); - e_mail_reader_set_folder ( - E_MAIL_READER (browser), folder, folder_uri); - e_mail_reader_set_message ( - E_MAIL_READER (browser), uid, FALSE); - gtk_widget_show (browser); - } - -exit: - camel_url_free (url); -} - -static gboolean -mail_shell_module_handle_uri_cb (EShell *shell, - const gchar *uri, - EShellModule *shell_module) -{ - gboolean handled = TRUE; - - if (g_str_has_prefix (uri, "mailto:")) { - if (em_utils_check_user_can_send_mail (NULL)) - em_utils_compose_new_message_with_mailto (uri, NULL); - - } else if (g_str_has_prefix (uri, "email:")) { - CamelURL *url; - - url = camel_url_new (uri, NULL); - if (camel_url_get_param (url, "uid") != NULL) { - gchar *curi = em_uri_to_camel (uri); - - mail_get_folder ( - curi, 0, - mail_shell_module_handle_email_uri_cb, - url, mail_msg_unordered_push); - g_free (curi); - - } else { - g_warning ("Email URI's must include a uid parameter"); - camel_url_free (url); - } - } else - handled = FALSE; - - return TRUE; -} - -/* Helper for mail_shell_module_prepare_for_[off|on]line_cb() */ -static void -mail_shell_store_line_transition_done_cb (CamelStore *store, - gpointer user_data) -{ - EActivity *activity = user_data; - - g_object_unref (activity); -} - -/* Helper for mail_shell_module_prepare_for_offline_cb() */ -static void -mail_shell_store_prepare_for_offline_cb (CamelService *service, - gpointer unused, - EActivity *activity) -{ - if (CAMEL_IS_DISCO_STORE (service) || CAMEL_IS_OFFLINE_STORE (service)) - mail_store_set_offline ( - CAMEL_STORE (service), TRUE, - mail_shell_store_line_transition_done_cb, - g_object_ref (activity)); -} - -static void -mail_shell_module_prepare_for_offline_cb (EShell *shell, - EActivity *activity, - EShellModule *shell_module) -{ - GList *watched_windows; - GtkWidget *parent = NULL; - gboolean synchronize = FALSE; - - watched_windows = e_shell_get_watched_windows (shell); - if (watched_windows != NULL) - parent = GTK_WIDGET (watched_windows->data); - - if (e_shell_get_network_available (shell)) - synchronize = em_utils_prompt_user ( - GTK_WINDOW (parent), - "/apps/evolution/mail/prompts/quick_offline", - "mail:ask-quick-offline", NULL); - - if (!synchronize) { - mail_cancel_all (); - camel_session_set_network_state (session, FALSE); - } - - e_mail_shell_module_stores_foreach ( - shell_module, (GHFunc) - mail_shell_store_prepare_for_offline_cb, activity); -} - -/* Helper for mail_shell_module_prepare_for_online_cb() */ -static void -mail_shell_store_prepare_for_online_cb (CamelService *service, - gpointer unused, - EActivity *activity) -{ - if (CAMEL_IS_DISCO_STORE (service) || CAMEL_IS_OFFLINE_STORE (service)) - mail_store_set_offline ( - CAMEL_STORE (service), FALSE, - mail_shell_store_line_transition_done_cb, - g_object_ref (activity)); -} - -static void -mail_shell_module_prepare_for_online_cb (EShell *shell, - EActivity *activity, - EShellModule *shell_module) -{ - camel_session_set_online (session, TRUE); - - e_mail_shell_module_stores_foreach ( - shell_module, (GHFunc) - mail_shell_store_prepare_for_online_cb, activity); -} - -static void -mail_shell_module_send_receive_cb (EShell *shell, - GtkWindow *parent, - EShellModule *shell_module) -{ - em_utils_clear_get_password_canceled_accounts_flag (); - mail_send_receive (parent); -} - -static void -mail_shell_module_window_weak_notify_cb (EShell *shell, - GObject *where_the_object_was) -{ - g_signal_handlers_disconnect_by_func ( - shell, mail_shell_module_mail_icon_cb, - where_the_object_was); -} - -static void -mail_shell_module_window_created_cb (EShell *shell, - GtkWindow *window, - EShellModule *shell_module) -{ - EShellSettings *shell_settings; - static gboolean first_time = TRUE; - const gchar *module_name; - - shell_settings = e_shell_get_shell_settings (shell); - - /* This applies to both the composer and signature editor. */ - if (GTKHTML_IS_EDITOR (window)) { - GList *spell_languages; - - e_binding_new ( - G_OBJECT (shell_settings), "composer-inline-spelling", - G_OBJECT (window), "inline-spelling"); - - e_binding_new ( - G_OBJECT (shell_settings), "composer-magic-links", - G_OBJECT (window), "magic-links"); - - e_binding_new ( - G_OBJECT (shell_settings), "composer-magic-smileys", - G_OBJECT (window), "magic-smileys"); - - spell_languages = e_load_spell_languages (); - gtkhtml_editor_set_spell_languages ( - GTKHTML_EDITOR (window), spell_languages); - g_list_free (spell_languages); - } - - if (E_IS_MSG_COMPOSER (window)) { - /* Integrate the new composer into the mail module. */ - em_configure_new_composer (E_MSG_COMPOSER (window)); - return; - } - - if (!E_IS_SHELL_WINDOW (window)) - return; - - module_name = G_TYPE_MODULE (shell_module)->name; - - e_shell_window_register_new_item_actions ( - E_SHELL_WINDOW (window), module_name, - item_entries, G_N_ELEMENTS (item_entries)); - - e_shell_window_register_new_source_actions ( - E_SHELL_WINDOW (window), module_name, - source_entries, G_N_ELEMENTS (source_entries)); - - g_signal_connect_swapped ( - shell, "event::mail-icon", - G_CALLBACK (mail_shell_module_mail_icon_cb), window); - - g_object_weak_ref ( - G_OBJECT (window), (GWeakNotify) - mail_shell_module_window_weak_notify_cb, shell); - - if (first_time) { - g_signal_connect ( - window, "map-event", - G_CALLBACK (e_msg_composer_check_autosave), NULL); - first_time = FALSE; - } -} - -static void -mail_shell_module_start (EShellModule *shell_module) -{ - EShell *shell; - EShellSettings *shell_settings; - gboolean enable_search_folders; - - shell = e_shell_module_get_shell (shell_module); - shell_settings = e_shell_get_shell_settings (shell); - - /* XXX Do we really still need this flag? */ - mail_session_set_interactive (TRUE); - - enable_search_folders = e_shell_settings_get_boolean ( - shell_settings, "mail-enable-search-folders"); - if (enable_search_folders) - vfolder_load_storage (); - - mail_autoreceive_init (shell_module, session); - - if (g_getenv ("CAMEL_FLUSH_CHANGES") != NULL) - mail_sync_timeout_source_id = g_timeout_add_seconds ( - mail_config_get_sync_timeout (), - (GSourceFunc) mail_shell_module_mail_sync, - shell_module); -} - -static EShellModuleInfo module_info = { - - MODULE_NAME, - MODULE_ALIASES, - MODULE_SCHEMES, - MODULE_SORT_ORDER, - - mail_shell_module_start, - /* is_busy */ NULL, - /* shutdown */ NULL, - e_mail_shell_module_migrate -}; - -void -e_shell_module_init (GTypeModule *type_module) -{ - EShell *shell; - EShellModule *shell_module; - - shell_module = E_SHELL_MODULE (type_module); - shell = e_shell_module_get_shell (shell_module); - - e_shell_module_set_info ( - shell_module, &module_info, - e_mail_shell_view_get_type (type_module)); - - /* This also initializes Camel, so it needs to happen early. */ - mail_session_init (shell_module); - - mail_shell_module_init_hooks (); - mail_shell_module_init_importers (); - - e_attachment_handler_mail_get_type (); - - /* XXX This never gets unreffed. */ - mail_shell_module = g_object_ref (shell_module); - - store_hash = g_hash_table_new_full ( - g_direct_hash, g_direct_equal, - (GDestroyNotify) NULL, - (GDestroyNotify) store_hash_free); - - async_event = mail_async_event_new (); - - folder_tree_model = em_folder_tree_model_new (shell_module); - - g_signal_connect ( - shell, "notify::online", - G_CALLBACK (mail_shell_module_notify_online_cb), - shell_module); - - g_signal_connect ( - shell, "handle-uri", - G_CALLBACK (mail_shell_module_handle_uri_cb), - shell_module); - - g_signal_connect ( - shell, "prepare-for-offline", - G_CALLBACK (mail_shell_module_prepare_for_offline_cb), - shell_module); - - g_signal_connect ( - shell, "prepare-for-online", - G_CALLBACK (mail_shell_module_prepare_for_online_cb), - shell_module); - - g_signal_connect ( - shell, "send-receive", - G_CALLBACK (mail_shell_module_send_receive_cb), - shell_module); - - g_signal_connect ( - shell, "window-created", - G_CALLBACK (mail_shell_module_window_created_cb), - shell_module); - - mail_config_init (); - mail_msg_init (); - - mail_shell_module_init_local_store (shell_module); - mail_shell_module_load_accounts (shell_module); - - /* Initialize settings before initializing preferences, - * since the preferences bind to the shell settings. */ - e_mail_shell_module_init_settings (shell); - mail_shell_module_init_preferences (shell); -} - -/******************************** Public API *********************************/ - -CamelFolder * -e_mail_shell_module_get_folder (EShellModule *shell_module, - EMailFolderType folder_type) -{ - g_return_val_if_fail (E_IS_SHELL_MODULE (shell_module), NULL); - - return default_local_folders[folder_type].folder; -} - -const gchar * -e_mail_shell_module_get_folder_uri (EShellModule *shell_module, - EMailFolderType folder_type) -{ - g_return_val_if_fail (E_IS_SHELL_MODULE (shell_module), NULL); - - return default_local_folders[folder_type].uri; -} - -EMFolderTreeModel * -e_mail_shell_module_get_folder_tree_model (EShellModule *shell_module) -{ - /* Require a shell module in case we need it in the future. */ - g_return_val_if_fail (E_IS_SHELL_MODULE (shell_module), NULL); - - return folder_tree_model; -} - -void -e_mail_shell_module_add_store (EShellModule *shell_module, - CamelStore *store, - const gchar *name) -{ - g_return_if_fail (E_IS_SHELL_MODULE (shell_module)); - g_return_if_fail (CAMEL_IS_STORE (store)); - g_return_if_fail (name != NULL); - - mail_shell_module_add_store (shell_module, store, name, NULL); -} - -CamelStore * -e_mail_shell_module_get_local_store (EShellModule *shell_module) -{ - g_return_val_if_fail (E_IS_SHELL_MODULE (shell_module), NULL); - g_return_val_if_fail (local_store != NULL, NULL); - - return local_store; -} - -CamelStore * -e_mail_shell_module_load_store_by_uri (EShellModule *shell_module, - const gchar *uri, - const gchar *name) -{ - CamelStore *store; - CamelProvider *provider; - CamelException ex; - - g_return_val_if_fail (E_IS_SHELL_MODULE (shell_module), NULL); - g_return_val_if_fail (uri != NULL, NULL); - g_return_val_if_fail (name != NULL, NULL); - - camel_exception_init (&ex); - - /* Load the service, but don't connect. Check its provider, - * and if this belongs in the shell's folder list, add it. */ - - provider = camel_provider_get (uri, &ex); - if (provider == NULL) - goto fail; - - if (!(provider->flags & CAMEL_PROVIDER_IS_STORAGE)) - return NULL; - - store = (CamelStore *) camel_session_get_service ( - session, uri, CAMEL_PROVIDER_STORE, &ex); - if (store == NULL) - goto fail; - - e_mail_shell_module_add_store (shell_module, store, name); - - camel_object_unref (store); - - return store; - -fail: - /* FIXME: Show an error dialog. */ - g_warning ( - "Couldn't get service: %s: %s", uri, - camel_exception_get_description (&ex)); - camel_exception_clear (&ex); - - return NULL; -} - -/* Helper for e_mail_shell_module_remove_store() */ -static void -mail_shell_module_remove_store_cb (CamelStore *store, - gpointer event_data, - gpointer user_data) -{ - camel_service_disconnect (CAMEL_SERVICE (store), TRUE, NULL); - camel_object_unref (store); -} - -void -e_mail_shell_module_remove_store (EShellModule *shell_module, - CamelStore *store) -{ - g_return_if_fail (E_IS_SHELL_MODULE (shell_module)); - g_return_if_fail (CAMEL_IS_STORE (store)); - - /* Because the store hash holds a reference to each store used - * as a key in it, none of them will ever be gc'ed, meaning any - * call to camel_session_get_{service,store} with the same URL - * will always return the same object. So this works. */ - - if (g_hash_table_lookup (store_hash, store) == NULL) - return; - - camel_object_ref (store); - g_hash_table_remove (store_hash, store); - mail_note_store_remove (store); - em_folder_tree_model_remove_store (folder_tree_model, store); - - mail_async_event_emit ( - async_event, MAIL_ASYNC_THREAD, - (MailAsyncFunc) mail_shell_module_remove_store_cb, - store, NULL, NULL); -} - -void -e_mail_shell_module_remove_store_by_uri (EShellModule *shell_module, - const gchar *uri) -{ - CamelStore *store; - CamelProvider *provider; - - g_return_if_fail (E_IS_SHELL_MODULE (shell_module)); - g_return_if_fail (uri != NULL); - - provider = camel_provider_get (uri, NULL); - if (provider == NULL) - return; - - if (!(provider->flags & CAMEL_PROVIDER_IS_STORAGE)) - return; - - store = (CamelStore *) camel_session_get_service ( - session, uri, CAMEL_PROVIDER_STORE, NULL); - if (store != NULL) { - e_mail_shell_module_remove_store (shell_module, store); - camel_object_unref (store); - } -} - -void -e_mail_shell_module_stores_foreach (EShellModule *shell_module, - GHFunc func, - gpointer user_data) -{ - GHashTableIter iter; - gpointer key, value; - - g_return_if_fail (E_IS_SHELL_MODULE (shell_module)); - g_return_if_fail (func != NULL); - - g_hash_table_iter_init (&iter, store_hash); - - while (g_hash_table_iter_next (&iter, &key, &value)) - func (key, ((StoreInfo *) value)->name, user_data); -} - -/******************* Code below here belongs elsewhere. *******************/ - -#include "filter/filter-option.h" -#include "shell/e-shell-settings.h" -#include "mail/e-mail-label-list-store.h" - -GSList * -e_mail_labels_get_filter_options (void) -{ - EShell *shell; - EShellSettings *shell_settings; - EMailLabelListStore *list_store; - GtkTreeModel *model; - GtkTreeIter iter; - GSList *list = NULL; - gboolean valid; - - shell = e_shell_get_default (); - shell_settings = e_shell_get_shell_settings (shell); - list_store = e_shell_settings_get_object ( - shell_settings, "mail-label-list-store"); - - model = GTK_TREE_MODEL (list_store); - valid = gtk_tree_model_get_iter_first (model, &iter); - - while (valid) { - struct _filter_option *option; - gchar *name, *tag; - - name = e_mail_label_list_store_get_name (list_store, &iter); - tag = e_mail_label_list_store_get_tag (list_store, &iter); - - option = g_new0 (struct _filter_option, 1); - option->title = e_str_without_underscores (name); - option->value = tag; /* takes ownership */ - - g_free (name); - - valid = gtk_tree_model_iter_next (model, &iter); - } - - g_object_unref (list_store); - - return list; -} diff --git a/mail/e-mail-shell-module.h b/mail/e-mail-shell-module.h deleted file mode 100644 index d72df698a5..0000000000 --- a/mail/e-mail-shell-module.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * e-mail-shell-module.h - * - * 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 - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_MAIL_SHELL_MODULE_H -#define E_MAIL_SHELL_MODULE_H - -#include - -#include -#include -#include -#include - -G_BEGIN_DECLS - -/* Globally available shell module. - * - * XXX I don't like having this globally available but passing it around - * to all the various utilities that need to access the module's data - * directory and local folders is too much of a pain for now. */ -extern EShellModule *mail_shell_module; - -typedef enum { - E_MAIL_FOLDER_INBOX, - E_MAIL_FOLDER_DRAFTS, - E_MAIL_FOLDER_OUTBOX, - E_MAIL_FOLDER_SENT, - E_MAIL_FOLDER_TEMPLATES, - E_MAIL_FOLDER_LOCAL_INBOX -} EMailFolderType; - -struct _EMFolderTreeModel; - -CamelFolder * e_mail_shell_module_get_folder (EShellModule *shell_module, - EMailFolderType folder_type); -const gchar * e_mail_shell_module_get_folder_uri - (EShellModule *shell_module, - EMailFolderType folder_type); -struct _EMFolderTreeModel * - e_mail_shell_module_get_folder_tree_model - (EShellModule *shell_module); -void e_mail_shell_module_add_store (EShellModule *shell_module, - CamelStore *store, - const gchar *name); -CamelStore * e_mail_shell_module_get_local_store - (EShellModule *shell_module); -CamelStore * e_mail_shell_module_load_store_by_uri - (EShellModule *shell_module, - const gchar *uri, - const gchar *name); -void e_mail_shell_module_remove_store(EShellModule *shell_module, - CamelStore *store); -void e_mail_shell_module_remove_store_by_uri - (EShellModule *shell_module, - const gchar *uri); -void e_mail_shell_module_stores_foreach - (EShellModule *shell_module, - GHFunc func, - gpointer user_data); - -/* XXX Find a better place for this function. */ -GSList * e_mail_labels_get_filter_options(void); - -G_END_DECLS - -#endif /* E_MAIL_SHELL_MODULE_H */ diff --git a/mail/e-mail-shell-settings.c b/mail/e-mail-shell-settings.c new file mode 100644 index 0000000000..8237924e3c --- /dev/null +++ b/mail/e-mail-shell-settings.c @@ -0,0 +1,521 @@ +/* + * e-mail-shell-settings.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 + * + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "e-mail-shell-settings.h" + +#include +#include + +#include "e-util/e-signature-list.h" +#include "mail/e-mail-label-list-store.h" +#include "mail/mail-session.h" + +void +e_mail_shell_settings_init (EShell *shell) +{ + EShellSettings *shell_settings; + gpointer object; + + shell_settings = e_shell_get_shell_settings (shell); + + /* XXX Default values should match the GConf schema. + * Yes it's redundant, but we're stuck with GConf. */ + + /*** Global Objects ***/ + + e_shell_settings_install_property ( + g_param_spec_object ( + "mail-label-list-store", + NULL, + NULL, + E_TYPE_MAIL_LABEL_LIST_STORE, + G_PARAM_READWRITE)); + + object = e_mail_label_list_store_new (); + e_shell_settings_set_object ( + shell_settings, "mail-label-list-store", object); + g_object_unref (object); + + e_shell_settings_install_property ( + g_param_spec_pointer ( + "mail-session", + NULL, + NULL, + G_PARAM_READWRITE)); + + camel_object_ref (session); + e_shell_settings_set_pointer ( + shell_settings, "mail-session", session); + + /*** Mail Preferences ***/ + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "mail-address-compress", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-address-compress", + "/apps/evolution/mail/display/address_compress"); + + e_shell_settings_install_property ( + g_param_spec_int ( + "mail-address-count", + NULL, + NULL, + G_MININT, + G_MAXINT, + 0, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-address-count", + "/apps/evolution/mail/display/address_count"); + + e_shell_settings_install_property ( + g_param_spec_string ( + "mail-charset-default", + NULL, + NULL, + NULL, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-charset-default", + "/apps/evolution/mail/display/charset"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "mail-check-for-junk", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-check-for-junk", + "/apps/evolution/mail/junk/check_incoming"); + + e_shell_settings_install_property ( + g_param_spec_string ( + "mail-citation-color", + NULL, + NULL, + "#737373", + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-citation-color", + "/apps/evolution/mail/display/citation_colour"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "mail-confirm-expunge", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-confirm-expunge", + "/apps/evolution/mail/prompts/expunge"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "mail-confirm-unwanted-html", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-confirm-unwanted-html", + "/apps/evolution/mail/prompts/unwanted_html"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "mail-empty-trash-on-exit", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-empty-trash-on-exit", + "/apps/evolution/mail/trash/empty_on_exit"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "mail-enable-search-folders", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-enable-search-folders", + "/apps/evolution/mail/display/enable_vfolders"); + + e_shell_settings_install_property ( + g_param_spec_string ( + "mail-font-monospace", + NULL, + NULL, + "", + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-font-monospace", + "/apps/evolution/mail/display/fonts/monospace"); + + e_shell_settings_install_property ( + g_param_spec_string ( + "mail-font-variable", + NULL, + NULL, + "", + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-font-variable", + "/apps/evolution/mail/display/fonts/variable"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "mail-force-message-limit", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-force-message-limit", + "/apps/evolution/mail/display/force_message_limit"); + + /* This value corresponds to MailConfigForwardStyle enum. */ + e_shell_settings_install_property ( + g_param_spec_int ( + "mail-forward-style", + NULL, + NULL, + 0, + G_MAXINT, + 0, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-forward-style", + "/apps/evolution/mail/format/forward_style"); + + /* This value corresponds to MailConfigHTTPMode enum. */ + e_shell_settings_install_property ( + g_param_spec_int ( + "mail-image-loading-policy", + NULL, + NULL, + 0, + G_MAXINT, + 0, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-image-loading-policy", + "/apps/evolution/mail/display/load_http_images"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "mail-magic-spacebar", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-magic-spacebar", + "/apps/evolution/mail/display/magic_spacebar"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "mail-mark-citations", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-mark-citations", + "/apps/evolution/mail/display/mark_citations"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "mail-mark-seen", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-mark-seen", + "/apps/evolution/mail/display/mark_seen"); + + e_shell_settings_install_property ( + g_param_spec_int ( + "mail-mark-seen-timeout", + NULL, + NULL, + G_MININT, + G_MAXINT, + 0, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-mark-seen-timeout", + "/apps/evolution/mail/display/mark_seen_timeout"); + + e_shell_settings_install_property ( + g_param_spec_int ( + "mail-message-text-part-limit", + NULL, + NULL, + G_MININT, + G_MAXINT, + 0, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-message-text-part-limit", + "/apps/evolution/mail/display/message_text_part_limit"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "mail-only-local-photos", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-only-local-photos", + "/apps/evolution/mail/display/photo_local"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "mail-prompt-delete-in-vfolder", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-prompt-delete-in-vfolder", + "/apps/evolution/mail/prompts/delete_in_vfolder"); + + /* This value corresponds to MailConfigReplyStyle enum, + * but the ordering of the combo box items in preferences + * has changed. We use transformation functions there. */ + e_shell_settings_install_property ( + g_param_spec_int ( + "mail-reply-style", + NULL, + NULL, + 0, + G_MAXINT, + 0, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-reply-style", + "/apps/evolution/mail/format/reply_style"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "mail-show-animated-images", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-show-animated-images", + "/apps/evolution/mail/display/animated_images"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "mail-show-sender-photo", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-show-sender-photo", + "/apps/evolution/mail/display/sender_photo"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "mail-use-custom-fonts", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "mail-use-custom-fonts", + "/apps/evolution/mail/display/fonts/use_custom"); + + + /*** Composer Preferences ***/ + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "composer-format-html", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "composer-format-html", + "/apps/evolution/mail/composer/send_html"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "composer-inline-spelling", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "composer-inline-spelling", + "/apps/evolution/mail/composer/inline_spelling"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "composer-magic-links", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "composer-magic-links", + "/apps/evolution/mail/composer/magic_links"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "composer-magic-smileys", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "composer-magic-smileys", + "/apps/evolution/mail/composer/magic_smileys"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "composer-outlook-filenames", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "composer-outlook-filenames", + "/apps/evolution/mail/composer/outlook_filenames"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "composer-prompt-only-bcc", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "composer-prompt-only-bcc", + "/apps/evolution/mail/prompts/only_bcc"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "composer-prompt-empty-subject", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "composer-prompt-empty-subject", + "/apps/evolution/mail/prompts/empty_subject"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "composer-reply-start-bottom", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "composer-reply-start-bottom", + "/apps/evolution/mail/composer/reply_start_bottom"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "composer-request-receipt", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "composer-request-receipt", + "/apps/evolution/mail/composer/request_receipt"); + + e_shell_settings_install_property ( + g_param_spec_string ( + "composer-spell-color", + NULL, + NULL, + "#ff0000", + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "composer-spell-color", + "/apps/evolution/mail/composer/spell_color"); + + e_shell_settings_install_property ( + g_param_spec_boolean ( + "composer-top-signature", + NULL, + NULL, + FALSE, + G_PARAM_READWRITE)); + + e_shell_settings_bind_to_gconf ( + shell_settings, "composer-top-signature", + "/apps/evolution/mail/composer/top_signature"); +} diff --git a/mail/e-mail-shell-settings.h b/mail/e-mail-shell-settings.h new file mode 100644 index 0000000000..4267fd8a60 --- /dev/null +++ b/mail/e-mail-shell-settings.h @@ -0,0 +1,33 @@ +/* + * e-mail-shell-settings.h + * + * 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 + * + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef E_MAIL_SHELL_SETTINGS_H +#define E_MAIL_SHELL_SETTINGS_H + +#include + +G_BEGIN_DECLS + +void e_mail_shell_settings_init (EShell *shell); + +G_END_DECLS + +#endif /* E_MAIL_SHELL_SETTINGS_H */ diff --git a/mail/e-mail-shell-sidebar.c b/mail/e-mail-shell-sidebar.c index c448be9782..e71fe4d6b2 100644 --- a/mail/e-mail-shell-sidebar.c +++ b/mail/e-mail-shell-sidebar.c @@ -27,7 +27,7 @@ #include "em-utils.h" #include "em-folder-utils.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" #define E_MAIL_SHELL_SIDEBAR_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE \ @@ -129,7 +129,7 @@ mail_shell_sidebar_constructed (GObject *object) { EMailShellSidebarPrivate *priv; EShellSidebar *shell_sidebar; - EShellModule *shell_module; + EShellBackend *shell_backend; EShellView *shell_view; GtkTreeSelection *selection; GtkTreeView *tree_view; @@ -143,7 +143,7 @@ mail_shell_sidebar_constructed (GObject *object) shell_sidebar = E_SHELL_SIDEBAR (object); shell_view = e_shell_sidebar_get_shell_view (shell_sidebar); - shell_module = e_shell_view_get_shell_module (shell_view); + shell_backend = e_shell_view_get_shell_backend (shell_view); /* Build sidebar widgets. */ @@ -160,7 +160,7 @@ mail_shell_sidebar_constructed (GObject *object) container = widget; - widget = em_folder_tree_new (shell_module); + widget = em_folder_tree_new (shell_backend); em_folder_tree_set_excluded (EM_FOLDER_TREE (widget), 0); em_folder_tree_enable_drag_and_drop (EM_FOLDER_TREE (widget)); gtk_container_add (GTK_CONTAINER (container), widget); @@ -180,7 +180,7 @@ static guint32 mail_shell_sidebar_check_state (EShellSidebar *shell_sidebar) { EMailShellSidebar *mail_shell_sidebar; - EShellModule *shell_module; + EShellBackend *shell_backend; EShellView *shell_view; EMFolderTree *folder_tree; GtkTreeSelection *selection; @@ -202,8 +202,8 @@ mail_shell_sidebar_check_state (EShellSidebar *shell_sidebar) guint32 state = 0; shell_view = e_shell_sidebar_get_shell_view (shell_sidebar); - shell_module = e_shell_view_get_shell_module (shell_view); - local_store = e_mail_shell_module_get_local_store (shell_module); + shell_backend = e_shell_view_get_shell_backend (shell_view); + local_store = e_mail_shell_backend_get_local_store (shell_backend); mail_shell_sidebar = E_MAIL_SHELL_SIDEBAR (shell_sidebar); folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar); diff --git a/mail/e-mail-shell-view-actions.c b/mail/e-mail-shell-view-actions.c index 600d8e847c..2491e41a46 100644 --- a/mail/e-mail-shell-view-actions.c +++ b/mail/e-mail-shell-view-actions.c @@ -46,7 +46,7 @@ action_mail_account_disable_cb (GtkAction *action, EMailShellView *mail_shell_view) { EMailShellSidebar *mail_shell_sidebar; - EShellModule *shell_module; + EShellBackend *shell_backend; EShellView *shell_view; EMFolderTree *folder_tree; EAccountList *account_list; @@ -54,7 +54,7 @@ action_mail_account_disable_cb (GtkAction *action, gchar *folder_uri; shell_view = E_SHELL_VIEW (mail_shell_view); - shell_module = e_shell_view_get_shell_module (shell_view); + shell_backend = e_shell_view_get_shell_backend (shell_view); mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar; folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar); @@ -70,7 +70,7 @@ action_mail_account_disable_cb (GtkAction *action, account->enabled = !account->enabled; e_account_list_change (account_list, account); - e_mail_shell_module_remove_store_by_uri (shell_module, folder_uri); + e_mail_shell_backend_remove_store_by_uri (shell_backend, folder_uri); if (account->parent_uid != NULL) e_account_list_remove (account_list, account); @@ -101,13 +101,13 @@ action_mail_download_cb (GtkAction *action, EMailShellView *mail_shell_view) { EShellView *shell_view; - EShellModule *shell_module; + EShellBackend *shell_backend; shell_view = E_SHELL_VIEW (mail_shell_view); - shell_module = e_shell_view_get_shell_module (shell_view); + shell_backend = e_shell_view_get_shell_backend (shell_view); - e_mail_shell_module_stores_foreach ( - shell_module, (GHFunc) action_mail_download_foreach_cb, NULL); + e_mail_shell_backend_stores_foreach ( + shell_backend, (GHFunc) action_mail_download_foreach_cb, NULL); } static void diff --git a/mail/e-mail-shell-view-private.c b/mail/e-mail-shell-view-private.c index 5974cc7386..e31292ed65 100644 --- a/mail/e-mail-shell-view-private.c +++ b/mail/e-mail-shell-view-private.c @@ -743,7 +743,7 @@ void e_mail_shell_view_update_sidebar (EMailShellView *mail_shell_view) { EShellSidebar *shell_sidebar; - EShellModule *shell_module; + EShellBackend *shell_backend; EShellView *shell_view; EMailReader *reader; MessageList *message_list; @@ -764,9 +764,9 @@ e_mail_shell_view_update_sidebar (EMailShellView *mail_shell_view) g_return_if_fail (E_IS_MAIL_SHELL_VIEW (mail_shell_view)); shell_view = E_SHELL_VIEW (mail_shell_view); - shell_module = e_shell_view_get_shell_module (shell_view); + shell_backend = e_shell_view_get_shell_backend (shell_view); shell_sidebar = e_shell_view_get_shell_sidebar (shell_view); - local_store = e_mail_shell_module_get_local_store (shell_module); + local_store = e_mail_shell_backend_get_local_store (shell_backend); reader = E_MAIL_READER (mail_shell_view->priv->mail_shell_content); message_list = e_mail_reader_get_message_list (reader); diff --git a/mail/e-mail-shell-view-private.h b/mail/e-mail-shell-view-private.h index 97bb638b3b..6034dbcc66 100644 --- a/mail/e-mail-shell-view-private.h +++ b/mail/e-mail-shell-view-private.h @@ -54,8 +54,8 @@ #include "mail-send-recv.h" #include "mail-vfolder.h" +#include "e-mail-shell-backend.h" #include "e-mail-shell-content.h" -#include "e-mail-shell-module.h" #include "e-mail-shell-sidebar.h" #include "e-mail-shell-view-actions.h" diff --git a/mail/e-mail-shell-view.c b/mail/e-mail-shell-view.c index ab0e7d92d5..6f4e6f9b88 100644 --- a/mail/e-mail-shell-view.c +++ b/mail/e-mail-shell-view.c @@ -216,7 +216,6 @@ mail_shell_view_class_init (EMailShellViewClass *class, shell_view_class->ui_manager_id = "org.gnome.evolution.mail"; shell_view_class->search_options = "/mail-search-options"; shell_view_class->search_rules = "searchtypes.xml"; - shell_view_class->type_module = type_module; shell_view_class->new_shell_content = e_mail_shell_content_new; shell_view_class->new_shell_sidebar = e_mail_shell_sidebar_new; shell_view_class->toggled = mail_shell_view_toggled; @@ -243,11 +242,11 @@ e_mail_shell_view_get_type (GTypeModule *type_module) (GBaseFinalizeFunc) NULL, (GClassInitFunc) mail_shell_view_class_init, (GClassFinalizeFunc) NULL, - type_module, + NULL, /* class_data */ sizeof (EMailShellView), - 0, /* n_preallocs */ + 0, /* n_preallocs */ (GInstanceInitFunc) mail_shell_view_init, - NULL /* value_table */ + NULL /* value_table */ }; e_mail_shell_view_type = diff --git a/mail/em-account-editor.c b/mail/em-account-editor.c index a5c5d59fd8..72e8881863 100644 --- a/mail/em-account-editor.c +++ b/mail/em-account-editor.c @@ -70,7 +70,7 @@ #include "mail-ops.h" #include "mail-mt.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" #if defined (HAVE_NSS) #include "smime/gui/e-cert-selector.h" @@ -449,13 +449,13 @@ default_folders_clicked (GtkButton *button, gpointer user_data) EMAccountEditor *emae = user_data; const char *uri; - uri = e_mail_shell_module_get_folder_uri ( - mail_shell_module, E_MAIL_FOLDER_DRAFTS); + uri = e_mail_shell_backend_get_folder_uri ( + global_mail_shell_backend, E_MAIL_FOLDER_DRAFTS); em_folder_selection_button_set_selection((EMFolderSelectionButton *)emae->priv->drafts_folder_button, uri); emae_account_folder_changed((EMFolderSelectionButton *)emae->priv->drafts_folder_button, emae); - uri = e_mail_shell_module_get_folder_uri ( - mail_shell_module, E_MAIL_FOLDER_SENT); + uri = e_mail_shell_backend_get_folder_uri ( + global_mail_shell_backend, E_MAIL_FOLDER_SENT); em_folder_selection_button_set_selection((EMFolderSelectionButton *)emae->priv->sent_folder_button, uri); emae_account_folder_changed((EMFolderSelectionButton *)emae->priv->sent_folder_button, emae); } @@ -468,7 +468,7 @@ em_account_editor_folder_selector_button_new (char *widget_name, char *string1, { EMFolderTreeModel *model; - model = e_mail_shell_module_get_folder_tree_model (mail_shell_module); + model = e_mail_shell_backend_get_folder_tree_model (global_mail_shell_backend); return (GtkWidget *)em_folder_selection_button_new(model, string1 ? string1 : _("Select Folder"), NULL); } @@ -907,8 +907,8 @@ emae_account_folder(EMAccountEditor *emae, const char *name, int item, int deffo } else { const gchar *uri; - uri = e_mail_shell_module_get_folder_uri ( - mail_shell_module, deffolder); + uri = e_mail_shell_backend_get_folder_uri ( + global_mail_shell_backend, deffolder); em_folder_selection_button_set_selection(folder, uri); } @@ -2868,13 +2868,13 @@ em_account_editor_construct(EMAccountEditor *emae, EAccount *account, em_account emae->account = e_account_new(); emae->account->enabled = TRUE; - uri = e_mail_shell_module_get_folder_uri ( - mail_shell_module, E_MAIL_FOLDER_DRAFTS); + uri = e_mail_shell_backend_get_folder_uri ( + global_mail_shell_backend, E_MAIL_FOLDER_DRAFTS); e_account_set_string ( emae->account, E_ACCOUNT_DRAFTS_FOLDER_URI, uri); - uri = e_mail_shell_module_get_folder_uri ( - mail_shell_module, E_MAIL_FOLDER_SENT); + uri = e_mail_shell_backend_get_folder_uri ( + global_mail_shell_backend, E_MAIL_FOLDER_SENT); e_account_set_string ( emae->account, E_ACCOUNT_SENT_FOLDER_URI, uri); } diff --git a/mail/em-account-prefs.c b/mail/em-account-prefs.c index 2b6e3343f6..bd72edd91a 100644 --- a/mail/em-account-prefs.c +++ b/mail/em-account-prefs.c @@ -38,7 +38,7 @@ #include "em-account-prefs.h" #include "em-account-editor.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" static void em_account_prefs_class_init (EMAccountPrefsClass *class); static void em_account_prefs_init (EMAccountPrefs *prefs); @@ -243,8 +243,8 @@ account_delete_clicked (GtkButton *button, gpointer user_data) /* remove it from the folder-tree in the shell */ if (account->enabled && account->source && account->source->url) - e_mail_shell_module_remove_store_by_uri ( - mail_shell_module, account->source->url); + e_mail_shell_backend_remove_store_by_uri ( + global_mail_shell_backend, account->source->url); /* remove all the proxies account has created*/ if (has_proxies) @@ -300,12 +300,12 @@ account_able_changed(EAccount *account) if (account->source->url) { if (account->enabled) - e_mail_shell_module_load_store_by_uri ( - mail_shell_module, + e_mail_shell_backend_load_store_by_uri ( + global_mail_shell_backend, account->source->url, account->name); else - e_mail_shell_module_remove_store_by_uri ( - mail_shell_module, account->source->url); + e_mail_shell_backend_remove_store_by_uri ( + global_mail_shell_backend, account->source->url); } mail_config_write (); diff --git a/mail/em-composer-prefs.c b/mail/em-composer-prefs.c index dbc174340e..fde3297321 100644 --- a/mail/em-composer-prefs.c +++ b/mail/em-composer-prefs.c @@ -570,7 +570,7 @@ em_composer_prefs_construct (EMComposerPrefs *prefs, gtk_container_add (GTK_CONTAINER (container), widget); gtk_widget_show (widget); - /* The mail shell module responds to the "window-created" signal + /* The mail shell backend responds to the "window-created" signal * that this triggers and configures it with composer preferences. */ g_signal_connect_swapped ( widget, "editor-created", diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c index f503f2d7ed..66863faf64 100644 --- a/mail/em-composer-utils.c +++ b/mail/em-composer-utils.c @@ -60,7 +60,7 @@ #include #include -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" #ifdef G_OS_WIN32 /* Undef the similar macro from pthread.h, it doesn't check if @@ -467,8 +467,8 @@ em_utils_composer_send_cb (EMsgComposer *composer) if ((message = composer_get_message (composer, FALSE)) == NULL) return; - mail_folder = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_OUTBOX); + mail_folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_OUTBOX); camel_object_ref (mail_folder); /* mail the message */ @@ -598,11 +598,11 @@ em_utils_composer_save_draft_cb (EMsgComposer *composer) * get destroyed while we're in mail_msg_wait() a little lower * down, waiting for the folder to open */ - local_drafts_folder = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_DRAFTS); + local_drafts_folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_DRAFTS); - local_drafts_folder_uri = e_mail_shell_module_get_folder_uri ( - mail_shell_module, E_MAIL_FOLDER_DRAFTS); + local_drafts_folder_uri = e_mail_shell_backend_get_folder_uri ( + global_mail_shell_backend, E_MAIL_FOLDER_DRAFTS); g_object_ref (composer); msg = e_msg_composer_get_message_draft (composer); @@ -1569,8 +1569,8 @@ em_utils_send_receipt (CamelFolder *folder, CamelMimeMessage *message) } /* Send the receipt */ - out_folder = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_OUTBOX); + out_folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_OUTBOX); info = camel_message_info_new (NULL); camel_message_info_set_flags (info, CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN); mail_append_mail (out_folder, receipt, info, em_utils_receipt_done, NULL); @@ -1666,7 +1666,8 @@ em_utils_forward_message_raw (CamelFolder *folder, CamelMimeMessage *message, co g_free (subject); /* and send it */ - out_folder = e_mail_shell_module_get_folder (mail_shell_module, E_MAIL_FOLDER_OUTBOX); + out_folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_OUTBOX); info = camel_message_info_new (NULL); camel_message_info_set_flags (info, CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN); mail_append_mail (out_folder, forward, info, emu_forward_raw_done, NULL); @@ -2537,14 +2538,14 @@ em_utils_post_reply_to_message_by_uid (CamelFolder *folder, const char *uid) static void post_header_clicked_cb (EComposerPostHeader *header, - EShellModule *shell_module) + EShellBackend *shell_backend) { EMFolderTreeModel *model; GtkWidget *folder_tree; GtkWidget *dialog; GList *list; - model = e_mail_shell_module_get_folder_tree_model (shell_module); + model = e_mail_shell_backend_get_folder_tree_model (shell_backend); folder_tree = em_folder_tree_new_with_model (model); em_folder_tree_set_multiselect ( @@ -2589,8 +2590,8 @@ exit: * em_configure_new_composer: * @composer: a newly created #EMsgComposer * - * Integrates a newly created #EMsgComposer into the mail module. The - * composer can't link directly to the mail module without introducing + * Integrates a newly created #EMsgComposer into the mail backend. The + * composer can't link directly to the mail backend without introducing * circular library dependencies, so this function finishes configuring * things the #EMsgComposer instance can't do itself. **/ @@ -2635,5 +2636,6 @@ em_configure_new_composer (EMsgComposer *composer) * the folder selector dialog. See the handler function. */ g_signal_connect ( header, "clicked", - G_CALLBACK (post_header_clicked_cb), mail_shell_module); + G_CALLBACK (post_header_clicked_cb), + global_mail_shell_backend); } diff --git a/mail/em-filter-folder-element.c b/mail/em-filter-folder-element.c index b4b098b4b6..61051106d1 100644 --- a/mail/em-filter-folder-element.c +++ b/mail/em-filter-folder-element.c @@ -37,7 +37,7 @@ #include "libedataserver/e-sexp.h" #include "e-util/e-error.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" #define d(x) @@ -257,7 +257,7 @@ get_widget(FilterElement *fe) uri = ff->uri; else uri = em_uri_to_camel (ff->uri); - model = e_mail_shell_module_get_folder_tree_model (mail_shell_module); + model = e_mail_shell_backend_get_folder_tree_model (global_mail_shell_backend); button = em_folder_selection_button_new (model, _("Select Folder"), NULL); em_folder_selection_button_set_selection(EM_FOLDER_SELECTION_BUTTON(button), uri); diff --git a/mail/em-folder-properties.c b/mail/em-folder-properties.c index 0eed463144..e346aa3fab 100644 --- a/mail/em-folder-properties.c +++ b/mail/em-folder-properties.c @@ -44,7 +44,7 @@ #include "mail-vfolder.h" #include "mail-config.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" struct _prop_data { void *object; @@ -299,7 +299,7 @@ emfp_dialog_got_folder_quota (CamelFolder *folder, gint32 count, i,deleted; EMConfig *ec; EMConfigTargetFolder *target; - EShellModule *shell_module; + EShellBackend *shell_backend; EShellWindow *shell_window; EShellView *shell_view; CamelArgGetV *arggetv; @@ -315,9 +315,9 @@ emfp_dialog_got_folder_quota (CamelFolder *folder, store = folder->parent_store; shell_view = E_SHELL_VIEW (data); - shell_module = e_shell_view_get_shell_module (shell_view); + shell_backend = e_shell_view_get_shell_backend (shell_view); shell_window = e_shell_view_get_shell_window (shell_view); - local_store = e_mail_shell_module_get_local_store (shell_module); + local_store = e_mail_shell_backend_get_local_store (shell_backend); prop_data = g_malloc0 (sizeof (*prop_data)); prop_data->object = folder; diff --git a/mail/em-folder-selection.c b/mail/em-folder-selection.c index 3a457407f7..ba63d19082 100644 --- a/mail/em-folder-selection.c +++ b/mail/em-folder-selection.c @@ -33,7 +33,7 @@ #include "em-folder-selector.h" #include "em-folder-selection.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" /* TODO: rmeove this file, it could just go on em-folder-selection or em-utils */ @@ -64,7 +64,7 @@ em_select_folder (GtkWindow *parent_window, const char *title, const char *oklab GtkWidget *dialog; EMFolderTree *emft; - model = e_mail_shell_module_get_folder_tree_model (mail_shell_module); + model = e_mail_shell_backend_get_folder_tree_model (global_mail_shell_backend); emft = (EMFolderTree *) em_folder_tree_new_with_model (model); if (exclude) em_folder_tree_set_excluded_func(emft, exclude, user_data); diff --git a/mail/em-folder-tree-model.c b/mail/em-folder-tree-model.c index e774760ee3..289df103fd 100644 --- a/mail/em-folder-tree-model.c +++ b/mail/em-folder-tree-model.c @@ -57,7 +57,7 @@ #include #include -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" #define u(x) /* unread count debug */ #define d(x) @@ -67,7 +67,7 @@ ((obj), EM_TYPE_FOLDER_TREE_MODEL, EMFolderTreeModelPrivate)) struct _EMFolderTreeModelPrivate { - gpointer shell_module; /* weak pointer */ + gpointer shell_backend; /* weak pointer */ }; static GType col_types[] = { @@ -88,7 +88,7 @@ static void account_removed (EAccountList *accounts, EAccount *account, gpointer enum { PROP_0, - PROP_SHELL_MODULE + PROP_SHELL_BACKEND }; enum { @@ -215,16 +215,16 @@ folder_tree_model_sort (GtkTreeModel *model, } static void -folder_tree_model_set_shell_module (EMFolderTreeModel *model, - EShellModule *shell_module) +folder_tree_model_set_shell_backend (EMFolderTreeModel *model, + EShellBackend *shell_backend) { - g_return_if_fail (model->priv->shell_module == NULL); + g_return_if_fail (model->priv->shell_backend == NULL); - model->priv->shell_module = shell_module; + model->priv->shell_backend = shell_backend; g_object_add_weak_pointer ( - G_OBJECT (shell_module), - &model->priv->shell_module); + G_OBJECT (shell_backend), + &model->priv->shell_backend); } static void @@ -234,8 +234,8 @@ folder_tree_model_set_property (GObject *object, GParamSpec *pspec) { switch (property_id) { - case PROP_SHELL_MODULE: - folder_tree_model_set_shell_module ( + case PROP_SHELL_BACKEND: + folder_tree_model_set_shell_backend ( EM_FOLDER_TREE_MODEL (object), g_value_get_object (value)); return; @@ -251,9 +251,10 @@ folder_tree_model_get_property (GObject *object, GParamSpec *pspec) { switch (property_id) { - case PROP_SHELL_MODULE: + case PROP_SHELL_BACKEND: g_value_set_object ( - value, em_folder_tree_model_get_shell_module ( + value, + em_folder_tree_model_get_mail_shell_backend ( EM_FOLDER_TREE_MODEL (object))); return; } @@ -285,12 +286,12 @@ static void folder_tree_model_constructed (GObject *object) { EMFolderTreeModel *model = EM_FOLDER_TREE_MODEL (object); - EShellModule *shell_module; + EShellBackend *shell_backend; const gchar *config_dir; gchar *filename; - shell_module = model->priv->shell_module; - config_dir = e_shell_module_get_config_dir (shell_module); + shell_backend = model->priv->shell_backend; + config_dir = e_shell_backend_get_config_dir (shell_backend); filename = g_build_filename ( config_dir, "folder-tree-expand-state.xml", NULL); @@ -314,12 +315,12 @@ folder_tree_model_class_init (EMFolderTreeModelClass *class) g_object_class_install_property ( object_class, - PROP_SHELL_MODULE, + PROP_SHELL_BACKEND, g_param_spec_object ( - "shell-module", - _("Shell Module"), + "shell-backend", + _("Shell Backend"), NULL, - E_TYPE_SHELL_MODULE, + E_TYPE_SHELL_BACKEND, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); @@ -485,21 +486,22 @@ emft_model_unread_count_changed (GtkTreeModel *model, GtkTreeIter *iter) EMFolderTreeModel * -em_folder_tree_model_new (EShellModule *shell_module) +em_folder_tree_model_new (EMailShellBackend *mail_shell_backend) { - g_return_val_if_fail (E_IS_SHELL_MODULE (shell_module), NULL); + g_return_val_if_fail ( + E_IS_MAIL_SHELL_BACKEND (mail_shell_backend), NULL); return g_object_new ( EM_TYPE_FOLDER_TREE_MODEL, - "shell-module", shell_module, NULL); + "shell-backend", mail_shell_backend, NULL); } -EShellModule * -em_folder_tree_model_get_shell_module (EMFolderTreeModel *model) +EShellBackend * +em_folder_tree_model_get_shell_backend (EMFolderTreeModel *model) { g_return_val_if_fail (EM_IS_FOLDER_TREE_MODEL (model), NULL); - return model->priv->shell_module; + return model->priv->shell_backend; } static void @@ -557,7 +559,7 @@ em_folder_tree_model_set_folder_info (EMFolderTreeModel *model, GtkTreeIter *ite struct _EMFolderTreeModelStoreInfo *si, CamelFolderInfo *fi, int fully_loaded) { - EShellModule *shell_module; + EShellBackend *shell_backend; GtkTreeRowReference *uri_row, *path_row; GtkTreeStore *tree_store; unsigned int unread; @@ -575,7 +577,7 @@ em_folder_tree_model_set_folder_info (EMFolderTreeModel *model, GtkTreeIter *ite return; tree_store = GTK_TREE_STORE (model); - shell_module = model->priv->shell_module; + shell_backend = model->priv->shell_backend; if (!fully_loaded) load = fi->child == NULL && !(fi->flags & (CAMEL_FOLDER_NOCHILDREN | CAMEL_FOLDER_NOINFERIORS)); @@ -596,10 +598,10 @@ em_folder_tree_model_set_folder_info (EMFolderTreeModel *model, GtkTreeIter *ite CamelFolder *local_drafts; CamelFolder *local_outbox; - local_drafts = e_mail_shell_module_get_folder ( - shell_module, E_MAIL_FOLDER_DRAFTS); - local_outbox = e_mail_shell_module_get_folder ( - shell_module, E_MAIL_FOLDER_OUTBOX); + local_drafts = e_mail_shell_backend_get_folder ( + shell_backend, E_MAIL_FOLDER_DRAFTS); + local_outbox = e_mail_shell_backend_get_folder ( + shell_backend, E_MAIL_FOLDER_OUTBOX); if (folder == local_outbox) { int total; @@ -632,7 +634,7 @@ em_folder_tree_model_set_folder_info (EMFolderTreeModel *model, GtkTreeIter *ite /* TODO: maybe this should be handled by mail_get_folderinfo (except em-folder-tree doesn't use it, duh) */ flags = fi->flags; name = fi->name; - if (si->store == e_mail_shell_module_get_local_store (shell_module)) { + if (si->store == e_mail_shell_backend_get_local_store (shell_backend)) { if (!strcmp(fi->full_name, "Drafts")) { name = _("Drafts"); } else if (!strcmp(fi->full_name, "Templates")) { diff --git a/mail/em-folder-tree-model.h b/mail/em-folder-tree-model.h index 8236f3c303..733c940951 100644 --- a/mail/em-folder-tree-model.h +++ b/mail/em-folder-tree-model.h @@ -27,8 +27,7 @@ #include #include #include - -#include +#include /* Standard GObject macros */ #define EM_TYPE_FOLDER_TREE_MODEL \ @@ -128,8 +127,9 @@ struct _EMFolderTreeModelClass { GType em_folder_tree_model_get_type (void); EMFolderTreeModel * - em_folder_tree_model_new (EShellModule *shell_module); -EShellModule * em_folder_tree_model_get_shell_module + em_folder_tree_model_new (EMailShellBackend *mail_shell_backend); +EMailShellBackend * + em_folder_tree_model_get_mail_shell_backend (EMFolderTreeModel *model); void em_folder_tree_model_set_folder_info (EMFolderTreeModel *model, GtkTreeIter *iter, diff --git a/mail/em-folder-tree.c b/mail/em-folder-tree.c index d87db9c181..128e2fe164 100644 --- a/mail/em-folder-tree.c +++ b/mail/em-folder-tree.c @@ -73,7 +73,7 @@ #include "em-folder-properties.h" #include "em-event.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" #define d(x) @@ -502,14 +502,15 @@ em_folder_tree_construct (EMFolderTree *emft, EMFolderTreeModel *model) } GtkWidget * -em_folder_tree_new (EShellModule *shell_module) +em_folder_tree_new (EMailShellBackend *mail_shell_backend) { EMFolderTreeModel *model; EMFolderTree *emft; - g_return_val_if_fail (E_IS_SHELL_MODULE (shell_module), NULL); + g_return_val_if_fail ( + E_IS_MAIL_SHELL_BACKEND (mail_shell_backend), NULL); - model = e_mail_shell_module_get_folder_tree_model (shell_module); + model = e_mail_shell_backend_get_folder_tree_model (mail_shell_backend); emft = (EMFolderTree *) em_folder_tree_new_with_model (model); g_object_unref (model); @@ -543,7 +544,7 @@ emft_expand_node (EMFolderTreeModel *model, const char *key, EMFolderTree *emft) struct _EMFolderTreePrivate *priv = emft->priv; struct _EMFolderTreeModelStoreInfo *si; extern CamelStore *vfolder_store; - EShellModule *shell_module; + EMailShellBackend *mail_shell_backend; GtkTreeRowReference *row; GtkTreeView *tree_view; GtkTreePath *path; @@ -564,7 +565,7 @@ emft_expand_node (EMFolderTreeModel *model, const char *key, EMFolderTree *emft) uid[n] = '\0'; tree_view = GTK_TREE_VIEW (emft); - shell_module = em_folder_tree_model_get_shell_module (model); + mail_shell_backend = em_folder_tree_model_get_mail_shell_backend (model); if ((account = e_get_account_by_uid (uid)) && account->enabled) { CamelException ex; @@ -581,7 +582,7 @@ emft_expand_node (EMFolderTreeModel *model, const char *key, EMFolderTree *emft) camel_object_ref (store); } else if (!strcmp (uid, "local")) { - if (!(store = e_mail_shell_module_get_local_store (shell_module))) + if (!(store = e_mail_shell_backend_get_local_store (mail_shell_backend))) return; camel_object_ref (store); @@ -1052,7 +1053,7 @@ emft_drop_target(EMFolderTree *emft, GdkDragContext *context, GtkTreePath *path) struct _EMFolderTreePrivate *p = emft->priv; char *full_name = NULL, *uri = NULL, *src_uri = NULL; CamelStore *local, *sstore, *dstore; - EShellModule *shell_module; + EMailShellBackend *mail_shell_backend; GdkAtom atom = GDK_NONE; gboolean is_store; GtkTreeIter iter; @@ -1070,8 +1071,8 @@ emft_drop_target(EMFolderTree *emft, GdkDragContext *context, GtkTreePath *path) COL_POINTER_CAMEL_STORE, &dstore, COL_STRING_URI, &uri, -1); - shell_module = em_folder_tree_model_get_shell_module (p->model); - local = e_mail_shell_module_get_local_store (shell_module); + mail_shell_backend = em_folder_tree_model_get_mail_shell_backend (p->model); + local = e_mail_shell_backend_get_local_store (mail_shell_backend); targets = context->targets; diff --git a/mail/em-folder-tree.h b/mail/em-folder-tree.h index f0dfe72d10..d84b173db5 100644 --- a/mail/em-folder-tree.h +++ b/mail/em-folder-tree.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include /* Standard GObject macros */ @@ -84,7 +84,7 @@ struct _EMFolderTreeClass { GType em_folder_tree_get_type (void); -GtkWidget *em_folder_tree_new (EShellModule *shell_module); +GtkWidget *em_folder_tree_new (EMailShellBackend *mail_shell_backend); GtkWidget *em_folder_tree_new_with_model (EMFolderTreeModel *model); void em_folder_tree_enable_drag_and_drop (EMFolderTree *emft); diff --git a/mail/em-folder-utils.c b/mail/em-folder-utils.c index ff93c9b5a9..510bcf782e 100644 --- a/mail/em-folder-utils.c +++ b/mail/em-folder-utils.c @@ -69,7 +69,7 @@ #include "em-folder-selection.h" #include "em-folder-properties.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" #define d(x) @@ -281,7 +281,7 @@ emfu_copy_folder_selected (const char *uri, void *data) camel_exception_init (&ex); - local_store = e_mail_shell_module_get_local_store (mail_shell_module); + local_store = e_mail_shell_backend_get_local_store (global_mail_shell_backend); if (!(fromstore = camel_session_get_store (session, cfd->fi->uri, &ex))) { e_error_run(NULL, @@ -405,7 +405,7 @@ em_folder_utils_delete_folder (CamelFolder *folder) GtkWidget *dialog; int flags = 0; - local_store = e_mail_shell_module_get_local_store (mail_shell_module); + local_store = e_mail_shell_backend_get_local_store (global_mail_shell_backend); if (folder->parent_store == local_store && emfu_is_special_local_folder (folder->full_name)) { dialog = e_error_new (NULL, "mail:no-delete-special-folder", folder->full_name, NULL); @@ -440,7 +440,7 @@ em_folder_utils_rename_folder (CamelFolder *folder) gboolean done = FALSE; size_t base_len; - local_store = e_mail_shell_module_get_local_store (mail_shell_module); + local_store = e_mail_shell_backend_get_local_store (global_mail_shell_backend); /* don't allow user to rename one of the special local folders */ if (folder->parent_store == local_store && emfu_is_special_local_folder (folder->full_name)) { @@ -694,7 +694,7 @@ em_folder_utils_create_folder (CamelFolderInfo *folderinfo, EMFolderTree *emft, EMFolderTreeModel *model; GtkWidget *dialog; - model = e_mail_shell_module_get_folder_tree_model (mail_shell_module); + model = e_mail_shell_backend_get_folder_tree_model (global_mail_shell_backend); folder_tree = (EMFolderTree *) em_folder_tree_new_with_model (model); dialog = em_folder_selector_create_new (folder_tree, 0, _("Create Folder"), _("Specify where to create the folder:")); diff --git a/mail/em-folder-view.c b/mail/em-folder-view.c index 5b97f2dcb8..01c2d3dcdf 100644 --- a/mail/em-folder-view.c +++ b/mail/em-folder-view.c @@ -92,7 +92,7 @@ #include "em-composer-utils.h" #include "em-menu.h" #include "em-event.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" #include "mail-mt.h" #include "mail-ops.h" @@ -603,7 +603,7 @@ emfv_list_done_message_selected(CamelFolder *folder, const char *uid, CamelMimeM e_profile_event_emit("goto.loaded", emfv->displayed_uid, 0); - shell = e_shell_module_get_shell (mail_shell_module); + shell = e_shell_backend_get_shell (mail_shell_backend); e_shell_event (shell, "mail-icon", "evolution-mail"); /** @Event: message.reading diff --git a/mail/em-utils.c b/mail/em-utils.c index 2da8efaad2..db7f99afe8 100644 --- a/mail/em-utils.c +++ b/mail/em-utils.c @@ -80,7 +80,7 @@ #include "em-account-editor.h" #include "e-attachment.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" static void emu_save_part_done (CamelMimePart *part, char *name, int done, void *data); @@ -261,7 +261,7 @@ em_filter_editor_response (GtkWidget *dialog, int button, gpointer user_data) const gchar *data_dir; char *user; - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (global_mail_shell_backend); fc = g_object_get_data ((GObject *) dialog, "context"); user = g_strdup_printf ("%s/filters.xml", data_dir); rule_context_save ((RuleContext *) fc, user); @@ -299,7 +299,7 @@ em_utils_edit_filters (GtkWidget *parent) return; } - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (global_mail_shell_backend); fc = em_filter_context_new (); user = g_build_filename (data_dir, "filters.xml", NULL); @@ -1396,8 +1396,8 @@ em_utils_folder_is_templates (CamelFolder *folder, const char *uri) int is = FALSE; char *templates_uri; - local_templates_folder = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_TEMPLATES); + local_templates_folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_TEMPLATES); if (folder == local_templates_folder) return TRUE; @@ -1447,8 +1447,8 @@ em_utils_folder_is_drafts(CamelFolder *folder, const char *uri) int is = FALSE; char *drafts_uri; - local_drafts_folder = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_DRAFTS); + local_drafts_folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_DRAFTS); if (folder == local_drafts_folder) return TRUE; @@ -1498,8 +1498,8 @@ em_utils_folder_is_sent(CamelFolder *folder, const char *uri) int is = FALSE; char *sent_uri; - local_sent_folder = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_SENT); + local_sent_folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_SENT); if (folder == local_sent_folder) return TRUE; @@ -1544,8 +1544,8 @@ em_utils_folder_is_outbox(CamelFolder *folder, const char *uri) { CamelFolder *local_outbox_folder; - local_outbox_folder = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_OUTBOX); + local_outbox_folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_OUTBOX); /* There can be only one. */ return folder == local_outbox_folder; @@ -2437,7 +2437,7 @@ em_utils_show_error_silent (GtkWidget *widget) EActivity *activity; activity = e_alert_activity_new_warning (widget); - e_shell_module_add_activity (mail_shell_module, activity); + e_shell_backend_add_activity (global_mail_shell_backend, activity); g_object_unref (activity); if (g_object_get_data (G_OBJECT (widget), "response-handled") == NULL) @@ -2452,7 +2452,7 @@ em_utils_show_info_silent (GtkWidget *widget) EActivity *activity; activity = e_alert_activity_new_info (widget); - e_shell_module_add_activity (mail_shell_module, activity); + e_shell_backend_add_activity (global_mail_shell_backend, activity); g_object_unref (activity); if (g_object_get_data (G_OBJECT (widget), "response-handled") == NULL) diff --git a/mail/em-vfolder-rule.c b/mail/em-vfolder-rule.c index 128b63b744..d75af50050 100644 --- a/mail/em-vfolder-rule.c +++ b/mail/em-vfolder-rule.c @@ -40,7 +40,7 @@ #include "e-util/e-error.h" #include "e-util/e-util-private.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" #define d(x) @@ -509,7 +509,7 @@ source_add(GtkWidget *widget, struct _source_data *data) EMFolderTreeModel *model; GtkWidget *dialog; - model = e_mail_shell_module_get_folder_tree_model (mail_shell_module); + model = e_mail_shell_backend_get_folder_tree_model (global_mail_shell_backend); emft =(EMFolderTree *)em_folder_tree_new_with_model (model); em_folder_tree_set_excluded(emft, EMFT_EXCLUDE_NOSELECT); diff --git a/mail/importers/evolution-mbox-importer.c b/mail/importers/evolution-mbox-importer.c index 36cf8768ff..964741f28a 100644 --- a/mail/importers/evolution-mbox-importer.c +++ b/mail/importers/evolution-mbox-importer.c @@ -40,7 +40,7 @@ #include -#include "mail/e-mail-shell-module.h" +#include "mail/e-mail-shell-backend.h" #include "mail/em-folder-selection-button.h" #include "mail/mail-mt.h" @@ -75,9 +75,10 @@ mbox_getwidget(EImport *ei, EImportTarget *target, EImportImporter *im) EMFolderTreeModel *model; const gchar *local_inbox_folder_uri; - local_inbox_folder_uri = e_mail_shell_module_get_folder_uri ( - mail_shell_module, E_MAIL_FOLDER_INBOX); - model = e_mail_shell_module_get_folder_tree_model (mail_shell_module); + local_inbox_folder_uri = e_mail_shell_backend_get_folder_uri ( + global_mail_shell_backend, E_MAIL_FOLDER_INBOX); + model = e_mail_shell_backend_get_folder_tree_model ( + global_mail_shell_backend); hbox = gtk_hbox_new(FALSE, 0); diff --git a/mail/importers/mail-importer.c b/mail/importers/mail-importer.c index fde63dfdae..dbae51dfcb 100644 --- a/mail/importers/mail-importer.c +++ b/mail/importers/mail-importer.c @@ -36,7 +36,6 @@ #include #include -#include #include #include #include @@ -49,7 +48,7 @@ #include "mail/mail-mt.h" #include "mail/mail-tools.h" -#include "mail/e-mail-shell-module.h" +#include "mail/e-mail-shell-backend.h" #include "mail-importer.h" @@ -203,8 +202,8 @@ import_mbox_exec (struct _import_mbox_msg *m) } if (m->uri == NULL || m->uri[0] == 0) - folder = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_INBOX); + folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_INBOX); else folder = mail_tool_uri_to_folder(m->uri, CAMEL_STORE_FOLDER_CREATE, &m->base.ex); @@ -369,7 +368,7 @@ import_folders_rec(struct _import_folders_data *m, const char *filepath, const c if (dir == NULL) return; - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (global_mail_shell_backend); utf8_filename = g_filename_to_utf8 (filepath, -1, NULL, NULL, NULL); camel_operation_start(NULL, _("Scanning %s"), utf8_filename); diff --git a/mail/mail-autofilter.c b/mail/mail-autofilter.c index f73c44be42..b437fda1c6 100644 --- a/mail/mail-autofilter.c +++ b/mail/mail-autofilter.c @@ -48,7 +48,7 @@ #include #include -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" #define d(x) @@ -346,6 +346,7 @@ filter_rule_from_message (EMFilterContext *context, CamelMimeMessage *msg, int f void filter_gui_add_from_message (CamelMimeMessage *msg, const char *source, int flags) { + EShellBackend *shell_backend; EMFilterContext *fc; const gchar *data_dir; char *user, *system; @@ -353,8 +354,10 @@ filter_gui_add_from_message (CamelMimeMessage *msg, const char *source, int flag g_return_if_fail (msg != NULL); + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + fc = em_filter_context_new (); - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (shell_backend); user = g_build_filename (data_dir, "filters.xml", NULL); system = g_build_filename (EVOLUTION_PRIVDATADIR, "filtertypes.xml", NULL); rule_context_load ((RuleContext *)fc, system, user); @@ -372,6 +375,7 @@ filter_gui_add_from_message (CamelMimeMessage *msg, const char *source, int flag void mail_filter_rename_uri(CamelStore *store, const char *olduri, const char *newuri) { + EShellBackend *shell_backend; EMFilterContext *fc; const gchar *data_dir; char *user, *system; @@ -381,8 +385,10 @@ mail_filter_rename_uri(CamelStore *store, const char *olduri, const char *newuri eolduri = em_uri_from_camel(olduri); enewuri = em_uri_from_camel(newuri); + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + fc = em_filter_context_new (); - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (shell_backend); user = g_build_filename (data_dir, "filters.xml", NULL); system = g_build_filename (EVOLUTION_PRIVDATADIR, "filtertypes.xml", NULL); rule_context_load ((RuleContext *)fc, system, user); @@ -406,6 +412,7 @@ mail_filter_rename_uri(CamelStore *store, const char *olduri, const char *newuri void mail_filter_delete_uri(CamelStore *store, const char *uri) { + EShellBackend *shell_backend; EMFilterContext *fc; const gchar *data_dir; char *user, *system; @@ -414,8 +421,10 @@ mail_filter_delete_uri(CamelStore *store, const char *uri) euri = em_uri_from_camel(uri); + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + fc = em_filter_context_new (); - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (shell_backend); user = g_build_filename (data_dir, "filters.xml", NULL); system = g_build_filename (EVOLUTION_PRIVDATADIR, "filtertypes.xml", NULL); rule_context_load ((RuleContext *)fc, system, user); diff --git a/mail/mail-config.c b/mail/mail-config.c index be5b0164ee..45fc8f9b40 100644 --- a/mail/mail-config.c +++ b/mail/mail-config.c @@ -64,7 +64,7 @@ #include "mail-mt.h" #include "mail-tools.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" typedef struct { GConfClient *gconf; @@ -773,11 +773,13 @@ mail_config_get_default_transport (void) static char * uri_to_evname (const char *uri, const char *prefix) { + EShellBackend *shell_backend; const gchar *data_dir; char *safe; char *tmp; - data_dir = e_shell_module_get_data_dir (mail_shell_module); + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + data_dir = e_shell_backend_get_data_dir (shell_backend); safe = g_strdup (uri); e_filename_make_safe (safe); @@ -855,10 +857,10 @@ mail_config_uri_deleted (GCompareFunc uri_cmp, const char *uri) const gchar *local_sent_folder_uri; /* assumes these can't be removed ... */ - local_drafts_folder_uri = e_mail_shell_module_get_folder_uri ( - mail_shell_module, E_MAIL_FOLDER_DRAFTS); - local_sent_folder_uri = e_mail_shell_module_get_folder_uri ( - mail_shell_module, E_MAIL_FOLDER_SENT); + local_drafts_folder_uri = e_mail_shell_backend_get_folder_uri ( + global_mail_shell_backend, E_MAIL_FOLDER_DRAFTS); + local_sent_folder_uri = e_mail_shell_backend_get_folder_uri ( + global_mail_shell_backend, E_MAIL_FOLDER_SENT); account_list = e_get_account_list (); iter = e_list_get_iterator ((EList *) account_list); @@ -905,10 +907,12 @@ mail_config_folder_to_safe_url (CamelFolder *folder) char * mail_config_folder_to_cachename (CamelFolder *folder, const char *prefix) { + EShellBackend *shell_backend; char *url, *basename, *filename; const gchar *config_dir; - config_dir = e_shell_module_get_config_dir (mail_shell_module); + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + config_dir = e_shell_backend_get_config_dir (shell_backend); url = mail_config_folder_to_safe_url (folder); basename = g_strdup_printf ("%s%s", prefix, url); diff --git a/mail/mail-folder-cache.c b/mail/mail-folder-cache.c index f4e07f289c..097b9bf9b4 100644 --- a/mail/mail-folder-cache.c +++ b/mail/mail-folder-cache.c @@ -56,7 +56,6 @@ #include "mail-ops.h" #include "mail-session.h" #include "mail-tools.h" -#include "e-mail-shell-module.h" /* For notifications of changes */ #include "mail-vfolder.h" @@ -110,7 +109,7 @@ struct _folder_update { }; struct _store_info { - EShellModule *shell_module; + EMailShellBackend *mail_shell_backend; GHashTable *folders; /* by full_name */ GHashTable *folders_uri; /* by uri */ @@ -152,14 +151,14 @@ free_update(struct _folder_update *up) } static void -real_flush_updates (EShellModule *shell_module) +real_flush_updates (EMailShellBackend *mail_shell_backend) { EShell *shell; struct _EMFolderTreeModel *model; struct _folder_update *up; - shell = e_shell_module_get_shell (shell_module); - model = e_mail_shell_module_get_folder_tree_model (shell_module); + shell = e_shell_backend_get_shell (E_SHELL_BACKEND (mail_shell_backend)); + model = e_mail_shell_backend_get_folder_tree_model (mail_shell_backend); LOCK(info_lock); while ((up = (struct _folder_update *)e_dlist_remhead(&updates))) { @@ -233,13 +232,13 @@ real_flush_updates (EShellModule *shell_module) } static void -flush_updates (EShellModule *shell_module) +flush_updates (EMailShellBackend *shell_backend) { if (update_id == -1 && !e_dlist_empty(&updates)) update_id = mail_async_event_emit ( mail_async_event, MAIL_ASYNC_GUI, (MailAsyncFunc) real_flush_updates, - shell_module, NULL, NULL); + shell_backend, NULL, NULL); } static void @@ -252,7 +251,7 @@ unset_folder_info(struct _folder_info *mfi, int delete, int unsub) if (mfi->folder) { CamelFolder *folder = mfi->folder; - camel_object_unhook_event(folder, "folder_changed", folder_changed, mfi->store_info->shell_module); + camel_object_unhook_event(folder, "folder_changed", folder_changed, mfi->store_info->mail_shell_backend); camel_object_unhook_event(folder, "renamed", folder_renamed, NULL); camel_object_unhook_event(folder, "finalize", folder_finalised, NULL); } @@ -269,7 +268,7 @@ unset_folder_info(struct _folder_info *mfi, int delete, int unsub) up->uri = g_strdup(mfi->uri); e_dlist_addtail(&updates, (EDListNode *)up); - flush_updates(mfi->store_info->shell_module); + flush_updates(mfi->store_info->mail_shell_backend); } } @@ -307,7 +306,7 @@ static void update_1folder(struct _folder_info *mfi, int new, CamelFolderInfo *info) { struct _folder_update *up; - EShellModule *shell_module; + EMailShellBackend *mail_shell_backend; CamelFolder *folder; CamelFolder *local_drafts; CamelFolder *local_outbox; @@ -315,13 +314,13 @@ update_1folder(struct _folder_info *mfi, int new, CamelFolderInfo *info) int unread = -1; int deleted; - shell_module = mfi->store_info->shell_module; - local_drafts = e_mail_shell_module_get_folder ( - shell_module, E_MAIL_FOLDER_DRAFTS); - local_outbox = e_mail_shell_module_get_folder ( - shell_module, E_MAIL_FOLDER_OUTBOX); - local_sent = e_mail_shell_module_get_folder ( - shell_module, E_MAIL_FOLDER_SENT); + mail_shell_backend = mfi->store_info->mail_shell_backend; + local_drafts = e_mail_shell_backend_get_folder ( + mail_shell_backend, E_MAIL_FOLDER_DRAFTS); + local_outbox = e_mail_shell_backend_get_folder ( + mail_shell_backend, E_MAIL_FOLDER_OUTBOX); + local_sent = e_mail_shell_backend_get_folder ( + mail_shell_backend, E_MAIL_FOLDER_SENT); folder = mfi->folder; if (folder) { @@ -366,7 +365,7 @@ update_1folder(struct _folder_info *mfi, int new, CamelFolderInfo *info) up->uri = g_strdup(mfi->uri); camel_object_ref(up->store); e_dlist_addtail(&updates, (EDListNode *)up); - flush_updates(shell_module); + flush_updates(mail_shell_backend); } static void @@ -400,7 +399,7 @@ setup_folder(CamelFolderInfo *fi, struct _store_info *si) up->add = TRUE; e_dlist_addtail(&updates, (EDListNode *)up); - flush_updates(si->shell_module); + flush_updates(si->mail_shell_backend); } } @@ -423,7 +422,7 @@ static void folder_changed (CamelObject *o, gpointer event_data, gpointer user_data) { static time_t last_newmail = 0; - EShellModule *shell_module = user_data; + EMailShellBackend *mail_shell_backend = user_data; CamelFolderChangeInfo *changes = event_data; CamelFolder *folder = (CamelFolder *)o; CamelFolder *local_drafts; @@ -439,12 +438,12 @@ folder_changed (CamelObject *o, gpointer event_data, gpointer user_data) d(printf("folder '%s' changed\n", folder->full_name)); - local_drafts = e_mail_shell_module_get_folder ( - shell_module, E_MAIL_FOLDER_DRAFTS); - local_outbox = e_mail_shell_module_get_folder ( - shell_module, E_MAIL_FOLDER_OUTBOX); - local_sent = e_mail_shell_module_get_folder ( - shell_module, E_MAIL_FOLDER_SENT); + local_drafts = e_mail_shell_backend_get_folder ( + mail_shell_backend, E_MAIL_FOLDER_DRAFTS); + local_outbox = e_mail_shell_backend_get_folder ( + mail_shell_backend, E_MAIL_FOLDER_OUTBOX); + local_sent = e_mail_shell_backend_get_folder ( + mail_shell_backend, E_MAIL_FOLDER_SENT); if (!CAMEL_IS_VEE_FOLDER(folder) && folder != local_drafts @@ -541,7 +540,7 @@ void mail_note_folder(CamelFolder *folder) UNLOCK(info_lock); - camel_object_hook_event(folder, "folder_changed", folder_changed, si->shell_module); + camel_object_hook_event(folder, "folder_changed", folder_changed, si->mail_shell_backend); camel_object_hook_event(folder, "renamed", folder_renamed, NULL); camel_object_hook_event(folder, "finalize", folder_finalised, NULL); } @@ -634,6 +633,7 @@ folder_to_url(CamelStore *store, const char *full_name) static void rename_folders(struct _store_info *si, const char *oldbase, const char *newbase, CamelFolderInfo *fi) { + EShellBackend *shell_backend; char *old, *olduri, *oldfile, *newuri, *newfile; struct _folder_info *mfi; struct _folder_update *up; @@ -684,7 +684,7 @@ rename_folders(struct _store_info *si, const char *oldbase, const char *newbase, up->add = TRUE; e_dlist_addtail(&updates, (EDListNode *)up); - flush_updates(si->shell_module); + flush_updates(si->mail_shell_backend); #if 0 if (fi->sibling) rename_folders(si, oldbase, newbase, fi->sibling, folders); @@ -693,7 +693,8 @@ rename_folders(struct _store_info *si, const char *oldbase, const char *newbase, #endif /* rename the meta-data we maintain ourselves */ - config_dir = e_shell_module_get_config_dir (si->shell_module); + shell_backend = E_SHELL_BACKEND (si->mail_shell_backend); + config_dir = e_shell_backend_get_config_dir (shell_backend); olduri = folder_to_url(si->store, old); e_filename_make_safe(olduri); newuri = folder_to_url(si->store, fi->full_name); @@ -808,7 +809,7 @@ mail_note_store_remove(CamelStore *store) if (si) { g_hash_table_remove(stores, store); - g_object_unref(si->shell_module); + g_object_unref(si->mail_shell_backend); camel_object_unhook_event(store, "folder_opened", store_folder_opened, NULL); camel_object_unhook_event(store, "folder_created", store_folder_created, NULL); @@ -962,7 +963,7 @@ store_online_cb (CamelStore *store, void *data) } void -mail_note_store(EShellModule *shell_module, CamelStore *store, CamelOperation *op, +mail_note_store(EMailShellBackend *mail_shell_backend, CamelStore *store, CamelOperation *op, gboolean (*done)(CamelStore *store, CamelFolderInfo *info, void *data), void *data) { struct _store_info *si; @@ -971,7 +972,7 @@ mail_note_store(EShellModule *shell_module, CamelStore *store, CamelOperation *o guint timeout; int hook = 0; - g_return_if_fail (E_IS_SHELL_MODULE (shell_module)); + g_return_if_fail (E_IS_MAIL_SHELL_BACKEND (mail_shell_backend)); g_return_if_fail (CAMEL_IS_STORE(store)); g_return_if_fail (mail_in_main_thread()); @@ -991,7 +992,7 @@ mail_note_store(EShellModule *shell_module, CamelStore *store, CamelOperation *o d(printf("Noting a new store: %p: %s\n", store, camel_url_to_string(((CamelService *)store)->url, 0))); si = g_malloc0(sizeof(*si)); - si->shell_module = g_object_ref (shell_module); + si->mail_shell_backend = g_object_ref (mail_shell_backend); si->folders = g_hash_table_new(g_str_hash, g_str_equal); si->folders_uri = g_hash_table_new(CAMEL_STORE_CLASS(CAMEL_OBJECT_GET_CLASS(store))->hash_folder_name, CAMEL_STORE_CLASS(CAMEL_OBJECT_GET_CLASS(store))->compare_folder_name); diff --git a/mail/mail-folder-cache.h b/mail/mail-folder-cache.h index d685e5a5ad..fe893af84f 100644 --- a/mail/mail-folder-cache.h +++ b/mail/mail-folder-cache.h @@ -27,14 +27,15 @@ #define _MAIL_FOLDER_CACHE_H #include -#include + +#include "e-mail-shell-backend.h" /* Add a store whose folders should appear in the shell The folders are scanned from the store, and/or added at runtime via the folder_created event. The 'done' function returns if we can free folder info. */ void -mail_note_store (EShellModule *shell_module, CamelStore *store, CamelOperation *op, +mail_note_store (EMailShellBackend *mail_shell_backend, CamelStore *store, CamelOperation *op, gboolean (*done) (CamelStore *store, CamelFolderInfo *info, void *data), void *data); diff --git a/mail/mail-mt.c b/mail/mail-mt.c index 566d5ecd6f..dbdfe3b690 100644 --- a/mail/mail-mt.c +++ b/mail/mail-mt.c @@ -43,7 +43,7 @@ #include "mail-session.h" #include "mail-mt.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" /*#define MALLOC_CHECK*/ #define LOG_OPS @@ -142,6 +142,10 @@ mail_msg_new (MailMsgInfo *info) static void end_event_callback (CamelObject *o, EActivity *activity, void *error) { + EShellBackend *shell_backend; + + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + if (error == NULL) { e_activity_complete (activity); g_object_unref (activity); @@ -149,7 +153,7 @@ end_event_callback (CamelObject *o, EActivity *activity, void *error) if (activity != NULL) g_object_unref (activity); activity = e_alert_activity_new_warning (error); - e_shell_module_add_activity (mail_shell_module, activity); + e_shell_backend_add_activity (shell_backend, activity); g_object_unref (activity); } } @@ -937,6 +941,7 @@ struct _op_status_msg { static void op_status_exec (struct _op_status_msg *m) { + EShellBackend *shell_backend; MailMsg *msg; MailMsgPrivate *data; char *out, *p, *o, c; @@ -944,6 +949,8 @@ op_status_exec (struct _op_status_msg *m) g_return_if_fail (mail_in_main_thread ()); + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + MAIL_MT_LOCK (mail_msg_lock); msg = g_hash_table_lookup (mail_msg_active_table, m->data); @@ -990,7 +997,7 @@ op_status_exec (struct _op_status_msg *m) data->activity = e_activity_new (what); e_activity_set_allow_cancel (data->activity, TRUE); e_activity_set_percent (data->activity, 0.0); - e_shell_module_add_activity (mail_shell_module, data->activity); + e_shell_backend_add_activity (shell_backend, data->activity); g_signal_connect_swapped ( data->activity, "cancelled", diff --git a/mail/mail-ops.c b/mail/mail-ops.c index 97df0ed9bd..63175d73d6 100644 --- a/mail/mail-ops.c +++ b/mail/mail-ops.c @@ -69,7 +69,7 @@ #include "mail-tools.h" #include "mail-vfolder.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" #define w(x) #define d(x) @@ -244,16 +244,19 @@ static char * uid_cachename_hack (CamelStore *store) { CamelURL *url = CAMEL_SERVICE (store)->url; + EShellBackend *shell_backend; char *encoded_url, *filename; const gchar *data_dir; + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + encoded_url = g_strdup_printf ("%s%s%s@%s", url->user, url->authmech ? ";auth=" : "", url->authmech ? url->authmech : "", url->host); e_filename_make_safe (encoded_url); - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (shell_backend); filename = g_build_filename (data_dir, "pop", encoded_url, "uid-cache", NULL); g_free (encoded_url); @@ -275,8 +278,8 @@ fetch_mail_exec (struct _fetch_mail_msg *m) if (m->cancel) camel_operation_register (m->cancel); - fm->destination = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_LOCAL_INBOX); + fm->destination = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_LOCAL_INBOX); if (fm->destination == NULL) goto fail; camel_object_ref (fm->destination); @@ -581,8 +584,8 @@ mail_send_message(CamelFolder *queue, const char *uid, const char *destination, } if (!folder) { - folder = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_SENT); + folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_SENT); camel_object_ref(folder); } @@ -595,8 +598,8 @@ mail_send_message(CamelFolder *queue, const char *uid, const char *destination, if (camel_exception_get_id (ex) == CAMEL_EXCEPTION_USER_CANCEL) goto exit; - sent_folder = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_SENT); + sent_folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_SENT); if (folder != sent_folder) { const char *name; @@ -698,8 +701,8 @@ send_queue_exec (struct _send_queue_msg *m) d(printf("sending queue\n")); - sent_folder = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_SENT); + sent_folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_SENT); if (!(uids = camel_folder_get_uids (m->queue))) return; @@ -1761,14 +1764,17 @@ empty_trash_desc (struct _empty_trash_msg *m) static void empty_trash_exec (struct _empty_trash_msg *m) { + EShellBackend *shell_backend; const gchar *data_dir; CamelFolder *trash; char *uri; + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + if (m->account) { trash = mail_tool_get_trash (m->account->source->url, FALSE, &m->base.ex); } else { - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (shell_backend); uri = g_strdup_printf ("mbox:%s/local", data_dir); trash = mail_tool_get_trash (uri, TRUE, &m->base.ex); g_free (uri); diff --git a/mail/mail-send-recv.c b/mail/mail-send-recv.c index 3ffc9b46a6..7b6326338e 100644 --- a/mail/mail-send-recv.c +++ b/mail/mail-send-recv.c @@ -50,7 +50,7 @@ #include "e-util/e-account-utils.h" #include "e-util/gconf-bridge.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" #define d(x) @@ -164,8 +164,8 @@ setup_send_data(void) g_str_hash, g_str_equal, (GDestroyNotify) NULL, (GDestroyNotify) free_folder_info); - data->inbox = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_LOCAL_INBOX); + data->inbox = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_LOCAL_INBOX); camel_object_ref(data->inbox); data->active = g_hash_table_new_full ( g_str_hash, g_str_equal, @@ -692,8 +692,8 @@ receive_done (char *uri, void *data) if (info->type == SEND_SEND && info->state == SEND_ACTIVE && info->again) { CamelFolder *local_outbox_folder; - local_outbox_folder = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_OUTBOX); + local_outbox_folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_OUTBOX); info->again = 0; mail_send_queue (local_outbox_folder, @@ -908,7 +908,7 @@ receive_update_got_store (char *uri, CamelStore *store, void *data) struct _send_info *info = data; if (store) { - mail_note_store(mail_shell_module, store, info->cancel, receive_update_got_folderinfo, info); + mail_note_store(global_mail_shell_backend, store, info->cancel, receive_update_got_folderinfo, info); } else { receive_done("", info); } @@ -940,8 +940,8 @@ mail_send_receive (GtkWindow *parent) accounts = e_get_account_list (); - outbox_folder = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_OUTBOX); + outbox_folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_OUTBOX); data = build_dialog ( parent, accounts, outbox_folder, account->transport->url); scan = data->infos; @@ -1090,14 +1090,14 @@ auto_online (EShell *shell) /* call to setup initial, and after changes are made to the config */ /* FIXME: Need a cleanup funciton for when object is deactivated */ void -mail_autoreceive_init (EShellModule *shell_module, +mail_autoreceive_init (EShellBackend *shell_backend, CamelSession *session) { EAccountList *accounts; EIterator *iter; EShell *shell; - g_return_if_fail (E_IS_SHELL_MODULE (shell_module)); + g_return_if_fail (E_IS_SHELL_BACKEND (shell_backend)); g_return_if_fail (CAMEL_IS_SESSION (session)); if (auto_active) @@ -1113,7 +1113,7 @@ mail_autoreceive_init (EShellModule *shell_module, for (iter = e_list_get_iterator((EList *)accounts);e_iterator_is_valid(iter);e_iterator_next(iter)) auto_account_added(accounts, (EAccount *)e_iterator_get(iter), NULL); - shell = e_shell_module_get_shell (shell_module); + shell = e_shell_backend_get_shell (shell_backend); auto_online (shell); @@ -1174,8 +1174,8 @@ mail_receive_uri (const gchar *uri, gboolean keep_on_server) break; case SEND_SEND: /* todo, store the folder in info? */ - outbox_folder = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_OUTBOX); + outbox_folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_OUTBOX); mail_send_queue (outbox_folder, info->uri, FILTER_SOURCE_OUTGOING, info->cancel, @@ -1237,8 +1237,8 @@ mail_send (void) g_hash_table_insert (data->active, SEND_URI_KEY, info); /* todo, store the folder in info? */ - outbox_folder = e_mail_shell_module_get_folder ( - mail_shell_module, E_MAIL_FOLDER_OUTBOX); + outbox_folder = e_mail_shell_backend_get_folder ( + global_mail_shell_backend, E_MAIL_FOLDER_OUTBOX); mail_send_queue (outbox_folder, info->uri, FILTER_SOURCE_OUTGOING, info->cancel, diff --git a/mail/mail-send-recv.h b/mail/mail-send-recv.h index d602e63bd7..a9f18f6a0b 100644 --- a/mail/mail-send-recv.h +++ b/mail/mail-send-recv.h @@ -25,7 +25,7 @@ #include #include -#include +#include G_BEGIN_DECLS @@ -39,7 +39,7 @@ void mail_receive_uri (const gchar *uri, void mail_send (void); /* setup auto receive stuff */ -void mail_autoreceive_init (EShellModule *shell_module, +void mail_autoreceive_init (EShellBackend *shell_backend, CamelSession *session); G_END_DECLS diff --git a/mail/mail-session.c b/mail/mail-session.c index df5d35c179..5cb61e9f71 100644 --- a/mail/mail-session.c +++ b/mail/mail-session.c @@ -83,7 +83,7 @@ typedef struct _MailSessionClass { } MailSessionClass; -static EShellModule *mail_shell_module; +static EMailShellBackend *session_mail_shell_backend; static CamelSessionClass *ms_parent_class; static char *get_password(CamelSession *session, CamelService *service, const char *domain, const char *prompt, const char *item, guint32 flags, CamelException *ex); @@ -512,7 +512,7 @@ main_get_filter_driver (CamelSession *session, const char *type, CamelException gconf = mail_config_get_gconf_client (); - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (session_mail_shell_backend); user = g_build_filename (data_dir, "filters.xml", NULL); system = g_build_filename (EVOLUTION_PRIVDATADIR, "filtertypes.xml", NULL); fc = (RuleContext *) em_filter_context_new (); @@ -706,16 +706,18 @@ mail_session_check_junk_notify (GConfClient *gconf, guint id, GConfEntry *entry, } void -mail_session_init (EShellModule *shell_module) +mail_session_init (EMailShellBackend *mail_shell_backend) { EShell *shell; + EShellBackend *shell_backend; GConfClient *gconf; gboolean online; const gchar *data_dir; - mail_shell_module = shell_module; + session_mail_shell_backend = mail_shell_backend; - shell = e_shell_module_get_shell (shell_module); + shell_backend = E_SHELL_BACKEND (mail_shell_backend); + shell = e_shell_backend_get_shell (shell_backend); online = e_shell_get_online (shell); data_dir = e_get_user_data_dir (); @@ -728,7 +730,7 @@ mail_session_init (EShellModule *shell_module) e_account_combo_box_set_session (session); /* XXX Don't ask... */ e_account_writable(NULL, E_ACCOUNT_SOURCE_SAVE_PASSWD); /* Init the EAccount Setup */ - data_dir = e_shell_module_get_data_dir (shell_module); + data_dir = e_shell_backend_get_data_dir (shell_backend); camel_session_construct (session, data_dir); gconf = mail_config_get_gconf_client (); diff --git a/mail/mail-session.h b/mail/mail-session.h index e98a4bd604..135898e8b2 100644 --- a/mail/mail-session.h +++ b/mail/mail-session.h @@ -25,11 +25,11 @@ #include #include -#include +#include G_BEGIN_DECLS -void mail_session_init (EShellModule *shell_module); +void mail_session_init (EMailShellBackend *mail_shell_backend); void mail_session_shutdown (void); gboolean mail_session_get_interactive (void); void mail_session_set_interactive (gboolean interactive); diff --git a/mail/mail-tools.c b/mail/mail-tools.c index 4c7131dacc..d5f90b0d35 100644 --- a/mail/mail-tools.c +++ b/mail/mail-tools.c @@ -58,7 +58,7 @@ #include "mail-tools.h" #include "mail-vfolder.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" /* **************************************** */ @@ -107,6 +107,7 @@ mail_tool_get_trash (const gchar *url, int connect, CamelException *ex) static char * mail_tool_get_local_movemail_path (const unsigned char *uri, CamelException *ex) { + EShellBackend *shell_backend; unsigned char *safe_uri, *c; const gchar *data_dir; char *path, *full; @@ -117,7 +118,8 @@ mail_tool_get_local_movemail_path (const unsigned char *uri, CamelException *ex) if (strchr("/:;=|%&#!*^()\\, ", *c) || !isprint((int) *c)) *c = '_'; - data_dir = e_shell_module_get_data_dir (mail_shell_module); + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + data_dir = e_shell_backend_get_data_dir (shell_backend); path = g_build_filename (data_dir, "spool", NULL); if (g_stat(path, &st) == -1 && g_mkdir_with_parents(path, 0777) == -1) { diff --git a/mail/mail-vfolder.c b/mail/mail-vfolder.c index 2afcafdd6a..dc0f64e6fd 100644 --- a/mail/mail-vfolder.c +++ b/mail/mail-vfolder.c @@ -50,7 +50,7 @@ #include "mail-tools.h" #include "mail-vfolder.h" -#include "e-mail-shell-module.h" +#include "e-mail-shell-backend.h" #define d(x) /* (printf("%s:%s: ", G_STRLOC, G_STRFUNC), (x))*/ @@ -344,12 +344,12 @@ uri_is_ignore(CamelStore *store, const char *uri) const gchar *local_sent_folder_uri; int found = FALSE; - local_drafts_folder_uri = e_mail_shell_module_get_folder_uri ( - mail_shell_module, E_MAIL_FOLDER_DRAFTS); - local_outbox_folder_uri = e_mail_shell_module_get_folder_uri ( - mail_shell_module, E_MAIL_FOLDER_OUTBOX); - local_sent_folder_uri = e_mail_shell_module_get_folder_uri ( - mail_shell_module, E_MAIL_FOLDER_SENT); + local_drafts_folder_uri = e_mail_shell_backend_get_folder_uri ( + global_mail_shell_backend, E_MAIL_FOLDER_DRAFTS); + local_outbox_folder_uri = e_mail_shell_backend_get_folder_uri ( + global_mail_shell_backend, E_MAIL_FOLDER_OUTBOX); + local_sent_folder_uri = e_mail_shell_backend_get_folder_uri ( + global_mail_shell_backend, E_MAIL_FOLDER_SENT); d(printf("checking '%s' against:\n %s\n %s\n %s\n", uri, local_outbox_folder_uri, @@ -534,6 +534,7 @@ done: void mail_vfolder_delete_uri(CamelStore *store, const char *curi) { + EShellBackend *shell_backend; FilterRule *rule; const char *source; CamelVeeFolder *vf; @@ -550,6 +551,8 @@ mail_vfolder_delete_uri(CamelStore *store, const char *curi) g_return_if_fail (mail_in_main_thread()); + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + changed = g_string_new (""); LOCK(); @@ -610,7 +613,7 @@ done: dialog = e_error_new(NULL, "mail:vfolder-updated", changed->str, uri, NULL); em_utils_show_info_silent (dialog); - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (shell_backend); user = g_build_filename (data_dir, "vfolders.xml", NULL); rule_context_save ((RuleContext *) context, user); g_free (user); @@ -625,6 +628,7 @@ done: void mail_vfolder_rename_uri(CamelStore *store, const char *cfrom, const char *cto) { + EShellBackend *shell_backend; FilterRule *rule; const char *source; CamelVeeFolder *vf; @@ -638,6 +642,8 @@ mail_vfolder_rename_uri(CamelStore *store, const char *cfrom, const char *cto) g_return_if_fail (mail_in_main_thread()); + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + from = em_uri_from_camel(cfrom); to = em_uri_from_camel(cto); @@ -678,7 +684,7 @@ mail_vfolder_rename_uri(CamelStore *store, const char *cfrom, const char *cto) char *user; d(printf("Vfolders updated from renamed folder\n")); - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (shell_backend); user = g_build_filename (data_dir, "vfolders.xml", NULL); rule_context_save((RuleContext *)context, user); g_free(user); @@ -832,6 +838,7 @@ store_folder_created(CamelObject *o, void *event_data, void *data) static void store_folder_deleted(CamelObject *o, void *event_data, void *data) { + EShellBackend *shell_backend; CamelStore *store = (CamelStore *)o; CamelFolderInfo *info = event_data; FilterRule *rule; @@ -840,6 +847,8 @@ store_folder_deleted(CamelObject *o, void *event_data, void *data) d(printf("Folder deleted: %s\n", info->name)); store = store; + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + /* Warning not thread safe, but might be enough */ LOCK(); @@ -856,7 +865,7 @@ store_folder_deleted(CamelObject *o, void *event_data, void *data) g_object_unref(rule); g_signal_connect(context, "rule_removed", G_CALLBACK(context_rule_removed), context); - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (shell_backend); user = g_build_filename (data_dir, "vfolders.xml", NULL); rule_context_save((RuleContext *)context, user); g_free(user); @@ -870,12 +879,15 @@ store_folder_deleted(CamelObject *o, void *event_data, void *data) static void store_folder_renamed(CamelObject *o, void *event_data, void *data) { + EShellBackend *shell_backend; CamelRenameInfo *info = event_data; FilterRule *rule; char *user; gpointer key, folder; + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + /* This should be more-or-less thread-safe */ d(printf("Folder renamed to '%s' from '%s'\n", info->new->full_name, info->old_base)); @@ -902,7 +914,7 @@ store_folder_renamed(CamelObject *o, void *event_data, void *data) filter_rule_set_name(rule, info->new->full_name); g_signal_connect(rule, "changed", G_CALLBACK(rule_changed), folder); - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (shell_backend); user = g_build_filename (data_dir, "vfolders.xml", NULL); rule_context_save((RuleContext *)context, user); g_free(user); @@ -920,12 +932,15 @@ vfolder_load_storage(void) /* lock for loading storage, it is safe to call it more than once */ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; + EShellBackend *shell_backend; const gchar *data_dir; char *user, *storeuri; FilterRule *rule; char *xmlfile; GConfClient *gconf; + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + pthread_mutex_lock (&lock); if (vfolder_hash) { @@ -939,7 +954,7 @@ vfolder_load_storage(void) pthread_mutex_unlock (&lock); /* first, create the vfolder store, and set it up */ - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (shell_backend); storeuri = g_strdup_printf("vfolder:%s/vfolder", data_dir); vfolder_store = camel_session_get_store(session, storeuri, NULL); if (vfolder_store == NULL) { @@ -972,8 +987,8 @@ vfolder_load_storage(void) g_signal_connect(context, "rule_removed", G_CALLBACK(context_rule_removed), context); /* load store to mail component */ - e_mail_shell_module_load_store_by_uri ( - mail_shell_module, storeuri, _("Search Folders")); + e_mail_shell_backend_load_store_by_uri ( + global_mail_shell_backend, storeuri, _("Search Folders")); /* and setup the rules we have */ rule = NULL; @@ -996,11 +1011,14 @@ vfolder_load_storage(void) void vfolder_revert(void) { + EShellBackend *shell_backend; const gchar *data_dir; char *user; + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + d(printf("vfolder_revert\n")); - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (shell_backend); user = g_build_filename (data_dir, "vfolders.xml", NULL); rule_context_revert((RuleContext *)context, user); g_free(user); @@ -1009,7 +1027,7 @@ vfolder_revert(void) void vfolder_edit (EShellView *shell_view) { - EShellModule *shell_module; + EShellBackend *shell_backend; EShellWindow *shell_window; GtkWidget *dialog; const gchar *data_dir; @@ -1017,10 +1035,10 @@ vfolder_edit (EShellView *shell_view) g_return_if_fail (E_IS_SHELL_VIEW (shell_view)); - shell_module = e_shell_view_get_shell_module (shell_view); + shell_backend = e_shell_view_get_shell_backend (shell_view); shell_window = e_shell_view_get_shell_window (shell_view); - data_dir = e_shell_module_get_data_dir (shell_module); + data_dir = e_shell_backend_get_data_dir (shell_backend); filename = g_build_filename (data_dir, "vfolders.xml", NULL); /* ensures vfolder is running */ @@ -1047,6 +1065,10 @@ vfolder_edit (EShellView *shell_view) static void edit_rule_response(GtkWidget *w, int button, void *data) { + EShellBackend *shell_backend; + + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + if (button == GTK_RESPONSE_OK) { const gchar *data_dir; char *user; @@ -1054,7 +1076,7 @@ edit_rule_response(GtkWidget *w, int button, void *data) FilterRule *orig = g_object_get_data (G_OBJECT (w), "orig"); filter_rule_copy(orig, rule); - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (shell_backend); user = g_build_filename (data_dir, "vfolders.xml", NULL); rule_context_save((RuleContext *)context, user); g_free(user); @@ -1111,6 +1133,10 @@ vfolder_edit_rule(const char *uri) static void new_rule_clicked(GtkWidget *w, int button, void *data) { + EShellBackend *shell_backend; + + shell_backend = E_SHELL_BACKEND (global_mail_shell_backend); + if (button == GTK_RESPONSE_OK) { const gchar *data_dir; char *user; @@ -1129,7 +1155,7 @@ new_rule_clicked(GtkWidget *w, int button, void *data) g_object_ref(rule); rule_context_add_rule((RuleContext *)context, rule); - data_dir = e_shell_module_get_data_dir (mail_shell_module); + data_dir = e_shell_backend_get_data_dir (shell_backend); user = g_build_filename (data_dir, "vfolders.xml", NULL); rule_context_save((RuleContext *)context, user); g_free(user); diff --git a/mail/message-list.c b/mail/message-list.c index 39784acfcc..d425ae0494 100644 --- a/mail/message-list.c +++ b/mail/message-list.c @@ -113,7 +113,7 @@ struct _MLSelection { struct _MessageListPrivate { GtkWidget *invisible; /* 4 selection */ - EShellModule *shell_module; + EShellBackend *shell_backend; struct _MLSelection clipboard; gboolean destroyed; @@ -1242,7 +1242,7 @@ get_all_labels (MessageList *message_list, gboolean get_tags) { EShell *shell; - EShellModule *shell_module; + EShellBackend *shell_backend; EShellSettings *shell_settings; EMailLabelListStore *store; GtkTreeIter iter; @@ -1253,8 +1253,8 @@ get_all_labels (MessageList *message_list, int count = 0; const CamelFlag *flag; - shell_module = message_list_get_shell_module (message_list); - shell = e_shell_module_get_shell (shell_module); + shell_backend = message_list_get_shell_backend (message_list); + shell = e_shell_backend_get_shell (shell_backend); shell_settings = e_shell_get_shell_settings (shell); property_name = "mail-label-list-store"; @@ -1318,7 +1318,7 @@ get_label_color (MessageList *message_list, const gchar *tag) { EShell *shell; - EShellModule *shell_module; + EShellBackend *shell_backend; EShellSettings *shell_settings; EMailLabelListStore *store; GtkTreeIter iter; @@ -1330,8 +1330,8 @@ get_label_color (MessageList *message_list, /* FIXME get_all_labels() should return an array of tree iterators, * not strings. Now we just have to lookup the tag again. */ - shell_module = message_list_get_shell_module (message_list); - shell = e_shell_module_get_shell (shell_module); + shell_backend = message_list_get_shell_backend (message_list); + shell = e_shell_backend_get_shell (shell_backend); shell_settings = e_shell_get_shell_settings (shell); property_name = "mail-label-list-store"; @@ -2327,12 +2327,12 @@ on_model_row_changed (ETableModel *model, int row, MessageList *ml) */ static void -message_list_set_shell_module (MessageList *message_list, - EShellModule *shell_module) +message_list_set_shell_backend (MessageList *message_list, + EShellBackend *shell_backend) { - g_return_if_fail (message_list->priv->shell_module == NULL); + g_return_if_fail (message_list->priv->shell_backend == NULL); - message_list->priv->shell_module = g_object_ref (shell_module); + message_list->priv->shell_backend = g_object_ref (shell_backend); } static void @@ -2457,7 +2457,7 @@ message_list_set_property (GObject *object, { switch (property_id) { case PROP_SHELL_MODULE: - message_list_set_shell_module ( + message_list_set_shell_backend ( MESSAGE_LIST (object), g_value_get_object (value)); return; @@ -2475,7 +2475,7 @@ message_list_get_property (GObject *object, switch (property_id) { case PROP_SHELL_MODULE: g_value_set_object ( - value, message_list_get_shell_module ( + value, message_list_get_shell_backend ( MESSAGE_LIST (object))); return; } @@ -2490,9 +2490,9 @@ message_list_dispose (GObject *object) priv = MESSAGE_LIST_GET_PRIVATE (object); - if (priv->shell_module != NULL) { - g_object_unref (priv->shell_module); - priv->shell_module = NULL; + if (priv->shell_backend != NULL) { + g_object_unref (priv->shell_backend); + priv->shell_backend = NULL; } /* Chain up to parent's dispose() method. */ @@ -2567,10 +2567,10 @@ message_list_class_init (MessageListClass *class) object_class, PROP_SHELL_MODULE, g_param_spec_object ( - "shell-module", - _("Shell Module"), - _("The mail shell module"), - E_TYPE_SHELL_MODULE, + "shell-backend", + _("Shell Backend"), + _("The mail shell backend"), + E_TYPE_SHELL_BACKEND, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); @@ -2725,28 +2725,28 @@ message_list_construct (MessageList *message_list) * Returns a new message-list widget. **/ GtkWidget * -message_list_new (EShellModule *shell_module) +message_list_new (EShellBackend *shell_backend) { MessageList *message_list; - g_return_val_if_fail (E_IS_SHELL_MODULE (shell_module), NULL); + g_return_val_if_fail (E_IS_SHELL_BACKEND (shell_backend), NULL); message_list = MESSAGE_LIST (g_object_new(message_list_get_type (), "hadjustment", NULL, "vadjustment", NULL, - "shell-module", shell_module, + "shell-backend", shell_backend, NULL)); message_list_construct (message_list); return GTK_WIDGET (message_list); } -EShellModule * -message_list_get_shell_module (MessageList *message_list) +EShellBackend * +message_list_get_shell_backend (MessageList *message_list) { g_return_val_if_fail (IS_MESSAGE_LIST (message_list), NULL); - return message_list->priv->shell_module; + return message_list->priv->shell_backend; } static void -- cgit v1.2.3