[evolution] Bug 762376 - Embedded images in signature only displays under evolution and not other clients



commit cca2aa230bb138ea71b7d6413577ad9da10c06f3
Author: Tomas Popela <tpopela redhat com>
Date:   Fri Feb 26 10:34:43 2016 +0100

    Bug 762376 - Embedded images in signature only displays under evolution and not other clients
    
    The main problem is that the GMail does not support base64 images. This is not a
    problem for Evolution as it is using them just for the Drafts and Templates. But
    there was a problem with the signatures as when they were saved the images inside
    them were left in the base64 format, but the data-inline attribute was removed
    from them. This later prevented the composer to correctly handle them.
    
    To avoid this issue change how the signatures are saved in the Signature editor.
    Save them in the same way as the Drafts and don't try to process them when saving
    them, but when the message with the given signature is being send. This could also
    fix issues with editing a signature once it is in the body.

 composer/e-composer-private.c    |    2 +
 e-util/e-html-editor-view.c      |  280 ++++++++++++++++++++++----------------
 e-util/e-html-editor-view.h      |    5 +
 e-util/e-mail-signature-editor.c |    9 +-
 4 files changed, 174 insertions(+), 122 deletions(-)
---
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index ae8322c..36f9b81 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -1119,6 +1119,8 @@ composer_load_signature_cb (EMailSignatureComboBox *combo_box,
 
                webkit_dom_html_element_set_inner_html (
                        WEBKIT_DOM_HTML_ELEMENT (insert_signature_in), contents, NULL);
+               e_html_editor_view_convert_element_from_html_to_plain_text (
+                       view, insert_signature_in);
                inner_text = webkit_dom_html_element_get_inner_text (
                        WEBKIT_DOM_HTML_ELEMENT (insert_signature_in));
                while ((child = webkit_dom_node_get_last_child (WEBKIT_DOM_NODE (insert_signature_in))))
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index feb64fa..447d324 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -9516,6 +9516,116 @@ remove_evolution_attributes (WebKitDOMElement *element)
 }
 
 static void
+convert_element_from_html_to_plain_text (EHTMLEditorView *view,
+                                         WebKitDOMElement *element,
+                                         gboolean *wrap,
+                                         gboolean *quote)
+{
+       gint blockquotes_count;
+       gchar *inner_text, *inner_html;
+       WebKitDOMDocument *document;
+       WebKitDOMElement *top_signature, *signature, *blockquote, *main_blockquote;
+       WebKitDOMNode *signature_clone, *from;
+
+       document = webkit_dom_node_get_owner_document (WEBKIT_DOM_NODE (element));
+
+       top_signature = webkit_dom_element_query_selector (
+               element, ".-x-evo-top-signature", NULL);
+       signature = webkit_dom_element_query_selector (
+               element, "span.-x-evo-signature", NULL);
+       main_blockquote = webkit_dom_element_query_selector (
+               element, "#-x-evo-main-cite", NULL);
+
+       blockquote = webkit_dom_document_create_element (
+               document, "blockquote", NULL);
+
+       if (main_blockquote) {
+               webkit_dom_element_set_attribute (
+                       blockquote, "type", "cite", NULL);
+               from = WEBKIT_DOM_NODE (main_blockquote);
+       } else {
+               if (signature) {
+                       WebKitDOMNode *parent = webkit_dom_node_get_parent_node (
+                               WEBKIT_DOM_NODE (signature));
+                       signature_clone = webkit_dom_node_clone_node (parent, TRUE);
+                       remove_node (parent);
+               }
+               from = WEBKIT_DOM_NODE (element);
+       }
+
+       blockquotes_count = create_text_markers_for_citations_in_element (WEBKIT_DOM_ELEMENT (from));
+       create_text_markers_for_selection_in_element (WEBKIT_DOM_ELEMENT (from));
+
+       inner_text = webkit_dom_html_element_get_inner_text (
+               WEBKIT_DOM_HTML_ELEMENT (from));
+
+       webkit_dom_html_element_set_inner_text (
+               WEBKIT_DOM_HTML_ELEMENT (blockquote), inner_text, NULL);
+
+       inner_html = webkit_dom_html_element_get_inner_html (
+               WEBKIT_DOM_HTML_ELEMENT (blockquote));
+
+       parse_html_into_blocks (
+               view, document,
+               main_blockquote ? blockquote : WEBKIT_DOM_ELEMENT (element),
+               NULL,
+               inner_html);
+
+       if (main_blockquote) {
+               webkit_dom_node_replace_child (
+                       webkit_dom_node_get_parent_node (
+                               WEBKIT_DOM_NODE (main_blockquote)),
+                       WEBKIT_DOM_NODE (blockquote),
+                       WEBKIT_DOM_NODE (main_blockquote),
+                       NULL);
+
+               remove_evolution_attributes (WEBKIT_DOM_ELEMENT (element));
+       } else {
+               WebKitDOMNode *first_child;
+
+               if (signature) {
+                       if (!top_signature) {
+                               signature_clone = webkit_dom_node_append_child (
+                                       WEBKIT_DOM_NODE (element),
+                                       signature_clone,
+                                       NULL);
+                       } else {
+                               webkit_dom_node_insert_before (
+                                       WEBKIT_DOM_NODE (element),
+                                       signature_clone,
+                                       webkit_dom_node_get_first_child (
+                                               WEBKIT_DOM_NODE (element)),
+                                       NULL);
+                       }
+               }
+
+               first_child = webkit_dom_node_get_first_child (
+                       WEBKIT_DOM_NODE (element));
+               if (first_child) {
+                       if (!webkit_dom_node_has_child_nodes (first_child)) {
+                               webkit_dom_html_element_set_inner_html (
+                                       WEBKIT_DOM_HTML_ELEMENT (first_child),
+                                       "<br>",
+                                       NULL);
+                       }
+                       add_selection_markers_into_element_start (
+                               document, WEBKIT_DOM_ELEMENT (first_child), NULL, NULL);
+               }
+       }
+
+       if (wrap)
+               *wrap = TRUE;
+       if (quote)
+               *quote = main_blockquote || blockquotes_count > 0;
+
+       webkit_dom_element_set_attribute (
+               WEBKIT_DOM_ELEMENT (element), "data-converted", "", NULL);
+
+       g_free (inner_text);
+       g_free (inner_html);
+}
+
+static void
 process_elements (EHTMLEditorView *view,
                   WebKitDOMNode *node,
                   gboolean changing_mode,
@@ -9850,6 +9960,8 @@ process_elements (EHTMLEditorView *view,
                                }
                                g_object_unref (list_pre);
 
+                               convert_element_from_html_to_plain_text (
+                                       view, WEBKIT_DOM_ELEMENT (first_child), NULL, NULL);
                                content = webkit_dom_html_element_get_inner_text (
                                        WEBKIT_DOM_HTML_ELEMENT (first_child));
                                g_string_append (buffer, content);
@@ -9863,6 +9975,8 @@ process_elements (EHTMLEditorView *view,
                                g_free (content);
                        }
                        skip_node = TRUE;
+                       if (!to_plain_text && !changing_mode)
+                               skip_node = FALSE;
                        goto next;
                }
 
@@ -10193,7 +10307,8 @@ toggle_paragraphs_style (EHTMLEditorView *view)
 }
 
 static gchar *
-process_content_for_saving_as_draft (EHTMLEditorView *view)
+process_content_for_saving_as_draft (EHTMLEditorView *view,
+                                     gboolean only_inner_body)
 {
        gchar *content;
        gint ii, length;
@@ -10226,8 +10341,29 @@ process_content_for_saving_as_draft (EHTMLEditorView *view)
        }
        g_object_unref (list);
 
-       content = webkit_dom_html_element_get_outer_html (
-               WEBKIT_DOM_HTML_ELEMENT (document_element_clone));
+       list = webkit_dom_element_query_selector_all (
+               WEBKIT_DOM_ELEMENT (document_element_clone), "#-x-evo-input-start", NULL);
+       length = webkit_dom_node_list_get_length (list);
+       for (ii = 0; ii < length; ii++) {
+               WebKitDOMNode *node;
+
+               node = webkit_dom_node_list_item (list, ii);
+               webkit_dom_element_remove_attribute (WEBKIT_DOM_ELEMENT (node), "id");
+               g_object_unref (node);
+       }
+
+       g_object_unref (list);
+
+       if (only_inner_body) {
+               WebKitDOMElement *body;
+
+               body = webkit_dom_element_query_selector (
+                       WEBKIT_DOM_ELEMENT (document_element_clone), "body", NULL);
+               content = webkit_dom_html_element_get_inner_html (
+                       WEBKIT_DOM_HTML_ELEMENT (body));
+       } else
+               content = webkit_dom_html_element_get_outer_html (
+                       WEBKIT_DOM_HTML_ELEMENT (document_element_clone));
 
        webkit_dom_element_remove_attribute (
                WEBKIT_DOM_ELEMENT (body), "data-evo-draft");
@@ -10257,114 +10393,6 @@ process_content_for_mode_change (EHTMLEditorView *view)
        return g_string_free (plain_text, FALSE);
 }
 
-static void
-convert_element_from_html_to_plain_text (EHTMLEditorView *view,
-                                         WebKitDOMElement *element,
-                                         gboolean *wrap,
-                                         gboolean *quote)
-{
-       gint blockquotes_count;
-       gchar *inner_text, *inner_html;
-       WebKitDOMDocument *document;
-       WebKitDOMElement *top_signature, *signature, *blockquote, *main_blockquote;
-       WebKitDOMNode *signature_clone, *from;
-
-       document = webkit_dom_node_get_owner_document (WEBKIT_DOM_NODE (element));
-
-       top_signature = webkit_dom_element_query_selector (
-               element, ".-x-evo-top-signature", NULL);
-       signature = webkit_dom_element_query_selector (
-               element, "span.-x-evo-signature", NULL);
-       main_blockquote = webkit_dom_element_query_selector (
-               element, "#-x-evo-main-cite", NULL);
-
-       blockquote = webkit_dom_document_create_element (
-               document, "blockquote", NULL);
-
-       if (main_blockquote) {
-               webkit_dom_element_set_attribute (
-                       blockquote, "type", "cite", NULL);
-               from = WEBKIT_DOM_NODE (main_blockquote);
-       } else {
-               if (signature) {
-                       WebKitDOMNode *parent = webkit_dom_node_get_parent_node (
-                               WEBKIT_DOM_NODE (signature));
-                       signature_clone = webkit_dom_node_clone_node (parent, TRUE);
-                       remove_node (parent);
-               }
-               from = WEBKIT_DOM_NODE (element);
-       }
-
-       blockquotes_count = create_text_markers_for_citations_in_element (WEBKIT_DOM_ELEMENT (from));
-       create_text_markers_for_selection_in_element (WEBKIT_DOM_ELEMENT (from));
-
-       inner_text = webkit_dom_html_element_get_inner_text (
-               WEBKIT_DOM_HTML_ELEMENT (from));
-
-       webkit_dom_html_element_set_inner_text (
-               WEBKIT_DOM_HTML_ELEMENT (blockquote), inner_text, NULL);
-
-       inner_html = webkit_dom_html_element_get_inner_html (
-               WEBKIT_DOM_HTML_ELEMENT (blockquote));
-
-       parse_html_into_blocks (
-               view, document,
-               main_blockquote ? blockquote : WEBKIT_DOM_ELEMENT (element),
-               NULL,
-               inner_html);
-
-       if (main_blockquote) {
-               webkit_dom_node_replace_child (
-                       webkit_dom_node_get_parent_node (
-                               WEBKIT_DOM_NODE (main_blockquote)),
-                       WEBKIT_DOM_NODE (blockquote),
-                       WEBKIT_DOM_NODE (main_blockquote),
-                       NULL);
-
-               remove_evolution_attributes (WEBKIT_DOM_ELEMENT (element));
-       } else {
-               WebKitDOMNode *first_child;
-
-               if (signature) {
-                       if (!top_signature) {
-                               signature_clone = webkit_dom_node_append_child (
-                                       WEBKIT_DOM_NODE (element),
-                                       signature_clone,
-                                       NULL);
-                       } else {
-                               webkit_dom_node_insert_before (
-                                       WEBKIT_DOM_NODE (element),
-                                       signature_clone,
-                                       webkit_dom_node_get_first_child (
-                                               WEBKIT_DOM_NODE (element)),
-                                       NULL);
-                       }
-               }
-
-               first_child = webkit_dom_node_get_first_child (
-                       WEBKIT_DOM_NODE (element));
-               if (first_child) {
-                       if (!webkit_dom_node_has_child_nodes (first_child)) {
-                               webkit_dom_html_element_set_inner_html (
-                                       WEBKIT_DOM_HTML_ELEMENT (first_child),
-                                       "<br>",
-                                       NULL);
-                       }
-                       add_selection_markers_into_element_start (
-                               document, WEBKIT_DOM_ELEMENT (first_child), NULL, NULL);
-               }
-       }
-
-       *wrap = TRUE;
-       *quote = main_blockquote || blockquotes_count > 0;
-
-       webkit_dom_element_set_attribute (
-               WEBKIT_DOM_ELEMENT (element), "data-converted", "", NULL);
-
-       g_free (inner_text);
-       g_free (inner_html);
-}
-
 static gchar *
 process_content_for_plain_text (EHTMLEditorView *view)
 {
@@ -12052,7 +12080,7 @@ html_editor_view_restore_images (EHTMLEditorView *view,
  * e_html_editor_view_get_text_html:
  * @view: an #EHTMLEditorView:
  *
- * Returns processed HTML content of the editor document (with elements attributes
+ * Returns processed HTML content of the editor document (without elements attributes
  * used in Evolution composer)
  *
  * Returns: A newly allocated string
@@ -12083,15 +12111,30 @@ e_html_editor_view_get_text_html (EHTMLEditorView *view,
  * e_html_editor_view_get_text_html_for_drafts:
  * @view: an #EHTMLEditorView:
  *
- * Returns HTML content of the editor document (without elements attributes
- * used in Evolution composer)
+ * Returns HTML content of the editor document (with elements attributes used in
+ * Evolution composer)
  *
  * Returns: A newly allocated string
  */
 gchar *
 e_html_editor_view_get_text_html_for_drafts (EHTMLEditorView *view)
 {
-       return process_content_for_saving_as_draft (view);
+       return process_content_for_saving_as_draft (view, FALSE);
+}
+
+/**
+ * e_html_editor_view_get_text_html_for_drafts:
+ * @view: an #EHTMLEditorView:
+ *
+ * Returns HTML content of the editor document (with elements attributes used in
+ * Evolution composer)
+ *
+ * Returns: A newly allocated string
+ */
+gchar *
+e_html_editor_view_get_body_text_html_for_drafts (EHTMLEditorView *view)
+{
+       return process_content_for_saving_as_draft (view, TRUE);
 }
 
 /**
@@ -12124,6 +12167,13 @@ e_html_editor_view_convert_and_insert_html_to_plain_text (EHTMLEditorView *view,
        html_editor_view_insert_converted_html_into_selection (view, TRUE, html);
 }
 
+void
+e_html_editor_view_convert_element_from_html_to_plain_text (EHTMLEditorView *view,
+                                                            WebKitDOMElement *element)
+{
+       convert_element_from_html_to_plain_text (view, element, NULL, NULL);
+}
+
 /**
  * e_html_editor_view_set_text_html:
  * @view: an #EHTMLEditorView
diff --git a/e-util/e-html-editor-view.h b/e-util/e-html-editor-view.h
index 93d3ce7..d1f857a 100644
--- a/e-util/e-html-editor-view.h
+++ b/e-util/e-html-editor-view.h
@@ -209,6 +209,8 @@ gchar *             e_html_editor_view_get_text_html
                                                 GList **inline_images);
 gchar *                e_html_editor_view_get_text_html_for_drafts
                                                (EHTMLEditorView *view);
+gchar *                e_html_editor_view_get_body_text_html_for_drafts
+                                               (EHTMLEditorView *view);
 gchar *                e_html_editor_view_get_text_plain
                                                (EHTMLEditorView *view);
 void           e_html_editor_view_convert_and_insert_plain_text
@@ -217,6 +219,9 @@ void                e_html_editor_view_convert_and_insert_plain_text
 void           e_html_editor_view_convert_and_insert_html_to_plain_text
                                                (EHTMLEditorView *view,
                                                 const gchar *html);
+void           e_html_editor_view_convert_element_from_html_to_plain_text
+                                               (EHTMLEditorView *view,
+                                                WebKitDOMElement *element);
 void           e_html_editor_view_set_text_html
                                                (EHTMLEditorView *view,
                                                 const gchar *text);
diff --git a/e-util/e-mail-signature-editor.c b/e-util/e-mail-signature-editor.c
index 1520a6c..52bfcb3 100644
--- a/e-util/e-mail-signature-editor.c
+++ b/e-util/e-mail-signature-editor.c
@@ -831,13 +831,8 @@ e_mail_signature_editor_commit (EMailSignatureEditor *window,
        editor = e_mail_signature_editor_get_editor (window);
        view = e_html_editor_get_view (editor);
 
-       if (e_html_editor_view_get_html_mode (view)) {
-               mime_type = "text/html";
-               contents = e_html_editor_view_get_text_html (view, NULL, NULL);
-       } else {
-               mime_type = "text/plain";
-               contents = e_html_editor_view_get_text_plain (view);
-       }
+       mime_type = "text/html";
+       contents = e_html_editor_view_get_body_text_html_for_drafts (view);
 
        extension_name = E_SOURCE_EXTENSION_MAIL_SIGNATURE;
        extension = e_source_get_extension (source, extension_name);


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