From 5b8340563c271fb684a88c6e5bb6dd3bfb629058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Vr=C3=A1til?= Date: Wed, 6 Jun 2012 15:27:19 +0200 Subject: Mail formatter rewrite All mail-parsing and formatting code has been moved to em-format. Parsing is handeled by EMailParser class, formatting by EMailFormatter. Both classes have registry which hold extensions - simple classes that do actual parsing and formatting. Each supported mime-type has it's own parser and formatter extension class. --- modules/mail/e-mail-config-format-html.c | 4 +- modules/mail/e-mail-shell-backend.c | 73 +++++++++++++++----------------- modules/mail/e-mail-shell-content.h | 1 - modules/mail/e-mail-shell-view-actions.c | 2 +- modules/mail/em-mailer-prefs.c | 1 - 5 files changed, 36 insertions(+), 45 deletions(-) (limited to 'modules') diff --git a/modules/mail/e-mail-config-format-html.c b/modules/mail/e-mail-config-format-html.c index 527f720159..cbedecf914 100644 --- a/modules/mail/e-mail-config-format-html.c +++ b/modules/mail/e-mail-config-format-html.c @@ -26,7 +26,7 @@ #include #include -#include +#include static gpointer parent_class; @@ -95,7 +95,7 @@ mail_config_format_html_class_init (EExtensionClass *class) object_class = G_OBJECT_CLASS (class); object_class->constructed = mail_config_format_html_constructed; - class->extensible_type = EM_TYPE_FORMAT_HTML; + class->extensible_type = E_TYPE_MAIL_FORMATTER; } void diff --git a/modules/mail/e-mail-shell-backend.c b/modules/mail/e-mail-shell-backend.c index f5bb100c39..3aecfd91d8 100644 --- a/modules/mail/e-mail-shell-backend.c +++ b/modules/mail/e-mail-shell-backend.c @@ -53,14 +53,16 @@ #include #include #include -#include -#include #include #include #include #include #include +#include +#include +#include + #include "e-mail-shell-settings.h" #include "e-mail-shell-sidebar.h" #include "e-mail-shell-view.h" @@ -447,14 +449,6 @@ mail_shell_backend_constructed (GObject *object) /* Chain up to parent's constructed() method. */ G_OBJECT_CLASS (e_mail_shell_backend_parent_class)->constructed (object); - /* Register format types for 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 ()); - - /* Register plugin hook types. */ - em_format_hook_get_type (); - mail_shell_backend_init_importers (); g_signal_connect ( @@ -851,13 +845,35 @@ message_parsed_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - EMFormatHTML *formatter = EM_FORMAT_HTML (source_object); + EMailParser *parser = E_MAIL_PARSER (source_object); + EMailPartList *parts_list; GObject *preview = user_data; EMailDisplay *display; + SoupSession *soup_session; + GHashTable *mails; + gchar *mail_uri; display = g_object_get_data (preview, "mbox-imp-display"); - e_mail_display_set_formatter (display, formatter); - e_mail_display_load (display, EM_FORMAT (formatter)->uri_base); + + parts_list = e_mail_parser_parse_finish (parser, res, NULL); + + soup_session = webkit_get_default_session (); + mails = g_object_get_data (G_OBJECT (soup_session), "mails"); + if (!mails) { + mails = g_hash_table_new_full (g_str_hash, g_str_equal, + (GDestroyNotify) g_free, NULL); + g_object_set_data ( + G_OBJECT (soup_session), "mails", mails); + } + mail_uri = e_mail_part_build_uri ( + parts_list->folder, parts_list->message_uid, NULL, NULL); + + g_hash_table_insert (mails, mail_uri, parts_list); + + e_mail_display_set_parts_list (display, parts_list); + e_mail_display_load (display, NULL); + + g_object_unref (parts_list); } /* utility functions for mbox importer */ @@ -883,12 +899,9 @@ mbox_fill_preview_cb (GObject *preview, { EShell *shell; EMailDisplay *display; - EMFormat *formatter; - GHashTable *formatters; - SoupSession *soup_session; + EMailParser *parser; EMailSession *mail_session; ESourceRegistry *registry; - gchar *mail_uri; g_return_if_fail (preview != NULL); g_return_if_fail (msg != NULL); @@ -896,33 +909,13 @@ mbox_fill_preview_cb (GObject *preview, display = g_object_get_data (preview, "mbox-imp-display"); g_return_if_fail (display != NULL); - soup_session = webkit_get_default_session (); - formatters = g_object_get_data (G_OBJECT (soup_session), "formatters"); - if (!formatters) { - formatters = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, NULL); - g_object_set_data ( - G_OBJECT (soup_session), "formatters", formatters); - } - - mail_uri = em_format_build_mail_uri (NULL, msg->message_id, NULL, NULL); - shell = e_shell_get_default (); registry = e_shell_get_registry (shell); mail_session = e_mail_session_new (registry); - formatter = EM_FORMAT ( - em_format_html_display_new ( - CAMEL_SESSION (mail_session))); - formatter->message_uid = g_strdup (msg->message_id); - formatter->uri_base = g_strdup (mail_uri); - - /* Don't free the mail_uri!! */ - g_hash_table_insert (formatters, mail_uri, formatter); - - em_format_parse_async ( - formatter, msg, NULL, NULL, - message_parsed_cb, preview); + parser = e_mail_parser_new (CAMEL_SESSION (mail_session)); + e_mail_parser_parse (parser, NULL, msg->message_id, msg, + message_parsed_cb, NULL, preview); g_object_unref (mail_session); } diff --git a/modules/mail/e-mail-shell-content.h b/modules/mail/e-mail-shell-content.h index b3eecbef63..ff8fb94bf8 100644 --- a/modules/mail/e-mail-shell-content.h +++ b/modules/mail/e-mail-shell-content.h @@ -26,7 +26,6 @@ #include #include #include -#include /* Standard GObject macros */ #define E_TYPE_MAIL_SHELL_CONTENT \ diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c index afe347cae6..3468339200 100644 --- a/modules/mail/e-mail-shell-view-actions.c +++ b/modules/mail/e-mail-shell-view-actions.c @@ -145,7 +145,7 @@ action_mail_account_properties_cb (GtkAction *action, registry = e_shell_get_registry (shell); source = e_source_registry_ref_source (registry, uid); g_return_if_fail (source != NULL); - + e_mail_shell_backend_edit_account ( E_MAIL_SHELL_BACKEND (shell_backend), GTK_WINDOW (shell_window), source); diff --git a/modules/mail/em-mailer-prefs.c b/modules/mail/em-mailer-prefs.c index 00334d7559..9262ff8bb0 100644 --- a/modules/mail/em-mailer-prefs.c +++ b/modules/mail/em-mailer-prefs.c @@ -28,7 +28,6 @@ #include #include "em-mailer-prefs.h" -#include "em-format/em-format.h" #include #include -- cgit v1.2.3