Commit 722a27e8 authored by Milan Crha's avatar Milan Crha
Browse files

Bug #692005 - Changing character encoding doesn't work

parent 590b4711
...@@ -183,6 +183,7 @@ emfe_message_rfc822_format (EMailFormatterExtension *extension, ...@@ -183,6 +183,7 @@ emfe_message_rfc822_format (EMailFormatterExtension *extension,
EMailPart *p; EMailPart *p;
CamelFolder *folder; CamelFolder *folder;
const gchar *message_uid; const gchar *message_uid;
const gchar *default_charset, *charset;
gchar *str; gchar *str;
gchar *uri; gchar *uri;
...@@ -192,12 +193,21 @@ emfe_message_rfc822_format (EMailFormatterExtension *extension, ...@@ -192,12 +193,21 @@ emfe_message_rfc822_format (EMailFormatterExtension *extension,
folder = e_mail_part_list_get_folder (context->part_list); folder = e_mail_part_list_get_folder (context->part_list);
message_uid = e_mail_part_list_get_message_uid (context->part_list); message_uid = e_mail_part_list_get_message_uid (context->part_list);
default_charset = e_mail_formatter_get_default_charset (formatter);
charset = e_mail_formatter_get_charset (formatter);
if (!default_charset)
default_charset = "";
if (!charset)
charset = "";
uri = e_mail_part_build_uri ( uri = e_mail_part_build_uri (
folder, message_uid, folder, message_uid,
"part_id", G_TYPE_STRING, p->id, "part_id", G_TYPE_STRING, p->id,
"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW, "mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
"headers_collapsable", G_TYPE_INT, 0, "headers_collapsable", G_TYPE_INT, 0,
"formatter_default_charset", G_TYPE_STRING, default_charset,
"formatter_charset", G_TYPE_STRING, charset,
NULL); NULL);
str = g_strdup_printf ( str = g_strdup_printf (
......
...@@ -299,15 +299,25 @@ emfe_text_html_format (EMailFormatterExtension *extension, ...@@ -299,15 +299,25 @@ emfe_text_html_format (EMailFormatterExtension *extension,
} else { } else {
CamelFolder *folder; CamelFolder *folder;
const gchar *message_uid; const gchar *message_uid;
const gchar *default_charset, *charset;
gchar *uri, *str; gchar *uri, *str;
folder = e_mail_part_list_get_folder (context->part_list); folder = e_mail_part_list_get_folder (context->part_list);
message_uid = e_mail_part_list_get_message_uid (context->part_list); message_uid = e_mail_part_list_get_message_uid (context->part_list);
default_charset = e_mail_formatter_get_default_charset (formatter);
charset = e_mail_formatter_get_charset (formatter);
if (!default_charset)
default_charset = "";
if (!charset)
charset = "";
uri = e_mail_part_build_uri ( uri = e_mail_part_build_uri (
folder, message_uid, folder, message_uid,
"part_id", G_TYPE_STRING, part->id, "part_id", G_TYPE_STRING, part->id,
"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW, "mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
"formatter_default_charset", G_TYPE_STRING, default_charset,
"formatter_charset", G_TYPE_STRING, charset,
NULL); NULL);
str = g_strdup_printf ( str = g_strdup_printf (
......
...@@ -135,14 +135,24 @@ emfe_text_plain_format (EMailFormatterExtension *extension, ...@@ -135,14 +135,24 @@ emfe_text_plain_format (EMailFormatterExtension *extension,
CamelFolder *folder; CamelFolder *folder;
const gchar *message_uid; const gchar *message_uid;
gchar *uri, *str; gchar *uri, *str;
const gchar *default_charset, *charset;
folder = e_mail_part_list_get_folder (context->part_list); folder = e_mail_part_list_get_folder (context->part_list);
message_uid = e_mail_part_list_get_message_uid (context->part_list); message_uid = e_mail_part_list_get_message_uid (context->part_list);
default_charset = e_mail_formatter_get_default_charset (formatter);
charset = e_mail_formatter_get_charset (formatter);
if (!default_charset)
default_charset = "";
if (!charset)
charset = "";
uri = e_mail_part_build_uri ( uri = e_mail_part_build_uri (
folder, message_uid, folder, message_uid,
"part_id", G_TYPE_STRING, part->id, "part_id", G_TYPE_STRING, part->id,
"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW, "mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
"formatter_default_charset", G_TYPE_STRING, default_charset,
"formatter_charset", G_TYPE_STRING, charset,
NULL); NULL);
str = g_strdup_printf ( str = g_strdup_printf (
......
...@@ -76,6 +76,7 @@ enum { ...@@ -76,6 +76,7 @@ enum {
PROP_PART_LIST, PROP_PART_LIST,
PROP_HEADERS_COLLAPSABLE, PROP_HEADERS_COLLAPSABLE,
PROP_HEADERS_COLLAPSED, PROP_HEADERS_COLLAPSED,
PROP_FORMATTER
}; };
static CamelDataCache *emd_global_http_cache = NULL; static CamelDataCache *emd_global_http_cache = NULL;
...@@ -1282,6 +1283,11 @@ mail_display_get_property (GObject *object, ...@@ -1282,6 +1283,11 @@ mail_display_get_property (GObject *object,
GParamSpec *pspec) GParamSpec *pspec)
{ {
switch (property_id) { switch (property_id) {
case PROP_FORMATTER:
g_value_set_object (
value, e_mail_display_get_formatter (
E_MAIL_DISPLAY (object)));
return;
case PROP_PART_LIST: case PROP_PART_LIST:
g_value_set_pointer ( g_value_set_pointer (
value, e_mail_display_get_parts_list ( value, e_mail_display_get_parts_list (
...@@ -1486,6 +1492,16 @@ e_mail_display_class_init (EMailDisplayClass *class) ...@@ -1486,6 +1492,16 @@ e_mail_display_class_init (EMailDisplayClass *class)
web_view_class = E_WEB_VIEW_CLASS (class); web_view_class = E_WEB_VIEW_CLASS (class);
web_view_class->set_fonts = mail_display_set_fonts; web_view_class->set_fonts = mail_display_set_fonts;
g_object_class_install_property (
object_class,
PROP_FORMATTER,
g_param_spec_pointer (
"formatter",
"Mail Formatter",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property ( g_object_class_install_property (
object_class, object_class,
PROP_PART_LIST, PROP_PART_LIST,
...@@ -1703,6 +1719,14 @@ e_mail_display_set_mode (EMailDisplay *display, ...@@ -1703,6 +1719,14 @@ e_mail_display_set_mode (EMailDisplay *display,
g_object_notify (G_OBJECT (display), "mode"); g_object_notify (G_OBJECT (display), "mode");
} }
EMailFormatter *
e_mail_display_get_formatter (EMailDisplay *display)
{
g_return_val_if_fail (E_IS_MAIL_DISPLAY (display), NULL);
return display->priv->formatter;
}
EMailPartList * EMailPartList *
e_mail_display_get_parts_list (EMailDisplay *display) e_mail_display_get_parts_list (EMailDisplay *display)
{ {
...@@ -1788,6 +1812,7 @@ e_mail_display_load (EMailDisplay *display, ...@@ -1788,6 +1812,7 @@ e_mail_display_load (EMailDisplay *display,
EMailPartList *part_list; EMailPartList *part_list;
CamelFolder *folder; CamelFolder *folder;
const gchar *message_uid; const gchar *message_uid;
const gchar *default_charset, *charset;
gchar *uri; gchar *uri;
g_return_if_fail (E_IS_MAIL_DISPLAY (display)); g_return_if_fail (E_IS_MAIL_DISPLAY (display));
...@@ -1802,14 +1827,21 @@ e_mail_display_load (EMailDisplay *display, ...@@ -1802,14 +1827,21 @@ e_mail_display_load (EMailDisplay *display,
folder = e_mail_part_list_get_folder (part_list); folder = e_mail_part_list_get_folder (part_list);
message_uid = e_mail_part_list_get_message_uid (part_list); message_uid = e_mail_part_list_get_message_uid (part_list);
default_charset = e_mail_formatter_get_default_charset (display->priv->formatter);
charset = e_mail_formatter_get_charset (display->priv->formatter);
if (!default_charset)
default_charset = "";
if (!charset)
charset = "";
uri = e_mail_part_build_uri ( uri = e_mail_part_build_uri (
folder, message_uid, folder, message_uid,
"mode", G_TYPE_INT, display->priv->mode, "mode", G_TYPE_INT, display->priv->mode,
"headers_collapsable", G_TYPE_BOOLEAN, "headers_collapsable", G_TYPE_BOOLEAN, display->priv->headers_collapsable,
display->priv->headers_collapsable, "headers_collapsed", G_TYPE_BOOLEAN, display->priv->headers_collapsed,
"headers_collapsed", G_TYPE_BOOLEAN, "formatter_default_charset", G_TYPE_STRING, default_charset,
display->priv->headers_collapsed, "formatter_charset", G_TYPE_STRING, charset,
NULL); NULL);
e_web_view_load_uri (E_WEB_VIEW (display), uri); e_web_view_load_uri (E_WEB_VIEW (display), uri);
...@@ -1825,6 +1857,7 @@ do_reload_display (EMailDisplay *display) ...@@ -1825,6 +1857,7 @@ do_reload_display (EMailDisplay *display)
GHashTable *table; GHashTable *table;
SoupURI *soup_uri; SoupURI *soup_uri;
gchar *mode, *collapsable, *collapsed; gchar *mode, *collapsable, *collapsed;
const gchar *default_charset, *charset;
web_view = E_WEB_VIEW (display); web_view = E_WEB_VIEW (display);
uri = (gchar *) e_web_view_get_uri (web_view); uri = (gchar *) e_web_view_get_uri (web_view);
...@@ -1844,6 +1877,13 @@ do_reload_display (EMailDisplay *display) ...@@ -1844,6 +1877,13 @@ do_reload_display (EMailDisplay *display)
mode = g_strdup_printf ("%d", display->priv->mode); mode = g_strdup_printf ("%d", display->priv->mode);
collapsable = g_strdup_printf ("%d", display->priv->headers_collapsable); collapsable = g_strdup_printf ("%d", display->priv->headers_collapsable);
collapsed = g_strdup_printf ("%d", display->priv->headers_collapsed); collapsed = g_strdup_printf ("%d", display->priv->headers_collapsed);
default_charset = e_mail_formatter_get_default_charset (display->priv->formatter);
charset = e_mail_formatter_get_charset (display->priv->formatter);
if (!default_charset)
default_charset = "";
if (!charset)
charset = "";
table = soup_form_decode (soup_uri->query); table = soup_form_decode (soup_uri->query);
g_hash_table_replace ( g_hash_table_replace (
...@@ -1852,6 +1892,10 @@ do_reload_display (EMailDisplay *display) ...@@ -1852,6 +1892,10 @@ do_reload_display (EMailDisplay *display)
table, g_strdup ("headers_collapsable"), collapsable); table, g_strdup ("headers_collapsable"), collapsable);
g_hash_table_replace ( g_hash_table_replace (
table, g_strdup ("headers_collapsed"), collapsed); table, g_strdup ("headers_collapsed"), collapsed);
g_hash_table_replace (
table, g_strdup ("formatter_default_charset"), g_strdup (default_charset));
g_hash_table_replace (
table, g_strdup ("formatter_charset"), g_strdup (charset));
query = soup_form_encode_hash (table); query = soup_form_encode_hash (table);
......
...@@ -67,6 +67,8 @@ void e_mail_display_set_mode (EMailDisplay *display, ...@@ -67,6 +67,8 @@ void e_mail_display_set_mode (EMailDisplay *display,
EMailFormatterMode mode); EMailFormatterMode mode);
EMailFormatterMode e_mail_display_get_mode (EMailDisplay *display); EMailFormatterMode e_mail_display_get_mode (EMailDisplay *display);
EMailFormatter * e_mail_display_get_formatter (EMailDisplay *display);
EMailPartList * e_mail_display_get_parts_list (EMailDisplay *display); EMailPartList * e_mail_display_get_parts_list (EMailDisplay *display);
void e_mail_display_set_parts_list (EMailDisplay *display, void e_mail_display_set_parts_list (EMailDisplay *display,
......
...@@ -198,25 +198,38 @@ emp_start_printing (GObject *object, ...@@ -198,25 +198,38 @@ emp_start_printing (GObject *object,
} }
static void static void
emp_run_print_operation (EMailPrinter *emp) emp_run_print_operation (EMailPrinter *emp,
EMailFormatter *formatter)
{ {
EMailPartList *part_list; EMailPartList *part_list;
CamelFolder *folder; CamelFolder *folder;
const gchar *message_uid; const gchar *message_uid;
const gchar *default_charset, *charset;
gchar *mail_uri; gchar *mail_uri;
part_list = emp->priv->parts_list; part_list = emp->priv->parts_list;
folder = e_mail_part_list_get_folder (part_list); folder = e_mail_part_list_get_folder (part_list);
message_uid = e_mail_part_list_get_message_uid (part_list); message_uid = e_mail_part_list_get_message_uid (part_list);
default_charset = formatter ? e_mail_formatter_get_default_charset (formatter) : NULL;
charset = formatter ? e_mail_formatter_get_charset (formatter) : NULL;
if (!default_charset)
default_charset = "";
if (!charset)
charset = "";
mail_uri = e_mail_part_build_uri ( mail_uri = e_mail_part_build_uri (
folder, message_uid, folder, message_uid,
"__evo-load-image", G_TYPE_BOOLEAN, TRUE, "__evo-load-image", G_TYPE_BOOLEAN, TRUE,
"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_PRINTING, "mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_PRINTING,
"formatter_default_charset", G_TYPE_STRING, default_charset,
"formatter_charset", G_TYPE_STRING, charset,
NULL); NULL);
/* Print_layout is a special EMPart created by EMFormatHTMLPrint */ /* Print_layout is a special EMPart created by EMFormatHTMLPrint */
if (emp->priv->webview == NULL) { if (emp->priv->webview == NULL) {
EMailFormatter *emp_formatter;
emp->priv->webview = g_object_new ( emp->priv->webview = g_object_new (
E_TYPE_MAIL_DISPLAY, E_TYPE_MAIL_DISPLAY,
"mode", E_MAIL_FORMATTER_MODE_PRINTING, NULL); "mode", E_MAIL_FORMATTER_MODE_PRINTING, NULL);
...@@ -224,6 +237,12 @@ emp_run_print_operation (EMailPrinter *emp) ...@@ -224,6 +237,12 @@ emp_run_print_operation (EMailPrinter *emp)
e_mail_display_set_force_load_images ( e_mail_display_set_force_load_images (
E_MAIL_DISPLAY (emp->priv->webview), TRUE); E_MAIL_DISPLAY (emp->priv->webview), TRUE);
emp_formatter = e_mail_display_get_formatter (E_MAIL_DISPLAY (emp->priv->webview));
if (default_charset && *default_charset)
e_mail_formatter_set_default_charset (emp_formatter, default_charset);
if (charset && *charset)
e_mail_formatter_set_charset (emp_formatter, charset);
g_object_ref_sink (emp->priv->webview); g_object_ref_sink (emp->priv->webview);
g_signal_connect ( g_signal_connect (
emp->priv->webview, "notify::load-status", emp->priv->webview, "notify::load-status",
...@@ -831,6 +850,7 @@ e_mail_printer_new (EMailPartList *source) ...@@ -831,6 +850,7 @@ e_mail_printer_new (EMailPartList *source)
void void
e_mail_printer_print (EMailPrinter *emp, e_mail_printer_print (EMailPrinter *emp,
GtkPrintOperationAction action, GtkPrintOperationAction action,
EMailFormatter *formatter,
GCancellable *cancellable) GCancellable *cancellable)
{ {
g_return_if_fail (E_IS_MAIL_PRINTER (emp)); g_return_if_fail (E_IS_MAIL_PRINTER (emp));
...@@ -857,7 +877,7 @@ e_mail_printer_print (EMailPrinter *emp, ...@@ -857,7 +877,7 @@ e_mail_printer_print (EMailPrinter *emp,
cancellable, "cancelled", cancellable, "cancelled",
G_CALLBACK (gtk_print_operation_cancel), emp->priv->operation); G_CALLBACK (gtk_print_operation_cancel), emp->priv->operation);
emp_run_print_operation (emp); emp_run_print_operation (emp, formatter);
} }
const gchar * const gchar *
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#define E_MAIL_PRINTER_H #define E_MAIL_PRINTER_H
#include <em-format/e-mail-part-list.h> #include <em-format/e-mail-part-list.h>
#include <em-format/e-mail-formatter.h>
/* Standard GObject macros */ /* Standard GObject macros */
#define E_TYPE_MAIL_PRINTER \ #define E_TYPE_MAIL_PRINTER \
...@@ -67,6 +68,7 @@ EMailPrinter * e_mail_printer_new (EMailPartList *source); ...@@ -67,6 +68,7 @@ EMailPrinter * e_mail_printer_new (EMailPartList *source);
void e_mail_printer_print (EMailPrinter *printer, void e_mail_printer_print (EMailPrinter *printer,
GtkPrintOperationAction action, GtkPrintOperationAction action,
EMailFormatter *formatter,
GCancellable *cancellable); GCancellable *cancellable);
void e_mail_printer_set_export_filename void e_mail_printer_set_export_filename
......
...@@ -951,6 +951,7 @@ mail_reader_do_print_message (GObject *object, ...@@ -951,6 +951,7 @@ mail_reader_do_print_message (GObject *object,
gpointer user_data) gpointer user_data)
{ {
EMailReader *reader = E_MAIL_READER (object); EMailReader *reader = E_MAIL_READER (object);
EMailDisplay *mail_display;
EActivity *activity; EActivity *activity;
GCancellable *cancellable; GCancellable *cancellable;
EMailPrinter *printer; EMailPrinter *printer;
...@@ -969,7 +970,11 @@ mail_reader_do_print_message (GObject *object, ...@@ -969,7 +970,11 @@ mail_reader_do_print_message (GObject *object,
printer, "done", printer, "done",
G_CALLBACK (printing_done_cb), activity); G_CALLBACK (printing_done_cb), activity);
e_mail_printer_print (printer, context->action, cancellable); mail_display = e_mail_reader_get_mail_display (reader);
e_mail_printer_print (printer, context->action,
e_mail_display_get_formatter (mail_display),
cancellable);
free_message_printing_context (context); free_message_printing_context (context);
} }
......
...@@ -71,6 +71,7 @@ handle_mail_request (GSimpleAsyncResult *res, ...@@ -71,6 +71,7 @@ handle_mail_request (GSimpleAsyncResult *res,
GByteArray *ba; GByteArray *ba;
gchar *part_id; gchar *part_id;
gchar *val; gchar *val;
const gchar *default_charset, *charset;
EMailFormatterContext context = { 0 }; EMailFormatterContext context = { 0 };
...@@ -99,6 +100,9 @@ handle_mail_request (GSimpleAsyncResult *res, ...@@ -99,6 +100,9 @@ handle_mail_request (GSimpleAsyncResult *res,
if (val) if (val)
context.mode = atoi (val); context.mode = atoi (val);
default_charset = g_hash_table_lookup (request->priv->uri_query, "formatter_default_charset");
charset = g_hash_table_lookup (request->priv->uri_query, "formatter_charset");
context.part_list = g_object_ref (part_list); context.part_list = g_object_ref (part_list);
context.uri = request->priv->full_uri; context.uri = request->priv->full_uri;
...@@ -107,6 +111,11 @@ handle_mail_request (GSimpleAsyncResult *res, ...@@ -107,6 +111,11 @@ handle_mail_request (GSimpleAsyncResult *res,
else else
formatter = e_mail_formatter_new (); formatter = e_mail_formatter_new ();
if (default_charset && *default_charset)
e_mail_formatter_set_default_charset (formatter, default_charset);
if (charset && *charset)
e_mail_formatter_set_charset (formatter, charset);
part_id = g_hash_table_lookup (request->priv->uri_query, "part_id"); part_id = g_hash_table_lookup (request->priv->uri_query, "part_id");
if (part_id) { if (part_id) {
EMailPart *part; EMailPart *part;
......
...@@ -974,7 +974,7 @@ em_utils_composer_print_cb (EMsgComposer *composer, ...@@ -974,7 +974,7 @@ em_utils_composer_print_cb (EMsgComposer *composer,
emp, "done", emp, "done",
G_CALLBACK (composer_print_done_cb), NULL); G_CALLBACK (composer_print_done_cb), NULL);
e_mail_printer_print (emp, action, NULL); e_mail_printer_print (emp, action, NULL, NULL);
g_object_unref (parts); g_object_unref (parts);
} }
......
...@@ -622,7 +622,7 @@ do_print_msg_to_file (GObject *source, ...@@ -622,7 +622,7 @@ do_print_msg_to_file (GObject *source,
printer, "done", printer, "done",
G_CALLBACK (g_object_unref), printer); G_CALLBACK (g_object_unref), printer);
e_mail_printer_print (printer, GTK_PRINT_OPERATION_ACTION_EXPORT, NULL); e_mail_printer_print (printer, GTK_PRINT_OPERATION_ACTION_EXPORT, NULL, NULL);
g_object_unref (parser); g_object_unref (parser);
} }
...@@ -1143,7 +1143,7 @@ em_utils_selection_set_urilist (GtkSelectionData *data, ...@@ -1143,7 +1143,7 @@ em_utils_selection_set_urilist (GtkSelectionData *data,
} }
/** /**
* em_utils_selection_set_urilist: * em_utils_selection_get_urilist:
* @data: * @data:
* @folder: * @folder:
* @uids: * @uids:
......
...@@ -82,6 +82,7 @@ emfe_itip_format (EMailFormatterExtension *extension, ...@@ -82,6 +82,7 @@ emfe_itip_format (EMailFormatterExtension *extension,
CamelFolder *folder; CamelFolder *folder;
CamelMimeMessage *message; CamelMimeMessage *message;
const gchar *message_uid; const gchar *message_uid;
const gchar *default_charset, *charset;
gchar *uri; gchar *uri;
folder = e_mail_part_list_get_folder (context->part_list); folder = e_mail_part_list_get_folder (context->part_list);
...@@ -102,10 +103,20 @@ emfe_itip_format (EMailFormatterExtension *extension, ...@@ -102,10 +103,20 @@ emfe_itip_format (EMailFormatterExtension *extension,
itip_part->uid = g_strdup (message_uid); itip_part->uid = g_strdup (message_uid);
itip_part->msg = g_object_ref (message); itip_part->msg = g_object_ref (message);
default_charset = e_mail_formatter_get_default_charset (formatter);
charset = e_mail_formatter_get_charset (formatter);
if (!default_charset)
default_charset = "";
if (!charset)
charset = "";
uri = e_mail_part_build_uri ( uri = e_mail_part_build_uri (
folder, message_uid, folder, message_uid,
"part_id", G_TYPE_STRING, part->id, "part_id", G_TYPE_STRING, part->id,
"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW, "mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
"formatter_default_charset", G_TYPE_STRING, default_charset,
"formatter_charset", G_TYPE_STRING, charset,
NULL); NULL);
buffer = g_string_sized_new (256); buffer = g_string_sized_new (256);
......
...@@ -312,11 +312,19 @@ emfe_text_highlight_format (EMailFormatterExtension *extension, ...@@ -312,11 +312,19 @@ emfe_text_highlight_format (EMailFormatterExtension *extension,
} else { } else {
CamelFolder *folder; CamelFolder *folder;
const gchar *message_uid; const gchar *message_uid;
const gchar *default_charset, *charset;
gchar *uri, *str; gchar *uri, *str;
gchar *syntax; gchar *syntax;
folder = e_mail_part_list_get_folder (context->part_list); folder = e_mail_part_list_get_folder (context->part_list);
message_uid = e_mail_part_list_get_message_uid (context->part_list); message_uid = e_mail_part_list_get_message_uid (context->part_list);
default_charset = e_mail_formatter_get_default_charset (formatter);
charset = e_mail_formatter_get_charset (formatter);