Blame SOURCES/evolution-3.28.5-frame-flattenning.patch

002103
diff -up evolution-3.28.5/data/webview.css.frame-flattenning evolution-3.28.5/data/webview.css
002103
--- evolution-3.28.5/data/webview.css.frame-flattenning	2018-07-30 15:37:05.000000000 +0200
002103
+++ evolution-3.28.5/data/webview.css	2023-01-04 09:25:06.252929132 +0100
002103
@@ -8,8 +8,8 @@ img {
002103
 }
002103
 
002103
 body {
002103
-  /* Use margin so that children can safely use width=100% */
002103
-  margin: 5px 10px 5px 10px;
002103
+  /* Use padding so that children can safely use width=100% */
002103
+  padding: 8px;
002103
 }
002103
 
002103
 th {
002103
@@ -30,21 +30,21 @@ img#__evo-contact-photo {
002103
 
002103
 img.navigable {
002103
   cursor: pointer;
002103
-  margin-right: 4px;
002103
+  padding-right: 4px;
002103
 }
002103
 
002103
 .attachments {
002103
   background: #FFF;
002103
   border: 1px solid silver;
002103
-  margin: 10px 10px 10px 10px;
002103
+  padding: 10px 10px 10px 10px;
002103
   border-left: 0;
002103
   border-right: 0;
002103
   border-bottom: 0;
002103
 }
002103
 
002103
 .attachment {
002103
-  margin-left: 8px;
002103
-  margin-right: 0px;
002103
+  padding-left: 8px;
002103
+  padding-right: 0px;
002103
 }
002103
 
002103
 .attachment td {
002103
@@ -58,21 +58,21 @@ iframe:not([id$=".itip"]) {
002103
 
002103
 .part-container {
002103
   height: 100%;
002103
-  margin-top: 2px;
002103
-  margin-bottom: 2px;
002103
+  padding: 0px;
002103
 }
002103
 
002103
 .part-container-nostyle iframe {
002103
-  margin-right: 10px;
002103
+  margin: 0px;
002103
+  padding: 0px;
002103
 }
002103
 
002103
 .part-container-inner-margin {
002103
-  margin: 8px;
002103
+  padding: 0px;
002103
 }
002103
 
002103
 object { /* GtkWidgets */
002103
-  margin-top: 2px;
002103
-  margin-bottom: 2px;
002103
+  padding-top: 2px;
002103
+  padding-bottom: 2px;
002103
 }
002103
 
002103
 .__evo-highlight {
002103
@@ -139,7 +139,7 @@ th.rtl {
002103
 /***** PRINTING *******/
002103
 
002103
 .printing-header {
002103
-  margin-bottom: 20px;
002103
+  padding-bottom: 20px;
002103
 }
002103
 
002103
 .printing-header h1,
002103
@@ -159,7 +159,7 @@ th.rtl {
002103
 /******* ITIP *********/
002103
 .itip.icon {
002103
   float: left;
002103
-  margin-right: 5px;
002103
+  padding-right: 5px;
002103
 }
002103
 
002103
 .itip.content {
002103
@@ -168,7 +168,7 @@ th.rtl {
002103
 }
002103
 
002103
 .itip.description {
002103
-  margin: 5px;
002103
+  padding: 5px;
002103
 }
002103
 
002103
 .itip tr {
002103
@@ -192,7 +192,7 @@ th.rtl {
002103
 }
002103
 
002103
 #table_row_buttons img {
002103
-  margin-right: 5px;
002103
+  padding-right: 5px;
002103
   vertical-align: middle;
002103
 }
002103
 
002103
diff -up evolution-3.28.5/src/em-format/e-mail-formatter-text-plain.c.frame-flattenning evolution-3.28.5/src/em-format/e-mail-formatter-text-plain.c
002103
--- evolution-3.28.5/src/em-format/e-mail-formatter-text-plain.c.frame-flattenning	2018-07-30 15:37:05.000000000 +0200
002103
+++ evolution-3.28.5/src/em-format/e-mail-formatter-text-plain.c	2023-01-04 09:25:06.252929132 +0100
002103
@@ -111,7 +111,7 @@ emfe_text_plain_format (EMailFormatterEx
002103
 		string =
002103
 			"
002103
 			"-e-web-view-background-color -e-web-view-text-color\" "
002103
-			"style=\"border: none; padding: 8px; margin: 0;\">";
002103
+			"style=\"border: none; padding: 0px; margin: 0;\">";
002103
 
002103
 		g_output_stream_write_all (
002103
 			stream, string, strlen (string),
002103
diff -up evolution-3.28.5/src/mail/e-mail-display.c.frame-flattenning evolution-3.28.5/src/mail/e-mail-display.c
002103
--- evolution-3.28.5/src/mail/e-mail-display.c.frame-flattenning	2018-07-30 15:37:05.000000000 +0200
002103
+++ evolution-3.28.5/src/mail/e-mail-display.c	2023-01-04 09:25:06.252929132 +0100
002103
@@ -1529,6 +1529,19 @@ mail_display_set_fonts (EWebView *web_vi
002103
 	mail_display_get_font_settings (display->priv->settings, monospace, variable);
002103
 }
002103
 
002103
+static gboolean
002103
+mail_display_can_use_frame_flattening (void)
002103
+{
002103
+	guint wk_major, wk_minor;
002103
+
002103
+	wk_major = webkit_get_major_version ();
002103
+	wk_minor = webkit_get_minor_version ();
002103
+
002103
+	/* The 2.38 is the last version, which supports frame-flattening;
002103
+	   prefer it over the manual and expensive calculations. */
002103
+	return (wk_major < 2) || (wk_major == 2 && wk_minor <= 38);
002103
+}
002103
+
002103
 static void
002103
 mail_display_web_view_initialize (WebKitWebView *web_view)
002103
 {
002103
@@ -1536,9 +1549,11 @@ mail_display_web_view_initialize (WebKit
002103
 
002103
 	webkit_settings = webkit_web_view_get_settings (web_view);
002103
 
002103
-	g_object_set (webkit_settings,
002103
-		"enable-frame-flattening", TRUE,
002103
-		NULL);
002103
+	if (mail_display_can_use_frame_flattening ()) {
002103
+		g_object_set (webkit_settings,
002103
+			"enable-frame-flattening", TRUE,
002103
+			NULL);
002103
+	}
002103
 }
002103
 
002103
 static void
002103
diff -up evolution-3.28.5/src/modules/itip-formatter/web-extension/module-itip-formatter-web-extension.c.frame-flattenning evolution-3.28.5/src/modules/itip-formatter/web-extension/module-itip-formatter-web-extension.c
002103
--- evolution-3.28.5/src/modules/itip-formatter/web-extension/module-itip-formatter-web-extension.c.frame-flattenning	2018-07-30 15:37:05.000000000 +0200
002103
+++ evolution-3.28.5/src/modules/itip-formatter/web-extension/module-itip-formatter-web-extension.c	2023-01-04 09:25:06.253929132 +0100
002103
@@ -259,7 +259,7 @@ handle_method_call (GDBusConnection *con
002103
                     gpointer user_data)
002103
 {
002103
 	WebKitWebExtension *web_extension = WEBKIT_WEB_EXTENSION (user_data);
002103
-	WebKitDOMDocument *document;
002103
+	WebKitDOMDocument *document = NULL, *top_document = NULL;
002103
 	const gchar *part_id = NULL;
002103
 	guint64 page_id;
002103
 
002103
@@ -281,11 +281,12 @@ handle_method_call (GDBusConnection *con
002103
 
002103
 		g_variant_get (parameters, "(t&s&s)", &page_id, &part_id, &button_id);
002103
 
002103
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
-		if (document)
002103
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
002103
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
+		if (top_document)
002103
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
002103
 		if (document) {
002103
 			module_itip_formatter_dom_utils_show_button (document, button_id);
002103
+			e_dom_update_iframe_height (top_document);
002103
 			g_dbus_method_invocation_return_value (invocation, NULL);
002103
 		}
002103
 	} else if (g_strcmp0 (method_name, "EnableButton") == 0) {
002103
@@ -306,11 +307,12 @@ handle_method_call (GDBusConnection *con
002103
 
002103
 		g_variant_get (parameters, "(t&s&s&s)", &page_id, &part_id, &element_id, &inner_html);
002103
 
002103
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
-		if (document)
002103
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
002103
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
+		if (top_document)
002103
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
002103
 		if (document) {
002103
 			e_dom_utils_element_set_inner_html (document, element_id, inner_html);
002103
+			e_dom_update_iframe_height (top_document);
002103
 			g_dbus_method_invocation_return_value (invocation, NULL);
002103
 		}
002103
 	} else if (g_strcmp0 (method_name, "RemoveElement") == 0) {
002103
@@ -318,11 +320,12 @@ handle_method_call (GDBusConnection *con
002103
 
002103
 		g_variant_get (parameters, "(t&s&s)", &page_id, &part_id, &element_id);
002103
 
002103
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
-		if (document)
002103
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
002103
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
+		if (top_document)
002103
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
002103
 		if (document) {
002103
 			e_dom_utils_remove_element (document, element_id);
002103
+			e_dom_update_iframe_height (top_document);
002103
 			g_dbus_method_invocation_return_value (invocation, NULL);
002103
 		}
002103
 	} else if (g_strcmp0 (method_name, "ElementRemoveChildNodes") == 0) {
002103
@@ -330,11 +333,12 @@ handle_method_call (GDBusConnection *con
002103
 
002103
 		g_variant_get (parameters, "(t&s&s)", &page_id, &part_id, &element_id);
002103
 
002103
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
-		if (document)
002103
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
002103
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
+		if (top_document)
002103
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
002103
 		if (document) {
002103
 			e_dom_utils_element_remove_child_nodes (document, element_id);
002103
+			e_dom_update_iframe_height (top_document);
002103
 			g_dbus_method_invocation_return_value (invocation, NULL);
002103
 		}
002103
 	} else if (g_strcmp0 (method_name, "HideElement") == 0) {
002103
@@ -343,11 +347,12 @@ handle_method_call (GDBusConnection *con
002103
 
002103
 		g_variant_get (parameters, "(t&s&sb)", &page_id, &part_id, &element_id, &hide);
002103
 
002103
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
-		if (document)
002103
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
002103
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
+		if (top_document)
002103
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
002103
 		if (document) {
002103
 			e_dom_utils_hide_element (document, element_id, hide);
002103
+			e_dom_update_iframe_height (top_document);
002103
 			g_dbus_method_invocation_return_value (invocation, NULL);
002103
 		}
002103
 	} else if (g_strcmp0 (method_name, "ElementIsHidden") == 0) {
002103
@@ -395,11 +400,12 @@ handle_method_call (GDBusConnection *con
002103
 
002103
 		g_variant_get (parameters, "(t&s&sbb)", &page_id, &part_id, &id, &show, &update_second);
002103
 
002103
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
-		if (document)
002103
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
002103
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
+		if (top_document)
002103
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
002103
 		if (document) {
002103
 			module_itip_formatter_dom_utils_show_checkbox (document, id, show, update_second);
002103
+			e_dom_update_iframe_height (top_document);
002103
 			g_dbus_method_invocation_return_value (invocation, NULL);
002103
 		}
002103
 	} else if (g_strcmp0 (method_name, "SetButtonsSensitive") == 0) {
002103
@@ -419,11 +425,12 @@ handle_method_call (GDBusConnection *con
002103
 
002103
 		g_variant_get (parameters, "(t&s&s&s)", &page_id, &part_id, &id, &text);
002103
 
002103
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
-		if (document)
002103
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
002103
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
+		if (top_document)
002103
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
002103
 		if (document) {
002103
 			module_itip_formatter_dom_utils_set_area_text (document, id, text);
002103
+			e_dom_update_iframe_height (top_document);
002103
 			g_dbus_method_invocation_return_value (invocation, NULL);
002103
 		}
002103
 	} else if (g_strcmp0 (method_name, "ElementSetAccessKey") == 0) {
002103
@@ -443,11 +450,12 @@ handle_method_call (GDBusConnection *con
002103
 
002103
 		g_variant_get (parameters, "(t&s&s)", &page_id, &part_id, &element_id);
002103
 
002103
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
-		if (document)
002103
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
002103
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
+		if (top_document)
002103
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
002103
 		if (document) {
002103
 			module_itip_formatter_dom_utils_element_hide_child_nodes (document, element_id);
002103
+			e_dom_update_iframe_height (top_document);
002103
 			g_dbus_method_invocation_return_value (invocation, NULL);
002103
 		}
002103
 	} else if (g_strcmp0 (method_name, "EnableSelect") == 0) {
002103
@@ -509,11 +517,12 @@ handle_method_call (GDBusConnection *con
002103
 
002103
 		g_variant_get (parameters, "(t&s&s&s&s)", &page_id, &part_id, &element_id, &header, &label);
002103
 
002103
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
-		if (document)
002103
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
002103
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
+		if (top_document)
002103
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
002103
 		if (document) {
002103
 			module_itip_formatter_dom_utils_update_times (document, element_id, header, label);
002103
+			e_dom_update_iframe_height (top_document);
002103
 			g_dbus_method_invocation_return_value (invocation, NULL);
002103
 		}
002103
 	} else if (g_strcmp0 (method_name, "AppendInfoItemRow") == 0) {
002103
@@ -521,11 +530,12 @@ handle_method_call (GDBusConnection *con
002103
 
002103
 		g_variant_get (parameters, "(t&s&s&s&s&s)", &page_id, &part_id, &table_id, &row_id, &icon_name, &message);
002103
 
002103
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
-		if (document)
002103
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
002103
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
+		if (top_document)
002103
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
002103
 		if (document) {
002103
 			module_itip_formatter_dom_utils_append_info_item_row (document, table_id, row_id, icon_name, message);
002103
+			e_dom_update_iframe_height (top_document);
002103
 			g_dbus_method_invocation_return_value (invocation, NULL);
002103
 		}
002103
 	} else if (g_strcmp0 (method_name, "EnableTextArea") == 0) {
002103
@@ -546,11 +556,12 @@ handle_method_call (GDBusConnection *con
002103
 
002103
 		g_variant_get (parameters, "(t&s&s&s)", &page_id, &part_id, &area_id, &value);
002103
 
002103
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
-		if (document)
002103
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
002103
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
002103
+		if (top_document)
002103
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
002103
 		if (document) {
002103
 			module_itip_formatter_dom_utils_text_area_set_value (document, area_id, value);
002103
+			e_dom_update_iframe_height (top_document);
002103
 			g_dbus_method_invocation_return_value (invocation, NULL);
002103
 		}
002103
 	} else if (g_strcmp0 (method_name, "TextAreaGetValue") == 0) {
002103
diff -up evolution-3.28.5/src/modules/text-highlight/e-mail-formatter-text-highlight.c.frame-flattenning evolution-3.28.5/src/modules/text-highlight/e-mail-formatter-text-highlight.c
002103
--- evolution-3.28.5/src/modules/text-highlight/e-mail-formatter-text-highlight.c.frame-flattenning	2018-07-30 15:37:05.000000000 +0200
002103
+++ evolution-3.28.5/src/modules/text-highlight/e-mail-formatter-text-highlight.c	2023-01-04 09:25:06.252929132 +0100
002103
@@ -122,16 +122,26 @@ text_hightlight_read_data_thread (gpoint
002103
 {
002103
 	TextHighlightClosure *closure = user_data;
002103
 	gint nbuffer = 10240;
002103
+	gssize read;
002103
+	gsize wrote = 0;
002103
 	gchar *buffer;
002103
 
002103
 	g_return_val_if_fail (closure != NULL, NULL);
002103
 
002103
 	buffer = g_new (gchar, nbuffer);
002103
 
002103
+	strcpy (buffer, "<style>body{margin:0; padding:8px;}</style>");
002103
+	read = strlen (buffer);
002103
+
002103
+	if (!g_output_stream_write_all (closure->output_stream, buffer, read, &wrote, closure->cancellable, &closure->error) ||
002103
+	    (gssize) wrote != read || closure->error) {
002103
+		g_free (buffer);
002103
+		return NULL;
002103
+	}
002103
+
002103
 	while (!camel_stream_eos (closure->read_stream) &&
002103
 	       !g_cancellable_set_error_if_cancelled (closure->cancellable, &closure->error)) {
002103
-		gssize read;
002103
-		gsize wrote = 0;
002103
+		wrote = 0;
002103
 
002103
 		read = camel_stream_read (closure->read_stream, buffer, nbuffer, closure->cancellable, &closure->error);
002103
 		if (read < 0 || closure->error)
002103
diff -up evolution-3.28.5/src/web-extensions/e-dom-utils.c.frame-flattenning evolution-3.28.5/src/web-extensions/e-dom-utils.c
002103
--- evolution-3.28.5/src/web-extensions/e-dom-utils.c.frame-flattenning	2018-07-30 15:37:05.000000000 +0200
002103
+++ evolution-3.28.5/src/web-extensions/e-dom-utils.c	2023-01-04 09:25:06.253929132 +0100
002103
@@ -837,9 +837,8 @@ set_iframe_and_body_width (WebKitDOMDocu
002103
 		gchar *style;
002103
 
002103
 		/* Message main body */
002103
-		local_width -= 8; /* 8 + 8 margins of body without iframes */
002103
-		if (level > 1)
002103
-			local_width -= 8;
002103
+		local_width -= level * 20; /* 10 + 10 margins of body without iframes */
002103
+		local_width -= 4;
002103
 
002103
 		style = g_strdup_printf ("width: %" G_GINT64_FORMAT "px;", local_width);
002103
 		e_dom_utils_add_css_rule_into_style_sheet_in_document (
002103
@@ -867,7 +866,7 @@ set_iframe_and_body_width (WebKitDOMDocu
002103
 			style);
002103
 		g_free (style);
002103
 
002103
-		local_width -= 2; /* 1 + 1 frame borders */
002103
+		local_width -= 4; /* 2 + 2 frame borders */
002103
 
002103
 		style = g_strdup_printf ("width: %" G_GINT64_FORMAT "px;", local_width);
002103
 		e_dom_utils_add_css_rule_into_style_sheet_in_document (
002103
@@ -891,15 +890,11 @@ set_iframe_and_body_width (WebKitDOMDocu
002103
 	} else {
002103
 		gchar *style;
002103
 
002103
-		local_width -= 20; /* 10 + 10 margins of body with iframes */
002103
-		local_width -= 8; /* attachment margin */
002103
-		local_width -= 2; /* 1 + 1 frame borders */
002103
+		local_width -= (level - 1) * 20; /* 10 + 10 margins of body with iframes */
002103
+		local_width -= 4; /* 2 + 2 frame borders */
002103
+		local_width -= 10; /* attachment margin */
002103
 
002103
-		/* We need to subtract another 10 pixels from the iframe width to
002103
-		 * have the iframe's borders on the correct place. We can't subtract
002103
-		 * it from local_width as we don't want to propagate this change
002103
-		 * further. */
002103
-		style = g_strdup_printf ("width: %" G_GINT64_FORMAT "px;", local_width - 10);
002103
+		style = g_strdup_printf ("width: %" G_GINT64_FORMAT "px;", local_width);
002103
 		e_dom_utils_add_css_rule_into_style_sheet_in_document (
002103
 			document,
002103
 			"-e-mail-formatter-style-sheet",
002103
@@ -933,7 +928,7 @@ set_iframe_and_body_width (WebKitDOMDocu
002103
 		if (level == 0) {
002103
 			gchar *style = NULL;
002103
 
002103
-			tmp_local_width -= 8; /* attachment's margin */
002103
+			tmp_local_width -= 10; /* attachment's margin */
002103
 
002103
 			style = g_strdup_printf ("width: %" G_GINT64_FORMAT "px;", tmp_local_width);
002103
 			e_dom_utils_add_css_rule_into_style_sheet_in_document (
002103
@@ -947,9 +942,7 @@ set_iframe_and_body_width (WebKitDOMDocu
002103
 				"-e-mail-formatter-style-sheet",
002103
 				".attachment-wrapper iframe[src*=\"__formatas=txt\"]",
002103
 				style);
002103
-			g_free (style);
002103
 
002103
-			style = g_strdup_printf ("width: %" G_GINT64_FORMAT "px;", local_width);
002103
 			e_dom_utils_add_css_rule_into_style_sheet_in_document (
002103
 				document,
002103
 				"-e-mail-formatter-style-sheet",
002103
@@ -992,8 +985,10 @@ dom_window_resize_cb (WebKitDOMDOMWindow
002103
 
002103
 	document = webkit_dom_dom_window_get_document (dom_window);
002103
 
002103
-	if (document)
002103
+	if (document) {
002103
 		e_dom_resize_document_content_to_preview_width (document);
002103
+		e_dom_update_iframe_height (document);
002103
+	}
002103
 }
002103
 
002103
 static gboolean
002103
@@ -1106,6 +1101,7 @@ e_dom_utils_e_mail_display_bind_dom (Web
002103
 	e_dom_wrap_long_anchors (document);
002103
 
002103
 	e_dom_resize_document_content_to_preview_width (document);
002103
+	e_dom_update_iframe_height (document);
002103
 }
002103
 
002103
 void
002103
@@ -1160,6 +1156,99 @@ e_dom_utils_e_mail_display_unstyle_block
002103
 	g_clear_object (&collection);
002103
 }
002103
 
002103
+static void
002103
+e_dom_update_iframe_height_recursive (WebKitDOMDocument *document)
002103
+{
002103
+	WebKitDOMHTMLCollection *frames = NULL;
002103
+	WebKitDOMElement *scrolling_elem;
002103
+	gulong ii, length;
002103
+
002103
+	frames = webkit_dom_document_get_elements_by_tag_name_as_html_collection (document, "iframe");
002103
+	length = webkit_dom_html_collection_get_length (frames);
002103
+	for (ii = 0; ii < length; ii++) {
002103
+		WebKitDOMHTMLIFrameElement *iframe;
002103
+		WebKitDOMDocument *content_document;
002103
+
002103
+		iframe = WEBKIT_DOM_HTML_IFRAME_ELEMENT (webkit_dom_html_collection_item (frames, ii));
002103
+
002103
+		content_document = webkit_dom_html_iframe_element_get_content_document (iframe);
002103
+		if (!content_document)
002103
+			continue;
002103
+
002103
+		e_dom_update_iframe_height_recursive (content_document);
002103
+	}
002103
+
002103
+	scrolling_elem = webkit_dom_document_get_scrolling_element (document);
002103
+	if (scrolling_elem) {
002103
+		WebKitDOMDOMWindow *default_view;
002103
+
002103
+		default_view = webkit_dom_document_get_default_view (document);
002103
+		if (default_view) {
002103
+			WebKitDOMElement *frame_elem;
002103
+
002103
+			frame_elem = webkit_dom_dom_window_get_frame_element (default_view);
002103
+			if (frame_elem) {
002103
+				WebKitDOMHTMLIFrameElement *iframe = WEBKIT_DOM_HTML_IFRAME_ELEMENT (frame_elem);
002103
+				glong scroll_height;
002103
+				gchar *height;
002103
+
002103
+				scroll_height = webkit_dom_element_get_scroll_height (scrolling_elem);
002103
+				height = webkit_dom_html_iframe_element_get_height (iframe);
002103
+				if (!height || scroll_height == (glong) g_ascii_strtoll (height, NULL, 10))
002103
+					webkit_dom_html_iframe_element_set_height (iframe, "10");
002103
+				g_free (height);
002103
+
002103
+				scroll_height = webkit_dom_element_get_scroll_height (scrolling_elem);
002103
+				height = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64) (scroll_height + 2 +
002103
+					(webkit_dom_element_get_scroll_width (scrolling_elem) > webkit_dom_element_get_client_width (scrolling_elem) ? 20 : 0)));
002103
+				webkit_dom_html_iframe_element_set_height (iframe, height);
002103
+				g_free (height);
002103
+			}
002103
+		}
002103
+
002103
+		g_clear_object (&default_view);
002103
+	}
002103
+
002103
+	g_clear_object (&frames);
002103
+}
002103
+
002103
+static gboolean
002103
+mail_display_can_use_frame_flattening (void)
002103
+{
002103
+	guint wk_major, wk_minor;
002103
+
002103
+	wk_major = webkit_get_major_version ();
002103
+	wk_minor = webkit_get_minor_version ();
002103
+
002103
+	/* The 2.38 is the last version, which supports frame-flattening;
002103
+	   prefer it over the manual and expensive calculations. */
002103
+	return (wk_major < 2) || (wk_major == 2 && wk_minor <= 38);
002103
+}
002103
+
002103
+void
002103
+e_dom_update_iframe_height (WebKitDOMDocument *document)
002103
+{
002103
+	WebKitDOMDOMWindow *default_view;
002103
+
002103
+	if (mail_display_can_use_frame_flattening ())
002103
+		return;
002103
+
002103
+	default_view = webkit_dom_document_get_default_view (document);
002103
+	if (default_view) {
002103
+		glong scroll_x, scroll_y;
002103
+
002103
+		scroll_x = webkit_dom_dom_window_get_scroll_x (default_view);
002103
+		scroll_y = webkit_dom_dom_window_get_scroll_y (default_view);
002103
+
002103
+		e_dom_update_iframe_height_recursive (document);
002103
+
002103
+		if (scroll_y != webkit_dom_dom_window_get_scroll_y (default_view))
002103
+			webkit_dom_dom_window_scroll_to (default_view, scroll_x, scroll_y);
002103
+	}
002103
+
002103
+	g_clear_object (&default_view);
002103
+}
002103
+
002103
 void
002103
 e_dom_utils_eab_contact_formatter_bind_dom (WebKitDOMDocument *document)
002103
 {
002103
diff -up evolution-3.28.5/src/web-extensions/e-dom-utils.h.frame-flattenning evolution-3.28.5/src/web-extensions/e-dom-utils.h
002103
--- evolution-3.28.5/src/web-extensions/e-dom-utils.h.frame-flattenning	2018-07-30 15:37:05.000000000 +0200
002103
+++ evolution-3.28.5/src/web-extensions/e-dom-utils.h	2023-01-04 09:25:06.253929132 +0100
002103
@@ -69,6 +69,7 @@ void		e_dom_utils_e_mail_display_bind_do
002103
 						 GDBusConnection *connection);
002103
 void		e_dom_utils_e_mail_display_unstyle_blockquotes
002103
 						(WebKitDOMDocument *document);
002103
+void		e_dom_update_iframe_height	(WebKitDOMDocument *document);
002103
 WebKitDOMElement *
002103
 		e_dom_utils_find_element_by_selector
002103
 						(WebKitDOMDocument *document,
002103
diff -up evolution-3.28.5/src/web-extensions/e-web-extension.c.frame-flattenning evolution-3.28.5/src/web-extensions/e-web-extension.c
002103
--- evolution-3.28.5/src/web-extensions/e-web-extension.c.frame-flattenning	2018-07-30 15:37:05.000000000 +0200
002103
+++ evolution-3.28.5/src/web-extensions/e-web-extension.c	2023-01-04 09:25:06.253929132 +0100
002103
@@ -613,8 +613,10 @@ handle_method_call (GDBusConnection *con
002103
 
002103
 			e_dom_utils_hide_element (document, element_id, hidden);
002103
 
002103
-			if (expand_inner_data)
002103
+			if (expand_inner_data) {
002103
 				e_dom_resize_document_content_to_preview_width (document);
002103
+				e_dom_update_iframe_height (document);
002103
+			}
002103
 		}
002103
 
002103
 		g_dbus_method_invocation_return_value (invocation, NULL);