[evolution/wip/webkit2] Bug 688368 - Wrong characters encoding in attached html file



commit ede42534e3fb71ed00ffba52d7b3f74cf28deabf
Author: Milan Crha <mcrha redhat com>
Date:   Wed Mar 2 14:32:33 2016 +0100

    Bug 688368 - Wrong characters encoding in attached html file

 e-util/e-web-view.c          |    5 ++++
 em-format/e-mail-formatter.c |    2 +
 em-format/e-mail-part.c      |   48 ++++++++++++++++++++++++++++++++++++++++++
 em-format/e-mail-part.h      |    5 ++++
 mail/e-mail-request.c        |    7 +++++-
 5 files changed, 66 insertions(+), 1 deletions(-)
---
diff --git a/e-util/e-web-view.c b/e-util/e-web-view.c
index 7524d14..496cff5 100644
--- a/e-util/e-web-view.c
+++ b/e-util/e-web-view.c
@@ -1050,6 +1050,11 @@ web_view_constructed (GObject *object)
 
        web_settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (object));
 
+       g_object_set (
+               G_OBJECT (web_settings),
+               "default-charset", "UTF-8",
+               NULL);
+
        e_binding_bind_property (
                web_settings, "enable-caret-browsing",
                E_WEB_VIEW (object), "caret-mode",
diff --git a/em-format/e-mail-formatter.c b/em-format/e-mail-formatter.c
index 9502c05..d605524 100644
--- a/em-format/e-mail-formatter.c
+++ b/em-format/e-mail-formatter.c
@@ -1095,6 +1095,8 @@ e_mail_formatter_format_text (EMailFormatter *formatter,
 
        filter = camel_mime_filter_charset_new (charset, "UTF-8");
        if (filter != NULL) {
+               e_mail_part_set_converted_to_utf8 (part, TRUE);
+
                stream = camel_filter_output_stream_new (stream, filter);
                g_filter_output_stream_set_close_base_stream (
                        G_FILTER_OUTPUT_STREAM (stream), FALSE);
diff --git a/em-format/e-mail-part.c b/em-format/e-mail-part.c
index c5184b7..8795cde 100644
--- a/em-format/e-mail-part.c
+++ b/em-format/e-mail-part.c
@@ -50,11 +50,13 @@ struct _EMailPartPrivate {
        gchar *mime_type;
 
        gboolean is_attachment;
+       gboolean converted_to_utf8;
 };
 
 enum {
        PROP_0,
        PROP_CID,
+       PROP_CONVERTED_TO_UTF8,
        PROP_ID,
        PROP_IS_ATTACHMENT,
        PROP_MIME_PART,
@@ -114,6 +116,12 @@ mail_part_set_property (GObject *object,
                                g_value_get_string (value));
                        return;
 
+               case PROP_CONVERTED_TO_UTF8:
+                       e_mail_part_set_converted_to_utf8 (
+                               E_MAIL_PART (object),
+                               g_value_get_boolean (value));
+                       return;
+
                case PROP_ID:
                        mail_part_set_id (
                                E_MAIL_PART (object),
@@ -162,6 +170,13 @@ mail_part_get_property (GObject *object,
                                E_MAIL_PART (object)));
                        return;
 
+               case PROP_CONVERTED_TO_UTF8:
+                       g_value_set_boolean (
+                               value,
+                               e_mail_part_get_converted_to_utf8 (
+                               E_MAIL_PART (object)));
+                       return;
+
                case PROP_ID:
                        g_value_set_string (
                                value,
@@ -269,6 +284,17 @@ e_mail_part_class_init (EMailPartClass *class)
 
        g_object_class_install_property (
                object_class,
+               PROP_CONVERTED_TO_UTF8,
+               g_param_spec_boolean (
+                       "converted-to-utf8",
+                       "Converted To UTF8",
+                       "Whether the part content was already converted to UTF-8",
+                       FALSE,
+                       G_PARAM_READWRITE |
+                       G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (
+               object_class,
                PROP_ID,
                g_param_spec_string (
                        "id",
@@ -447,6 +473,28 @@ e_mail_part_set_mime_type (EMailPart *part,
 }
 
 gboolean
+e_mail_part_get_converted_to_utf8 (EMailPart *part)
+{
+       g_return_val_if_fail (E_IS_MAIL_PART (part), FALSE);
+
+       return part->priv->converted_to_utf8;
+}
+
+void
+e_mail_part_set_converted_to_utf8 (EMailPart *part,
+                                  gboolean converted_to_utf8)
+{
+       g_return_if_fail (E_IS_MAIL_PART (part));
+
+       if (converted_to_utf8 == part->priv->converted_to_utf8)
+               return;
+
+       part->priv->converted_to_utf8 = converted_to_utf8;
+
+       g_object_notify (G_OBJECT (part), "converted-to-utf8");
+}
+
+gboolean
 e_mail_part_should_show_inline (EMailPart *part)
 {
        CamelMimePart *mime_part;
diff --git a/em-format/e-mail-part.h b/em-format/e-mail-part.h
index 41069d6..7ff9163 100644
--- a/em-format/e-mail-part.h
+++ b/em-format/e-mail-part.h
@@ -108,6 +108,11 @@ CamelMimePart *    e_mail_part_ref_mime_part       (EMailPart *part);
 const gchar *  e_mail_part_get_mime_type       (EMailPart *part);
 void           e_mail_part_set_mime_type       (EMailPart *part,
                                                 const gchar *mime_type);
+gboolean       e_mail_part_get_converted_to_utf8
+                                               (EMailPart *part);
+void           e_mail_part_set_converted_to_utf8
+                                               (EMailPart *part,
+                                                gboolean converted_to_utf8);
 gboolean       e_mail_part_should_show_inline  (EMailPart *part);
 struct _EMailPartList *
                e_mail_part_ref_part_list       (EMailPart *part);
diff --git a/mail/e-mail-request.c b/mail/e-mail-request.c
index 65dac64..49e175a 100644
--- a/mail/e-mail-request.c
+++ b/mail/e-mail-request.c
@@ -52,6 +52,7 @@ struct _EMailRequestPrivate {
        gchar *uri_base;
        gchar *full_uri;
 
+       gboolean part_converted_to_utf8;
        gchar *ret_mime_type;
 };
 
@@ -173,6 +174,8 @@ handle_mail_request (GSimpleAsyncResult *simple,
                                formatter, &context, part,
                                output_stream, mime_type,
                                cancellable);
+
+                       request->priv->part_converted_to_utf8 = e_mail_part_get_converted_to_utf8 (part);
                }
 
                g_object_unref (part);
@@ -436,7 +439,8 @@ mail_request_get_content_type (SoupRequest *request)
                mime_type = g_strdup ("text/html");
        }
 
-       if (g_strcmp0 (mime_type, "text/html") == 0) {
+       if (g_strcmp0 (mime_type, "text/html") == 0 &&
+           priv->part_converted_to_utf8) {
                priv->ret_mime_type = g_strconcat (
                        mime_type, "; charset=\"UTF-8\"", NULL);
                g_free (mime_type);
@@ -473,5 +477,6 @@ static void
 e_mail_request_init (EMailRequest *request)
 {
        request->priv = E_MAIL_REQUEST_GET_PRIVATE (request);
+       request->priv->part_converted_to_utf8 = FALSE;
 }
 


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