[evolution/gnome-3-6] Bug #692005 - Changing character encoding doesn't work



commit 45aeb9e236f411b77c193ea9631f721d658a771c
Author: Milan Crha <mcrha redhat com>
Date:   Fri Jan 18 18:35:36 2013 +0100

    Bug #692005 - Changing character encoding doesn't work

 em-format/e-mail-formatter-message-rfc822.c        |   12 ++++-
 em-format/e-mail-formatter-text-html.c             |   11 ++++
 em-format/e-mail-formatter-text-plain.c            |   11 ++++
 mail/e-mail-display.c                              |   53 ++++++++++++++++++--
 mail/e-mail-display.h                              |    2 +
 mail/e-mail-printer.c                              |   25 +++++++++-
 mail/e-mail-printer.h                              |    2 +
 mail/e-mail-reader-utils.c                         |    7 ++-
 mail/e-mail-request.c                              |    9 +++
 mail/em-composer-utils.c                           |    2 +-
 mail/em-utils.c                                    |    4 +-
 modules/itip-formatter/e-mail-formatter-itip.c     |   11 ++++
 .../e-mail-formatter-text-highlight.c              |   11 ++++
 .../vcard-inline/e-mail-formatter-vcard-inline.c   |   11 ++++
 14 files changed, 160 insertions(+), 11 deletions(-)
---
diff --git a/em-format/e-mail-formatter-message-rfc822.c b/em-format/e-mail-formatter-message-rfc822.c
index 614efca..860f0a6 100644
--- a/em-format/e-mail-formatter-message-rfc822.c
+++ b/em-format/e-mail-formatter-message-rfc822.c
@@ -191,7 +191,7 @@ emfe_message_rfc822_format (EMailFormatterExtension *extension,
 	} else {
 		gchar *str;
 		gchar *uri;
-
+		const gchar *default_charset, *charset;
 		EMailPart *p;
 		GSList *iter;
 
@@ -199,6 +199,14 @@ emfe_message_rfc822_format (EMailFormatterExtension *extension,
 		if (!iter || !iter->next)
 			return FALSE;
 
+		default_charset = e_mail_formatter_get_default_charset (formatter);
+		charset = e_mail_formatter_get_charset (formatter);
+
+		if (!default_charset)
+			default_charset = "";
+		if (!charset)
+			charset = "";
+
 		p = iter->data;
 
 		uri = e_mail_part_build_uri (
@@ -206,6 +214,8 @@ emfe_message_rfc822_format (EMailFormatterExtension *extension,
 			"part_id", G_TYPE_STRING, p->id,
 			"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
 			"headers_collapsable", G_TYPE_INT, 0,
+			"formatter_default_charset", G_TYPE_STRING, default_charset,
+			"formatter_charset", G_TYPE_STRING, charset,
 			NULL);
 
 		str = g_strdup_printf (
diff --git a/em-format/e-mail-formatter-text-html.c b/em-format/e-mail-formatter-text-html.c
index 74cef43..33aabe8 100644
--- a/em-format/e-mail-formatter-text-html.c
+++ b/em-format/e-mail-formatter-text-html.c
@@ -315,11 +315,22 @@ emfe_text_html_format (EMailFormatterExtension *extension,
 		g_string_free (string, TRUE);
 	} else {
 		gchar *uri, *str;
+		const gchar *default_charset, *charset;
+
+		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 (
 			context->folder, context->message_uid,
 			"part_id", G_TYPE_STRING, part->id,
 			"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
+			"formatter_default_charset", G_TYPE_STRING, default_charset,
+			"formatter_charset", G_TYPE_STRING, charset,
 			NULL);
 
 		str = g_strdup_printf (
diff --git a/em-format/e-mail-formatter-text-plain.c b/em-format/e-mail-formatter-text-plain.c
index 40b9358..51165b3 100644
--- a/em-format/e-mail-formatter-text-plain.c
+++ b/em-format/e-mail-formatter-text-plain.c
@@ -147,11 +147,22 @@ emfe_text_plain_format (EMailFormatterExtension *extension,
 
 	} else {
 		gchar *uri, *str;
+		const gchar *default_charset, *charset;
+
+		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 (
 			context->folder, context->message_uid,
 			"part_id", G_TYPE_STRING, part->id,
 			"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
+			"formatter_default_charset", G_TYPE_STRING, default_charset,
+			"formatter_charset", G_TYPE_STRING, charset,
 			NULL);
 
 		str = g_strdup_printf (
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 9cbc983..9bb3238 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -83,6 +83,7 @@ enum {
 	PROP_PART_LIST,
 	PROP_HEADERS_COLLAPSABLE,
 	PROP_HEADERS_COLLAPSED,
+	PROP_FORMATTER
 };
 
 static CamelDataCache *emd_global_http_cache = NULL;
@@ -1283,6 +1284,11 @@ mail_display_get_property (GObject *object,
                            GParamSpec *pspec)
 {
 	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:
 			g_value_set_pointer (
 				value, e_mail_display_get_parts_list (
@@ -1489,6 +1495,16 @@ e_mail_display_class_init (EMailDisplayClass *class)
 
 	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 (
+		object_class,
 		PROP_PART_LIST,
 		g_param_spec_pointer (
 			"part-list",
@@ -1704,6 +1720,14 @@ e_mail_display_set_mode (EMailDisplay *display,
 	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 *
 e_mail_display_get_parts_list (EMailDisplay *display)
 {
@@ -1787,6 +1811,7 @@ e_mail_display_load (EMailDisplay *display,
                      const gchar *msg_uri)
 {
 	EMailPartList *part_list;
+	const gchar *default_charset, *charset;
 	gchar *uri;
 
 	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
@@ -1799,13 +1824,21 @@ e_mail_display_load (EMailDisplay *display,
 		return;
 	}
 
+	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 (
 		part_list->folder, part_list->message_uid,
 		"mode", G_TYPE_INT, display->priv->mode,
-		"headers_collapsable", G_TYPE_BOOLEAN,
-		display->priv->headers_collapsable,
-		"headers_collapsed", G_TYPE_BOOLEAN,
-		display->priv->headers_collapsed,
+		"headers_collapsable", G_TYPE_BOOLEAN, display->priv->headers_collapsable,
+		"headers_collapsed", G_TYPE_BOOLEAN, display->priv->headers_collapsed,
+		"formatter_default_charset", G_TYPE_STRING, default_charset,
+		"formatter_charset", G_TYPE_STRING, charset,
 		NULL);
 
 	e_web_view_load_uri (E_WEB_VIEW (display), uri);
@@ -1821,6 +1854,7 @@ do_reload_display (EMailDisplay *display)
 	GHashTable *table;
 	SoupURI *soup_uri;
 	gchar *mode, *collapsable, *collapsed;
+	const gchar *default_charset, *charset;
 
 	web_view = E_WEB_VIEW (display);
 	uri = (gchar *) e_web_view_get_uri (web_view);
@@ -1840,6 +1874,13 @@ do_reload_display (EMailDisplay *display)
 	mode = g_strdup_printf ("%d", display->priv->mode);
 	collapsable = g_strdup_printf ("%d", display->priv->headers_collapsable);
 	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);
 	g_hash_table_replace (
@@ -1848,6 +1889,10 @@ do_reload_display (EMailDisplay *display)
 		table, g_strdup ("headers_collapsable"), collapsable);
 	g_hash_table_replace (
 		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);
 
diff --git a/mail/e-mail-display.h b/mail/e-mail-display.h
index 99ad73a..90ba4eb 100644
--- a/mail/e-mail-display.h
+++ b/mail/e-mail-display.h
@@ -68,6 +68,8 @@ void			e_mail_display_set_mode		(EMailDisplay *display,
 							 EMailFormatterMode mode);
 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);
 
 void			e_mail_display_set_parts_list	(EMailDisplay *display,
diff --git a/mail/e-mail-printer.c b/mail/e-mail-printer.c
index 92642bb..b28ab17 100644
--- a/mail/e-mail-printer.c
+++ b/mail/e-mail-printer.c
@@ -199,19 +199,33 @@ emp_start_printing (GObject *object,
 }
 
 static void
-emp_run_print_operation (EMailPrinter *emp)
+emp_run_print_operation (EMailPrinter *emp,
+			 EMailFormatter *formatter)
 {
 	gchar *mail_uri;
+	const gchar *default_charset, *charset;
+
+	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 (
 		emp->priv->parts_list->folder,
 		emp->priv->parts_list->message_uid,
 		"__evo-load-image", G_TYPE_BOOLEAN, TRUE,
 		"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_PRINTING,
+		"formatter_default_charset", G_TYPE_STRING, default_charset,
+		"formatter_charset", G_TYPE_STRING, charset,
 		NULL);
 
 	/* Print_layout is a special EMPart created by EMFormatHTMLPrint */
 	if (emp->priv->webview == NULL) {
+		EMailFormatter *emp_formatter;
+
 		emp->priv->webview = g_object_new (
 			E_TYPE_MAIL_DISPLAY,
 			"mode", E_MAIL_FORMATTER_MODE_PRINTING, NULL);
@@ -219,6 +233,12 @@ emp_run_print_operation (EMailPrinter *emp)
 		e_mail_display_set_force_load_images (
 			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_signal_connect (
 			emp->priv->webview, "notify::load-status",
@@ -824,6 +844,7 @@ e_mail_printer_new (EMailPartList *source)
 void
 e_mail_printer_print (EMailPrinter *emp,
                       GtkPrintOperationAction action,
+		      EMailFormatter *formatter,
                       GCancellable *cancellable)
 {
 	g_return_if_fail (E_IS_MAIL_PRINTER (emp));
@@ -850,7 +871,7 @@ e_mail_printer_print (EMailPrinter *emp,
 			cancellable, "cancelled",
 			G_CALLBACK (gtk_print_operation_cancel), emp->priv->operation);
 
-	emp_run_print_operation (emp);
+	emp_run_print_operation (emp, formatter);
 }
 
 const gchar *
diff --git a/mail/e-mail-printer.h b/mail/e-mail-printer.h
index c177bfe..01c32f3 100644
--- a/mail/e-mail-printer.h
+++ b/mail/e-mail-printer.h
@@ -21,6 +21,7 @@
 #define E_MAIL_PRINTER_H
 
 #include <em-format/e-mail-part-list.h>
+#include <em-format/e-mail-formatter.h>
 
 /* Standard GObject macros */
 #define E_TYPE_MAIL_PRINTER \
@@ -67,6 +68,7 @@ EMailPrinter *  e_mail_printer_new	(EMailPartList *source);
 
 void		e_mail_printer_print	(EMailPrinter *printer,
 					 GtkPrintOperationAction action,
+					 EMailFormatter *formatter,
 					 GCancellable *cancellable);
 
 void            e_mail_printer_set_export_filename
diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c
index 91bb855..9625fc1 100644
--- a/mail/e-mail-reader-utils.c
+++ b/mail/e-mail-reader-utils.c
@@ -952,6 +952,7 @@ mail_reader_do_print_message (GObject *object,
                               gpointer user_data)
 {
 	EMailReader *reader = E_MAIL_READER (object);
+	EMailDisplay *mail_display;
 	EActivity *activity;
 	GCancellable *cancellable;
 	EMailPrinter *printer;
@@ -970,7 +971,11 @@ mail_reader_do_print_message (GObject *object,
 		printer, "done",
 		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);
 }
diff --git a/mail/e-mail-request.c b/mail/e-mail-request.c
index b0cbede..f6c5164 100644
--- a/mail/e-mail-request.c
+++ b/mail/e-mail-request.c
@@ -74,6 +74,7 @@ handle_mail_request (GSimpleAsyncResult *res,
 	GByteArray *ba;
 	gchar *part_id;
 	gchar *val;
+	const gchar *default_charset, *charset;
 
 	EMailFormatterContext context = { 0 };
 
@@ -108,11 +109,19 @@ handle_mail_request (GSimpleAsyncResult *res,
 	context.parts = part_list->list;
 	context.uri = request->priv->full_uri;
 
+	default_charset = g_hash_table_lookup (request->priv->uri_query, "formatter_default_charset");
+	charset = g_hash_table_lookup (request->priv->uri_query, "formatter_charset");
+
 	if (context.mode == E_MAIL_FORMATTER_MODE_PRINTING)
 		formatter = e_mail_formatter_print_new ();
 	else
 		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");
 	if (part_id) {
 		EMailPart *part;
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 513c03f..8c463b9 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -977,7 +977,7 @@ em_utils_composer_print_cb (EMsgComposer *composer,
 		emp, "done",
 		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);
 }
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 8f1a9c6..cd32397 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -631,7 +631,7 @@ do_print_msg_to_file (GObject *source,
 		printer, "done",
 		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);
 }
@@ -1152,7 +1152,7 @@ em_utils_selection_set_urilist (GtkSelectionData *data,
 }
 
 /**
- * em_utils_selection_set_urilist:
+ * em_utils_selection_get_urilist:
  * @data:
  * @folder:
  * @uids:
diff --git a/modules/itip-formatter/e-mail-formatter-itip.c b/modules/itip-formatter/e-mail-formatter-itip.c
index ca6b2f6..0456a88 100644
--- a/modules/itip-formatter/e-mail-formatter-itip.c
+++ b/modules/itip-formatter/e-mail-formatter-itip.c
@@ -90,6 +90,7 @@ emfe_itip_format (EMailFormatterExtension *extension,
 		itip_view_write (formatter, buffer);
 
 	} else {
+		const gchar *default_charset, *charset;
 		gchar *uri;
 
 		/* mark message as containing calendar, thus it will show the
@@ -107,10 +108,20 @@ emfe_itip_format (EMailFormatterExtension *extension,
 		itip_part->uid = g_strdup (context->message_uid);
 		itip_part->msg = g_object_ref (context->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 (
 			context->folder, context->message_uid,
 			"part_id", G_TYPE_STRING, part->id,
 			"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
+			"formatter_default_charset", G_TYPE_STRING, default_charset,
+			"formatter_charset", G_TYPE_STRING, charset,
 			NULL);
 
 		buffer = g_string_sized_new (256);
diff --git a/modules/text-highlight/e-mail-formatter-text-highlight.c b/modules/text-highlight/e-mail-formatter-text-highlight.c
index 3c71aea..8c1484d 100644
--- a/modules/text-highlight/e-mail-formatter-text-highlight.c
+++ b/modules/text-highlight/e-mail-formatter-text-highlight.c
@@ -325,9 +325,18 @@ emfe_text_highlight_format (EMailFormatterExtension *extension,
 		g_free ((gchar *) argv[3]);
 		pango_font_description_free (fd);
 	} else {
+		const gchar *default_charset, *charset;
 		gchar *uri, *str;
 		gchar *syntax;
 
+		default_charset = e_mail_formatter_get_default_charset (formatter);
+		charset = e_mail_formatter_get_charset (formatter);
+
+		if (!default_charset)
+			default_charset = "";
+		if (!charset)
+			charset = "";
+
 		syntax = get_syntax (part, NULL);
 
 		uri = e_mail_part_build_uri (
@@ -335,6 +344,8 @@ emfe_text_highlight_format (EMailFormatterExtension *extension,
 			"part_id", G_TYPE_STRING, part->id,
 			"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
 			"__formatas", G_TYPE_STRING, syntax,
+			"formatter_default_charset", G_TYPE_STRING, default_charset,
+			"formatter_charset", G_TYPE_STRING, charset,
 			NULL);
 
 		g_free (syntax);
diff --git a/modules/vcard-inline/e-mail-formatter-vcard-inline.c b/modules/vcard-inline/e-mail-formatter-vcard-inline.c
index 1abb428..d1da708 100644
--- a/modules/vcard-inline/e-mail-formatter-vcard-inline.c
+++ b/modules/vcard-inline/e-mail-formatter-vcard-inline.c
@@ -89,6 +89,7 @@ emfe_vcard_inline_format (EMailFormatterExtension *extension,
 			vcard_part->formatter, contact, stream, cancellable);
 
 	} else {
+		const gchar *default_charset, *charset;
 		gchar *str, *uri;
 		gint length;
 		const gchar *label = NULL;
@@ -100,6 +101,14 @@ emfe_vcard_inline_format (EMailFormatterExtension *extension,
 		if (length < 1)
 			return FALSE;
 
+		default_charset = e_mail_formatter_get_default_charset (formatter);
+		charset = e_mail_formatter_get_charset (formatter);
+
+		if (!default_charset)
+			default_charset = "";
+		if (!charset)
+			charset = "";
+
 		if (!vcard_part->message_uid && context->message_uid)
 			vcard_part->message_uid = g_strdup (context->message_uid);
 
@@ -110,6 +119,8 @@ emfe_vcard_inline_format (EMailFormatterExtension *extension,
 			context->folder, context->message_uid,
 			"part_id", G_TYPE_STRING, part->id,
 			"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
+			"formatter_default_charset", G_TYPE_STRING, default_charset,
+			"formatter_charset", G_TYPE_STRING, charset,
 			NULL);
 
 		mode = eab_contact_formatter_get_display_mode (vcard_part->formatter);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]