diff -urp evolution-3.22.6.orig/data/webview.css evolution-3.22.6/data/webview.css
--- evolution-3.22.6.orig/data/webview.css	2014-07-17 05:47:57.000000000 -0500
+++ evolution-3.22.6/data/webview.css	2023-07-14 14:47:32.049855403 -0500
@@ -8,8 +8,8 @@ img {
 }
 
 body {
-  /* Use margin so that children can safely use width=100% */
-  margin: 10px;
+  /* Use padding so that children can safely use width=100% */
+  padding: 8px;
 }
 
 th {
@@ -30,21 +30,21 @@ img#__evo-contact-photo {
 
 img.navigable {
   cursor: pointer;
-  margin-right: 4px;
+  padding-right: 4px;
 }
 
 .attachments {
   background: #FFF;
   border: 1px solid silver;
-  margin: 10px 10px 10px 10px;
+  padding: 10px 10px 10px 10px;
   border-left: 0;
   border-right: 0;
   border-bottom: 0;
 }
 
 .attachment {
-  margin-left: 8px;
-  margin-right: 8px;
+  padding-left: 8px;
+  padding-right: 8px;
 }
 
 .attachment-wrapper
@@ -54,20 +54,19 @@ img.navigable {
 
 .part-container {
   height: 100%;
-  margin-top: 2px;
-  margin-bottom: 3px;
+  padding: 0px;
   border-width: 1px;
   border-style: solid;
   right: 0;
 }
 
 .part-container-inner-margin {
-  margin: 8px;
+  padding: 0px;
 }
 
 object { /* GtkWidgets */
-  margin-top: 2px;
-  margin-bottom: 2px;
+  padding-top: 2px;
+  padding-bottom: 2px;
 }
 
 .__evo-highlight {
@@ -127,7 +126,7 @@ th.rtl {
 /***** PRINTING *******/
 
 .printing-header {
-  margin-bottom: 20px;
+  padding-bottom: 20px;
 }
 
 .printing-header h1,
@@ -147,7 +146,7 @@ th.rtl {
 /******* ITIP *********/
 .itip.icon {
   float: left;
-  margin-right: 5px;
+  padding-right: 5px;
 }
 
 .itip.content {
@@ -156,7 +155,7 @@ th.rtl {
 }
 
 .itip.description {
-  margin: 5px;
+  padding: 5px;
 }
 
 .itip tr {
@@ -180,7 +179,7 @@ th.rtl {
 }
 
 #table_row_buttons img {
-  margin-right: 5px;
+  padding-right: 5px;
   vertical-align: middle;
 }
 
diff -urp evolution-3.22.6.orig/em-format/e-mail-formatter-text-plain.c evolution-3.22.6/em-format/e-mail-formatter-text-plain.c
--- evolution-3.22.6.orig/em-format/e-mail-formatter-text-plain.c	2015-03-23 02:12:18.000000000 -0500
+++ evolution-3.22.6/em-format/e-mail-formatter-text-plain.c	2023-07-14 14:47:32.049855403 -0500
@@ -113,7 +113,7 @@ emfe_text_plain_format (EMailFormatterEx
 		string =
 			"<div class=\"part-container pre "
 			"-e-web-view-background-color -e-web-view-text-color\" "
-			"style=\"border: none; padding: 8px; margin: 0;\">";
+			"style=\"border: none; padding: 0px; margin: 0;\">";
 
 		g_output_stream_write_all (
 			stream, string, strlen (string),
diff -urp evolution-3.22.6.orig/mail/e-mail-display.c evolution-3.22.6/mail/e-mail-display.c
--- evolution-3.22.6.orig/mail/e-mail-display.c	2016-12-15 07:58:14.000000000 -0600
+++ evolution-3.22.6/mail/e-mail-display.c	2023-07-14 14:47:32.049855403 -0500
@@ -1521,6 +1521,19 @@ mail_display_set_fonts (EWebView *web_vi
 	mail_display_get_font_settings (display->priv->settings, monospace, variable);
 }
 
+static gboolean
+mail_display_can_use_frame_flattening (void)
+{
+	guint wk_major, wk_minor;
+
+	wk_major = webkit_get_major_version ();
+	wk_minor = webkit_get_minor_version ();
+
+	/* The 2.38 is the last version, which supports frame-flattening;
+	   prefer it over the manual and expensive calculations. */
+	return (wk_major < 2) || (wk_major == 2 && wk_minor <= 38);
+}
+
 static void
 mail_display_web_view_initialize (WebKitWebView *web_view)
 {
@@ -1528,9 +1541,11 @@ mail_display_web_view_initialize (WebKit
 
 	webkit_settings = webkit_web_view_get_settings (web_view);
 
-	g_object_set (webkit_settings,
-		"enable-frame-flattening", TRUE,
-		NULL);
+	if (mail_display_can_use_frame_flattening ()) {
+		g_object_set (webkit_settings,
+			"enable-frame-flattening", TRUE,
+			NULL);
+	}
 }
 
 static void
diff -urp evolution-3.22.6.orig/modules/itip-formatter/web-extension/module-itip-formatter-web-extension.c evolution-3.22.6/modules/itip-formatter/web-extension/module-itip-formatter-web-extension.c
--- evolution-3.22.6.orig/modules/itip-formatter/web-extension/module-itip-formatter-web-extension.c	2016-09-19 03:22:58.000000000 -0500
+++ evolution-3.22.6/modules/itip-formatter/web-extension/module-itip-formatter-web-extension.c	2023-07-14 14:47:32.053855424 -0500
@@ -259,7 +259,7 @@ handle_method_call (GDBusConnection *con
                     gpointer user_data)
 {
 	WebKitWebExtension *web_extension = WEBKIT_WEB_EXTENSION (user_data);
-	WebKitDOMDocument *document;
+	WebKitDOMDocument *document = NULL, *top_document = NULL;
 	const gchar *part_id = NULL;
 	guint64 page_id;
 
@@ -281,11 +281,12 @@ handle_method_call (GDBusConnection *con
 
 		g_variant_get (parameters, "(t&s&s)", &page_id, &part_id, &button_id);
 
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
-		if (document)
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
+		if (top_document)
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
 		if (document) {
 			module_itip_formatter_dom_utils_show_button (document, button_id);
+			e_dom_update_iframe_height (top_document);
 			g_dbus_method_invocation_return_value (invocation, NULL);
 		}
 	} else if (g_strcmp0 (method_name, "EnableButton") == 0) {
@@ -306,11 +307,12 @@ handle_method_call (GDBusConnection *con
 
 		g_variant_get (parameters, "(t&s&s&s)", &page_id, &part_id, &element_id, &inner_html);
 
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
-		if (document)
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
+		if (top_document)
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
 		if (document) {
 			e_dom_utils_element_set_inner_html (document, element_id, inner_html);
+			e_dom_update_iframe_height (top_document);
 			g_dbus_method_invocation_return_value (invocation, NULL);
 		}
 	} else if (g_strcmp0 (method_name, "RemoveElement") == 0) {
@@ -318,11 +320,12 @@ handle_method_call (GDBusConnection *con
 
 		g_variant_get (parameters, "(t&s&s)", &page_id, &part_id, &element_id);
 
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
-		if (document)
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
+		if (top_document)
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
 		if (document) {
 			e_dom_utils_remove_element (document, element_id);
+			e_dom_update_iframe_height (top_document);
 			g_dbus_method_invocation_return_value (invocation, NULL);
 		}
 	} else if (g_strcmp0 (method_name, "ElementRemoveChildNodes") == 0) {
@@ -330,11 +333,12 @@ handle_method_call (GDBusConnection *con
 
 		g_variant_get (parameters, "(t&s&s)", &page_id, &part_id, &element_id);
 
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
-		if (document)
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
+		if (top_document)
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
 		if (document) {
 			e_dom_utils_element_remove_child_nodes (document, element_id);
+			e_dom_update_iframe_height (top_document);
 			g_dbus_method_invocation_return_value (invocation, NULL);
 		}
 	} else if (g_strcmp0 (method_name, "HideElement") == 0) {
@@ -343,11 +347,12 @@ handle_method_call (GDBusConnection *con
 
 		g_variant_get (parameters, "(t&s&sb)", &page_id, &part_id, &element_id, &hide);
 
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
-		if (document)
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
+		if (top_document)
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
 		if (document) {
 			e_dom_utils_hide_element (document, element_id, hide);
+			e_dom_update_iframe_height (top_document);
 			g_dbus_method_invocation_return_value (invocation, NULL);
 		}
 	} else if (g_strcmp0 (method_name, "ElementIsHidden") == 0) {
@@ -395,11 +400,12 @@ handle_method_call (GDBusConnection *con
 
 		g_variant_get (parameters, "(t&s&sbb)", &page_id, &part_id, &id, &show, &update_second);
 
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
-		if (document)
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
+		if (top_document)
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
 		if (document) {
 			module_itip_formatter_dom_utils_show_checkbox (document, id, show, update_second);
+			e_dom_update_iframe_height (top_document);
 			g_dbus_method_invocation_return_value (invocation, NULL);
 		}
 	} else if (g_strcmp0 (method_name, "SetButtonsSensitive") == 0) {
@@ -419,11 +425,12 @@ handle_method_call (GDBusConnection *con
 
 		g_variant_get (parameters, "(t&s&s&s)", &page_id, &part_id, &id, &text);
 
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
-		if (document)
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
+		if (top_document)
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
 		if (document) {
 			module_itip_formatter_dom_utils_set_area_text (document, id, text);
+			e_dom_update_iframe_height (top_document);
 			g_dbus_method_invocation_return_value (invocation, NULL);
 		}
 	} else if (g_strcmp0 (method_name, "ElementSetAccessKey") == 0) {
@@ -443,11 +450,12 @@ handle_method_call (GDBusConnection *con
 
 		g_variant_get (parameters, "(t&s&s)", &page_id, &part_id, &element_id);
 
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
-		if (document)
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
+		if (top_document)
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
 		if (document) {
 			module_itip_formatter_dom_utils_element_hide_child_nodes (document, element_id);
+			e_dom_update_iframe_height (top_document);
 			g_dbus_method_invocation_return_value (invocation, NULL);
 		}
 	} else if (g_strcmp0 (method_name, "EnableSelect") == 0) {
@@ -509,11 +517,12 @@ handle_method_call (GDBusConnection *con
 
 		g_variant_get (parameters, "(t&s&s&s&s)", &page_id, &part_id, &element_id, &header, &label);
 
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
-		if (document)
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
+		if (top_document)
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
 		if (document) {
 			module_itip_formatter_dom_utils_update_times (document, element_id, header, label);
+			e_dom_update_iframe_height (top_document);
 			g_dbus_method_invocation_return_value (invocation, NULL);
 		}
 	} else if (g_strcmp0 (method_name, "AppendInfoItemRow") == 0) {
@@ -521,11 +530,12 @@ handle_method_call (GDBusConnection *con
 
 		g_variant_get (parameters, "(t&s&s&s&s&s)", &page_id, &part_id, &table_id, &row_id, &icon_name, &message);
 
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
-		if (document)
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
+		if (top_document)
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
 		if (document) {
 			module_itip_formatter_dom_utils_append_info_item_row (document, table_id, row_id, icon_name, message);
+			e_dom_update_iframe_height (top_document);
 			g_dbus_method_invocation_return_value (invocation, NULL);
 		}
 	} else if (g_strcmp0 (method_name, "EnableTextArea") == 0) {
@@ -546,11 +556,12 @@ handle_method_call (GDBusConnection *con
 
 		g_variant_get (parameters, "(t&s&s&s)", &page_id, &part_id, &area_id, &value);
 
-		document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
-		if (document)
-			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, document, part_id);
+		top_document = get_webkit_document_or_return_dbus_error (invocation, web_extension, page_id);
+		if (top_document)
+			document = find_webkit_document_for_partid_or_return_dbus_error (invocation, top_document, part_id);
 		if (document) {
 			module_itip_formatter_dom_utils_text_area_set_value (document, area_id, value);
+			e_dom_update_iframe_height (top_document);
 			g_dbus_method_invocation_return_value (invocation, NULL);
 		}
 	} else if (g_strcmp0 (method_name, "TextAreaGetValue") == 0) {
diff -urp evolution-3.22.6.orig/modules/text-highlight/e-mail-formatter-text-highlight.c evolution-3.22.6/modules/text-highlight/e-mail-formatter-text-highlight.c
--- evolution-3.22.6.orig/modules/text-highlight/e-mail-formatter-text-highlight.c	2015-03-23 02:12:18.000000000 -0500
+++ evolution-3.22.6/modules/text-highlight/e-mail-formatter-text-highlight.c	2023-07-14 14:47:32.053855424 -0500
@@ -122,14 +122,23 @@ static gpointer
 text_hightlight_read_data_thread (gpointer user_data)
 {
 	TextHighlightClosure *closure = user_data;
+	gssize read;
+	gsize wrote = 0;
 	gchar buffer[10240];
 
 	g_return_val_if_fail (closure != NULL, NULL);
 
+	strcpy (buffer, "<style>body{margin:0; padding:8px;}</style>");
+	read = strlen (buffer);
+
+	if (!g_output_stream_write_all (closure->output_stream, buffer, read, &wrote, closure->cancellable, &closure->error) ||
+	    (gssize) wrote != read || closure->error) {
+		return NULL;
+	}
+
 	while (!camel_stream_eos (closure->read_stream) &&
 	       !g_cancellable_set_error_if_cancelled (closure->cancellable, &closure->error)) {
-		gssize read;
-		gsize wrote = 0;
+		wrote = 0;
 
 		read = camel_stream_read (closure->read_stream, buffer, 10240, closure->cancellable, &closure->error);
 		if (read < 0 || closure->error)
diff -urp evolution-3.22.6.orig/web-extensions/e-dom-utils.c evolution-3.22.6/web-extensions/e-dom-utils.c
--- evolution-3.22.6.orig/web-extensions/e-dom-utils.c	2016-12-05 13:10:07.000000000 -0600
+++ evolution-3.22.6/web-extensions/e-dom-utils.c	2023-07-14 14:49:34.722503023 -0500
@@ -824,6 +824,99 @@ e_dom_utils_e_mail_display_bind_dom (Web
 		connection);
 }
 
+static void
+e_dom_update_iframe_height_recursive (WebKitDOMDocument *document)
+{
+	WebKitDOMHTMLCollection *frames = NULL;
+	WebKitDOMElement *scrolling_elem;
+	gulong ii, length;
+
+	frames = webkit_dom_document_get_elements_by_tag_name_as_html_collection (document, "iframe");
+	length = webkit_dom_html_collection_get_length (frames);
+	for (ii = 0; ii < length; ii++) {
+		WebKitDOMHTMLIFrameElement *iframe;
+		WebKitDOMDocument *content_document;
+
+		iframe = WEBKIT_DOM_HTML_IFRAME_ELEMENT (webkit_dom_html_collection_item (frames, ii));
+
+		content_document = webkit_dom_html_iframe_element_get_content_document (iframe);
+		if (!content_document)
+			continue;
+
+		e_dom_update_iframe_height_recursive (content_document);
+	}
+
+	scrolling_elem = webkit_dom_document_get_scrolling_element (document);
+	if (scrolling_elem) {
+		WebKitDOMDOMWindow *default_view;
+
+		default_view = webkit_dom_document_get_default_view (document);
+		if (default_view) {
+			WebKitDOMElement *frame_elem;
+
+			frame_elem = webkit_dom_dom_window_get_frame_element (default_view);
+			if (frame_elem) {
+				WebKitDOMHTMLIFrameElement *iframe = WEBKIT_DOM_HTML_IFRAME_ELEMENT (frame_elem);
+				glong scroll_height;
+				gchar *height;
+
+				scroll_height = webkit_dom_element_get_scroll_height (scrolling_elem);
+				height = webkit_dom_html_iframe_element_get_height (iframe);
+				if (!height || scroll_height == (glong) g_ascii_strtoll (height, NULL, 10))
+					webkit_dom_html_iframe_element_set_height (iframe, "10");
+				g_free (height);
+
+				scroll_height = webkit_dom_element_get_scroll_height (scrolling_elem);
+				height = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64) (scroll_height + 2 +
+					(webkit_dom_element_get_scroll_width (scrolling_elem) > webkit_dom_element_get_client_width (scrolling_elem) ? 20 : 0)));
+				webkit_dom_html_iframe_element_set_height (iframe, height);
+				g_free (height);
+			}
+		}
+
+		g_clear_object (&default_view);
+	}
+
+	g_clear_object (&frames);
+}
+
+static gboolean
+mail_display_can_use_frame_flattening (void)
+{
+	guint wk_major, wk_minor;
+
+	wk_major = webkit_get_major_version ();
+	wk_minor = webkit_get_minor_version ();
+
+	/* The 2.38 is the last version, which supports frame-flattening;
+	   prefer it over the manual and expensive calculations. */
+	return (wk_major < 2) || (wk_major == 2 && wk_minor <= 38);
+}
+
+void
+e_dom_update_iframe_height (WebKitDOMDocument *document)
+{
+	WebKitDOMDOMWindow *default_view;
+
+	if (mail_display_can_use_frame_flattening ())
+		return;
+
+	default_view = webkit_dom_document_get_default_view (document);
+	if (default_view) {
+		glong scroll_x, scroll_y;
+
+		scroll_x = webkit_dom_dom_window_get_scroll_x (default_view);
+		scroll_y = webkit_dom_dom_window_get_scroll_y (default_view);
+
+		e_dom_update_iframe_height_recursive (document);
+
+		if (scroll_y != webkit_dom_dom_window_get_scroll_y (default_view))
+			webkit_dom_dom_window_scroll_to (default_view, scroll_x, scroll_y);
+	}
+
+	g_clear_object (&default_view);
+}
+
 void
 e_dom_utils_eab_contact_formatter_bind_dom (WebKitDOMDocument *document)
 {
diff -urp evolution-3.22.6.orig/web-extensions/e-dom-utils.h evolution-3.22.6/web-extensions/e-dom-utils.h
--- evolution-3.22.6.orig/web-extensions/e-dom-utils.h	2016-12-05 13:10:08.000000000 -0600
+++ evolution-3.22.6/web-extensions/e-dom-utils.h	2023-07-14 14:50:52.542913825 -0500
@@ -58,6 +58,7 @@ void		e_dom_utils_eab_contact_formatter_
 void		e_dom_utils_e_mail_display_bind_dom
 						(WebKitDOMDocument *document,
 						 GDBusConnection *connection);
+void		e_dom_update_iframe_height	(WebKitDOMDocument *document);
 WebKitDOMElement *
 		e_dom_utils_find_element_by_selector
 						(WebKitDOMDocument *document,
