From b4013262bea4bf82dcfe7f335dd710f80ca9b77e Mon Sep 17 00:00:00 2001 From: Tomas Popela Date: Mon, 2 Feb 2015 10:40:52 +0100 Subject: [PATCH] Message credits are put on the end of quoted content instead of on its beginning. I received one message and on its end there was the paragraph element left opened:

When we appended the credentials after it:

credits
Now WebKit tried to do its best to parse, fix and load the content correctly that resulted in:

credits
Clearly, we will fail when moving the credits to right place as we are expecting the the credits are inner part of the span. So set the credentials into the data-credits attribute (as there it will be resistant against this behavior) and rework the part that's handling it. --- e-util/e-html-editor-view.c | 44 ++++++++++++++++++------------ em-format/e-mail-formatter-quote.c | 2 +- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c index 3651a397f0..0da22eb08d 100644 --- a/e-util/e-html-editor-view.c +++ b/e-util/e-html-editor-view.c @@ -1050,17 +1050,21 @@ move_elements_to_body (WebKitDOMDocument *document) list = webkit_dom_document_query_selector_all ( document, "span.-x-evo-to-body[data-credits]", NULL); for (ii = webkit_dom_node_list_get_length (list) - 1; ii >= 0; ii--) { - WebKitDOMNode *child; + char *credits; + WebKitDOMElement *pre_element; WebKitDOMNode *node = webkit_dom_node_list_item (list, ii); - while ((child = webkit_dom_node_get_first_child (node))) { - webkit_dom_node_insert_before ( - WEBKIT_DOM_NODE (body), - child, - webkit_dom_node_get_first_child ( - WEBKIT_DOM_NODE (body)), - NULL); - } + pre_element = webkit_dom_document_create_element (document, "pre", NULL); + credits = webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (node), "data-credits"); + webkit_dom_html_element_set_inner_text (WEBKIT_DOM_HTML_ELEMENT (pre_element), credits, NULL); + g_free (credits); + + webkit_dom_node_insert_before ( + WEBKIT_DOM_NODE (body), + WEBKIT_DOM_NODE (pre_element), + webkit_dom_node_get_first_child ( + WEBKIT_DOM_NODE (body)), + NULL); remove_node (node); } @@ -4904,16 +4908,20 @@ html_editor_convert_view_content (EHTMLEditorView *view, document, "span.-x-evo-to-body[data-credits]", NULL); length = webkit_dom_node_list_get_length (list); for (ii = 0; ii < length; ii++) { - WebKitDOMNode *node, *child; + char *credits; + WebKitDOMElement *pre_element; + WebKitDOMNode *node = webkit_dom_node_list_item (list, ii); - node = webkit_dom_node_list_item (list, ii); - while ((child = webkit_dom_node_get_first_child (node))) { - webkit_dom_node_insert_before ( - WEBKIT_DOM_NODE (wrapper), - child, - WEBKIT_DOM_NODE (content_wrapper), - NULL); - } + pre_element = webkit_dom_document_create_element (document, "pre", NULL); + credits = webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (node), "data-credits"); + webkit_dom_html_element_set_inner_text (WEBKIT_DOM_HTML_ELEMENT (pre_element), credits, NULL); + g_free (credits); + + webkit_dom_node_insert_before ( + WEBKIT_DOM_NODE (wrapper), + WEBKIT_DOM_NODE (pre_element), + WEBKIT_DOM_NODE (content_wrapper), + NULL); remove_node (node); } diff --git a/em-format/e-mail-formatter-quote.c b/em-format/e-mail-formatter-quote.c index bbd2da45a9..1916bbad8f 100644 --- a/em-format/e-mail-formatter-quote.c +++ b/em-format/e-mail-formatter-quote.c @@ -122,7 +122,7 @@ mail_formatter_quote_run (EMailFormatter *formatter, * the special span element and it will be moved to body in EHTMLEditorView */ if (qf->priv->credits && *qf->priv->credits) { gchar *credits = g_strdup_printf ( - "
%s
", + "", qf->priv->credits); g_output_stream_write_all ( stream, credits, strlen (credits), NULL, cancellable, NULL);