diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2010-10-07 11:38:52 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2010-10-13 01:58:59 +0800 |
commit | a06e4484b8df804124b5bcf88d94dec5acfba270 (patch) | |
tree | 4fa42793d7dc461f2b3767296d76592182c48222 /mail/importers | |
parent | 5e0758bb6934a7859b1d8a247c8fb21c156772cf (diff) | |
download | gsoc2013-evolution-a06e4484b8df804124b5bcf88d94dec5acfba270.tar.gz gsoc2013-evolution-a06e4484b8df804124b5bcf88d94dec5acfba270.tar.zst gsoc2013-evolution-a06e4484b8df804124b5bcf88d94dec5acfba270.zip |
Give MailSession a permanent home.
Global variables in shared libraries are a bad idea. EMailBackend now
owns the MailSession instance, which is actually now EMailSession.
Move the blocking utility functions in mail-tools.c to e-mail-session.c
and add asynchronous variants. Same approach as Camel.
Replace EMailReader.get_shell_backend() with EMailReader.get_backend(),
which returns an EMailBackend. Easier access to the EMailSession.
Diffstat (limited to 'mail/importers')
-rw-r--r-- | mail/importers/elm-importer.c | 14 | ||||
-rw-r--r-- | mail/importers/evolution-mbox-importer.c | 28 | ||||
-rw-r--r-- | mail/importers/mail-importer.c | 37 | ||||
-rw-r--r-- | mail/importers/mail-importer.h | 20 | ||||
-rw-r--r-- | mail/importers/pine-importer.c | 15 |
5 files changed, 98 insertions, 16 deletions
diff --git a/mail/importers/elm-importer.c b/mail/importers/elm-importer.c index 0164378942..18548fc21b 100644 --- a/mail/importers/elm-importer.c +++ b/mail/importers/elm-importer.c @@ -41,7 +41,9 @@ #include "mail-importer.h" #include "mail/mail-mt.h" +#include "mail/e-mail-backend.h" #include "e-util/e-import.h" +#include "shell/e-shell.h" #define d(x) @@ -184,9 +186,19 @@ static MailImporterSpecial elm_special_folders[] = { static void elm_import_exec (struct _elm_import_msg *m) { + EShell *shell; + EShellBackend *shell_backend; + EMailSession *session; const gchar *maildir; gchar *elmdir; + /* XXX Dig up the EMailSession from the default EShell. + * Since the EImport framework doesn't allow for user + * data, I don't see how else to get to it. */ + shell = e_shell_get_default (); + shell_backend = e_shell_get_backend_by_name (shell, "mail"); + session = e_mail_backend_get_session (E_MAIL_BACKEND (shell_backend)); + maildir = elm_get_rc(m->import, "maildir"); if (maildir == NULL) maildir = "Mail"; @@ -197,7 +209,7 @@ elm_import_exec (struct _elm_import_msg *m) elmdir = g_strdup (maildir); mail_importer_import_folders_sync ( - elmdir, elm_special_folders, 0, m->status); + session, elmdir, elm_special_folders, 0, m->status); g_free (elmdir); } diff --git a/mail/importers/evolution-mbox-importer.c b/mail/importers/evolution-mbox-importer.c index 460777073a..aba980188e 100644 --- a/mail/importers/evolution-mbox-importer.c +++ b/mail/importers/evolution-mbox-importer.c @@ -44,6 +44,7 @@ #include "shell/e-shell-view.h" #include "shell/e-shell-sidebar.h" +#include "mail/e-mail-backend.h" #include "mail/e-mail-local.h" #include "mail/e-mail-store.h" #include "mail/em-folder-selection-button.h" @@ -79,13 +80,23 @@ folder_selected (EMFolderSelectionButton *button, EImportTargetURI *target) static GtkWidget * mbox_getwidget (EImport *ei, EImportTarget *target, EImportImporter *im) { + EShell *shell; + EShellBackend *shell_backend; + EMailSession *session; GtkWindow *window; GtkWidget *hbox, *w; GtkLabel *label; gchar *select_uri = NULL; + /* XXX Dig up the EMailSession from the default EShell. + * Since the EImport framework doesn't allow for user + * data, I don't see how else to get to it. */ + shell = e_shell_get_default (); + shell_backend = e_shell_get_backend_by_name (shell, "mail"); + session = e_mail_backend_get_session (E_MAIL_BACKEND (shell_backend)); + /* preselect the folder selected in a mail view */ - window = e_shell_get_active_window (e_shell_get_default ()); + window = e_shell_get_active_window (shell); if (E_IS_SHELL_WINDOW (window)) { EShellWindow *shell_window; const gchar *view; @@ -119,7 +130,8 @@ mbox_getwidget (EImport *ei, EImportTarget *target, EImportImporter *im) label = GTK_LABEL (w); w = em_folder_selection_button_new ( - _("Select folder"), _("Select folder to import into")); + session, _("Select folder"), + _("Select folder to import into")); gtk_label_set_mnemonic_widget (label, w); em_folder_selection_button_set_selection ((EMFolderSelectionButton *)w, select_uri); folder_selected (EM_FOLDER_SELECTION_BUTTON (w), (EImportTargetURI *)target); @@ -215,9 +227,19 @@ mbox_import_done (gpointer data, GError **error) static void mbox_import (EImport *ei, EImportTarget *target, EImportImporter *im) { + EShell *shell; + EShellBackend *shell_backend; + EMailSession *session; MboxImporter *importer; gchar *filename; + /* XXX Dig up the EMailSession from the default EShell. + * Since the EImport framework doesn't allow for user + * data, I don't see how else to get to it. */ + shell = e_shell_get_default (); + shell_backend = e_shell_get_backend_by_name (shell, "mail"); + session = e_mail_backend_get_session (E_MAIL_BACKEND (shell_backend)); + /* TODO: do we validate target? */ importer = g_malloc0 (sizeof (*importer)); @@ -234,7 +256,7 @@ mbox_import (EImport *ei, EImportTarget *target, EImportImporter *im) filename = g_filename_from_uri (((EImportTargetURI *)target)->uri_src, NULL, NULL); mail_importer_import_mbox ( - filename, ((EImportTargetURI *)target)->uri_dest, + session, filename, ((EImportTargetURI *)target)->uri_dest, importer->cancellable, mbox_import_done, importer); g_free (filename); } diff --git a/mail/importers/mail-importer.c b/mail/importers/mail-importer.c index 08d0141f84..ff987f40c1 100644 --- a/mail/importers/mail-importer.c +++ b/mail/importers/mail-importer.c @@ -43,13 +43,14 @@ #include "mail-mt.h" #include "mail-tools.h" #include "e-mail-local.h" -#include "mail-session.h" +#include "e-mail-session.h" #include "mail-importer.h" struct _import_mbox_msg { MailMsg base; + EMailSession *session; gchar *path; gchar *uri; GCancellable *cancellable; @@ -122,8 +123,8 @@ import_mbox_exec (struct _import_mbox_msg *m) if (m->uri == NULL || m->uri[0] == 0) folder = e_mail_local_get_folder (E_MAIL_FOLDER_INBOX); else - folder = mail_tool_uri_to_folder ( - m->uri, CAMEL_STORE_FOLDER_CREATE, + folder = e_mail_session_uri_to_folder_sync ( + m->session, m->uri, CAMEL_STORE_FOLDER_CREATE, m->base.cancellable, &m->base.error); if (folder == NULL) @@ -212,6 +213,7 @@ import_mbox_done (struct _import_mbox_msg *m) static void import_mbox_free (struct _import_mbox_msg *m) { + g_object_unref (m->session); if (m->cancellable) g_object_unref (m->cancellable); g_free (m->uri); @@ -227,12 +229,18 @@ static MailMsgInfo import_mbox_info = { }; gint -mail_importer_import_mbox (const gchar *path, const gchar *folderuri, GCancellable *cancellable, void (*done)(gpointer data, GError **), gpointer data) +mail_importer_import_mbox (EMailSession *session, + const gchar *path, + const gchar *folderuri, + GCancellable *cancellable, + void (*done)(gpointer data, GError **), + gpointer data) { struct _import_mbox_msg *m; gint id; m = mail_msg_new (&import_mbox_info); + m->session = g_object_ref (session); m->path = g_strdup (path); m->uri = g_strdup (folderuri); m->done = done; @@ -247,11 +255,15 @@ mail_importer_import_mbox (const gchar *path, const gchar *folderuri, GCancellab } void -mail_importer_import_mbox_sync (const gchar *path, const gchar *folderuri, GCancellable *cancellable) +mail_importer_import_mbox_sync (EMailSession *session, + const gchar *path, + const gchar *folderuri, + GCancellable *cancellable) { struct _import_mbox_msg *m; m = mail_msg_new (&import_mbox_info); + m->session = g_object_ref (session); m->path = g_strdup (path); m->uri = g_strdup (folderuri); if (cancellable) @@ -264,13 +276,16 @@ mail_importer_import_mbox_sync (const gchar *path, const gchar *folderuri, GCanc struct _import_folders_data { MailImporterSpecial *special_folders; + EMailSession *session; GCancellable *cancellable; guint elmfmt:1; }; static void -import_folders_rec (struct _import_folders_data *m, const gchar *filepath, const gchar *folderparent) +import_folders_rec (struct _import_folders_data *m, + const gchar *filepath, + const gchar *folderparent) { GDir *dir; const gchar *d; @@ -319,7 +334,8 @@ import_folders_rec (struct _import_folders_data *m, const gchar *filepath, const } printf("importing to uri %s\n", uri); - mail_importer_import_mbox_sync (filefull, uri, m->cancellable); + mail_importer_import_mbox_sync ( + m->session, filefull, uri, m->cancellable); g_free (uri); /* This little gem re-uses the stat buffer and filefull to automagically scan mozilla-format folders */ @@ -363,12 +379,17 @@ import_folders_rec (struct _import_folders_data *m, const gchar *filepath, const * standard unix directories. **/ void -mail_importer_import_folders_sync (const gchar *filepath, MailImporterSpecial special_folders[], gint flags, GCancellable *cancellable) +mail_importer_import_folders_sync (EMailSession *session, + const gchar *filepath, + MailImporterSpecial special_folders[], + gint flags, + GCancellable *cancellable) { struct _import_folders_data m; m.special_folders = special_folders; m.elmfmt = (flags & MAIL_IMPORTER_MOZFMT) == 0; + m.session = g_object_ref (session); m.cancellable = cancellable; import_folders_rec (&m, filepath, NULL); diff --git a/mail/importers/mail-importer.h b/mail/importers/mail-importer.h index 12caadaeac..93d1897877 100644 --- a/mail/importers/mail-importer.h +++ b/mail/importers/mail-importer.h @@ -26,6 +26,7 @@ #include <e-util/e-import.h> #include <camel/camel.h> +#include <mail/e-mail-session.h> EImportImporter *mbox_importer_peek (void); @@ -46,8 +47,16 @@ EImportImporter *pine_importer_peek (void); #define MSG_FLAG_MARKED 0x0004 #define MSG_FLAG_EXPUNGED 0x0008 -gint mail_importer_import_mbox (const gchar *path, const gchar *folderuri, GCancellable *cancellable, void (*done)(gpointer data, GError **), gpointer data); -void mail_importer_import_mbox_sync (const gchar *path, const gchar *folderuri, GCancellable *cancellable); +gint mail_importer_import_mbox (EMailSession *session, + const gchar *path, + const gchar *folderuri, + GCancellable *cancellable, + void (*done)(gpointer data, GError **), + gpointer data); +void mail_importer_import_mbox_sync (EMailSession *session, + const gchar *path, + const gchar *folderuri, + GCancellable *cancellable); struct _MailImporterSpecial { const gchar *orig, *new; @@ -58,6 +67,11 @@ typedef struct _MailImporterSpecial MailImporterSpecial; #define MAIL_IMPORTER_MOZFMT (1<<0) /* api in flux */ -void mail_importer_import_folders_sync (const gchar *filepath, MailImporterSpecial special_folders[], gint flags, GCancellable *cancellable); +void mail_importer_import_folders_sync + (EMailSession *session, + const gchar *filepath, + MailImporterSpecial special_folders[], + gint flags, + GCancellable *cancellable); #endif diff --git a/mail/importers/pine-importer.c b/mail/importers/pine-importer.c index ad9b7d331a..26a37b853e 100644 --- a/mail/importers/pine-importer.c +++ b/mail/importers/pine-importer.c @@ -44,7 +44,9 @@ #include "mail-importer.h" #include "mail/mail-mt.h" +#include "mail/e-mail-backend.h" #include "e-util/e-import.h" +#include "shell/e-shell.h" #define d(x) @@ -230,6 +232,17 @@ static MailImporterSpecial pine_special_folders[] = { static void pine_import_exec (struct _pine_import_msg *m) { + EShell *shell; + EShellBackend *shell_backend; + EMailSession *session; + + /* XXX Dig up the EMailSession from the default EShell. + * Since the EImport framework doesn't allow for user + * data, I don't see how else to get to it. */ + shell = e_shell_get_default (); + shell_backend = e_shell_get_backend_by_name (shell, "mail"); + session = e_mail_backend_get_session (E_MAIL_BACKEND (shell_backend)); + if (GPOINTER_TO_INT(g_datalist_get_data(&m->target->data, "pine-do-addr"))) import_contacts (); @@ -238,7 +251,7 @@ pine_import_exec (struct _pine_import_msg *m) path = g_build_filename(g_get_home_dir(), "mail", NULL); mail_importer_import_folders_sync ( - path, pine_special_folders, 0, m->cancellable); + session, path, pine_special_folders, 0, m->cancellable); g_free (path); } } |