[evolution] I#1314 - templates: Quoted body shown incorrectly in Plain Text mode



commit 6c5c15900c486ffe40260c114a4863d32a00acf0
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jan 13 18:12:20 2021 +0100

    I#1314 - templates: Quoted body shown incorrectly in Plain Text mode
    
    Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1314

 data/webkit/e-editor.js     | 34 ++++++++++++++++++++++++++++++----
 src/mail/e-mail-templates.c | 20 +++++++++++++-------
 2 files changed, 43 insertions(+), 11 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 8f9334b54c..82173a07fb 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -5504,11 +5504,13 @@ EvoEditor.processLoadedContent = function()
 
                                EvoEditor.splitPreTexts(node, false, list);
 
-                               for (ii = 0; ii < list.length; ii++) {
-                                       node.parentElement.insertBefore(list[ii], node);
-                               }
+                               if (node.tagName == "PRE") {
+                                       for (ii = 0; ii < list.length; ii++) {
+                                               node.parentElement.insertBefore(list[ii], node);
+                                       }
 
-                               node.remove();
+                                       node.remove();
+                               }
                        }
                }
        }
@@ -5839,6 +5841,30 @@ EvoEditor.LoadHTML = function(html)
 
                document.documentElement.innerHTML = html;
 
+               var node = document.body.querySelector("#x-evo-template-fix-paragraphs");
+               if (node) {
+                       node.remove();
+
+                       var list, ii;
+
+                       list = document.body.querySelectorAll("BLOCKQUOTE,DIV,PRE");
+
+                       for (ii = 0; ii < list.length; ii++) {
+                               node = list[ii];
+
+                               if (node.parentElement && node.parentElement.parentElement &&
+                                   (node.parentElement.tagName == "DIV" || node.parentElement.tagName == 
"PRE") &&
+                                   (node.parentElement.parentElement === document.body || 
node.parentElement.parentElement.tagName == "BODY")) {
+                                       var parent = node.parentElement;
+
+                                       parent.parentElement.insertBefore(node, parent);
+
+                                       if (!parent.childElementCount)
+                                               parent.remove();
+                               }
+                       }
+               }
+
                EvoEditor.processLoadedContent();
                EvoEditor.initializeContent();
 
diff --git a/src/mail/e-mail-templates.c b/src/mail/e-mail-templates.c
index eebd004dbb..47fb3aafce 100644
--- a/src/mail/e-mail-templates.c
+++ b/src/mail/e-mail-templates.c
@@ -216,9 +216,15 @@ fill_template (CamelMimeMessage *message,
                                message_part = camel_multipart_get_part (multipart, i);
                        }
                }
-       } else
+       } else {
+               CamelContentType *mpct;
+
                message_part = CAMEL_MIME_PART (message);
 
+               mpct = camel_mime_part_get_content_type (message_part);
+               message_html = mpct && camel_content_type_is (mpct, "text", "html");
+       }
+
        /* Get content of the template */
        stream = camel_stream_mem_new ();
        camel_data_wrapper_decode_to_stream_sync (camel_medium_get_content (CAMEL_MEDIUM (template)), stream, 
NULL, NULL);
@@ -271,7 +277,7 @@ fill_template (CamelMimeMessage *message,
 
                html = camel_text_to_html (
                        template_body->str,
-                       CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
+                       CAMEL_MIME_FILTER_TOHTML_DIV |
                        CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES |
                        CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS |
                        CAMEL_MIME_FILTER_TOHTML_MARK_CITATION |
@@ -282,6 +288,8 @@ fill_template (CamelMimeMessage *message,
                g_string_append (template_body, "<!-- disable-format-prompt -->");
        }
 
+       g_string_append (template_body, "<span id=\"x-evo-template-fix-paragraphs\"></span>");
+
        /* Now extract body of the original message and replace the $ORIG[body] modifier in template */
        if (message_part && (has_quoted_body || e_util_strstrcase (template_body->str, "$ORIG[body]"))) {
                GString *message_body, *message_body_nosig = NULL;
@@ -363,10 +371,9 @@ fill_template (CamelMimeMessage *message,
                if (template_html && !message_html) {
                        gchar *html = camel_text_to_html (
                                message_body->str,
-                               CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
+                               CAMEL_MIME_FILTER_TOHTML_PRE |
                                CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES |
                                CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS |
-                               CAMEL_MIME_FILTER_TOHTML_MARK_CITATION |
                                CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES, 0);
                        replace_template_variable (template_body, "body", html);
                        g_free (html);
@@ -380,10 +387,9 @@ fill_template (CamelMimeMessage *message,
 
                        html = camel_text_to_html (
                                template_body->str,
-                               CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
+                               CAMEL_MIME_FILTER_TOHTML_DIV |
                                CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES |
                                CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS |
-                               CAMEL_MIME_FILTER_TOHTML_MARK_CITATION |
                                CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES, 0);
                        g_string_assign (template_body, html);
                        g_free (html);
@@ -397,7 +403,7 @@ fill_template (CamelMimeMessage *message,
                        if (!message_html) {
                                gchar *html = camel_text_to_html (
                                        message_body_nosig->str,
-                                       CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
+                                       CAMEL_MIME_FILTER_TOHTML_PRE |
                                        CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES |
                                        CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS |
                                        CAMEL_MIME_FILTER_TOHTML_QUOTE_CITATION |


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