So what happens is that the Evolution in bullseye is using a
deprecated WebKit API that was removed in the 2.40.x branch (the
function remains but it's a no-op now). Reverting that change in
WebKit is unfortunately not an option.

This was fixed in Evolution upstream a while ago[1] so bookworm is not
affected. The patch was backported to at least Evolution 3.28.5[2] and
3.40.4[3]. The latter can be applied fine to our version (3.38.3) and
fixes the problem for me, I'm putting Milan Crha on Cc for comments
since the patch is not trivial.

I'm also attaching the debdiff for Evolution with this patch included.

The other alternative would be to switch back to WebKitGTK 2.38.x but
that branch is not likely to receive any further security updates.

Berto

[1] https://gitlab.gnome.org/GNOME/evolution/-/issues/2001
[2] 
https://gitlab.com/redhat/centos-stream/rpms/evolution/-/blob/c8s/evolution-3.28.5-frame-flattenning.patch
[3] 
https://gitlab.com/redhat/centos-stream/rpms/evolution/-/blob/c9s/evolution-3.40.4-frame-flattenning.patch
diff -Nru evolution-3.38.3/debian/changelog evolution-3.38.3/debian/changelog
--- evolution-3.38.3/debian/changelog	2022-10-18 22:36:42.000000000 +0200
+++ evolution-3.38.3/debian/changelog	2023-05-04 00:33:14.000000000 +0200
@@ -1,3 +1,10 @@
+evolution (3.38.3-1+deb11u2) bullseye-security; urgency=medium
+
+  * Add a patch to make Evolution display email bodies properly when using
+    WebKitGTK 2.40.x (Closes: #1035469).
+
+ -- Alberto Garcia <be...@igalia.com>  Thu, 04 May 2023 00:33:14 +0200
+
 evolution (3.38.3-1+deb11u1) bullseye; urgency=medium
 
   * Add a patch from upstream to move Google Contacts addressbooks to
diff -Nru evolution-3.38.3/debian/control evolution-3.38.3/debian/control
--- evolution-3.38.3/debian/control	2022-10-18 22:36:42.000000000 +0200
+++ evolution-3.38.3/debian/control	2023-05-04 00:33:14.000000000 +0200
@@ -6,7 +6,7 @@
 Section: gnome
 Priority: optional
 Maintainer: Debian GNOME Maintainers <pkg-gnome-maintain...@lists.alioth.debian.org>
-Uploaders: Iain Lane <la...@debian.org>, Jeremy Bicha <jbi...@debian.org>, Laurent Bigonville <bi...@debian.org>, Sebastien Bacher <seb...@debian.org>
+Uploaders: Alberto Garcia <be...@igalia.com>, Iain Lane <la...@debian.org>, Jeremy Bicha <jbi...@debian.org>, Laurent Bigonville <bi...@debian.org>, Sebastien Bacher <seb...@debian.org>
 Build-Depends: cmake,
                debhelper (>= 11),
                dh-sequence-gnome,
diff -Nru evolution-3.38.3/debian/patches/frame-flattening.patch evolution-3.38.3/debian/patches/frame-flattening.patch
--- evolution-3.38.3/debian/patches/frame-flattening.patch	1970-01-01 01:00:00.000000000 +0100
+++ evolution-3.38.3/debian/patches/frame-flattening.patch	2023-05-04 00:33:14.000000000 +0200
@@ -0,0 +1,478 @@
+From: Milan Crha <mc...@redhat.com>
+Subject: Handle frame flattening change in WebKitGTK 2.40.x
+Bug: https://bugs.webkit.org/show_bug.cgi?id=256266
+Bug-Debian: https://bugs.debian.org/1035469
+Origin: https://gitlab.com/redhat/centos-stream/rpms/evolution/-/blob/c9s/evolution-3.40.4-frame-flattenning.patch
+Index: evolution-3.38.3/data/webkit/e-web-view.js
+===================================================================
+--- evolution-3.38.3.orig/data/webkit/e-web-view.js
++++ evolution-3.38.3/data/webkit/e-web-view.js
+@@ -722,6 +722,38 @@ Evo.EnsureMainDocumentInitialized = func
+ 	Evo.initializeAndPostContentLoaded(null);
+ }
+ 
++Evo.mailDisplayUpdateIFramesHeightRecursive = function(doc)
++{
++	if (!doc)
++		return;
++
++	var ii, iframes;
++
++	iframes = doc.getElementsByTagName("iframe");
++
++	/* Update from bottom to top */
++	for (ii = 0; ii < iframes.length; ii++) {
++		Evo.mailDisplayUpdateIFramesHeightRecursive(iframes[ii].contentDocument);
++	}
++
++	if (!doc.scrollingElement || !doc.defaultView || !doc.defaultView.frameElement)
++		return;
++
++	if (doc.defaultView.frameElement.height == doc.scrollingElement.scrollHeight)
++		doc.defaultView.frameElement.height = 10;
++	doc.defaultView.frameElement.height = doc.scrollingElement.scrollHeight + 2 + (doc.scrollingElement.scrollWidth > doc.scrollingElement.clientWidth ? 20 : 0);
++}
++
++Evo.MailDisplayUpdateIFramesHeight = function()
++{
++	var scrolly = document.defaultView ? document.defaultView.scrollY : -1;
++
++	Evo.mailDisplayUpdateIFramesHeightRecursive(document);
++
++	if (scrolly != -1 && document.defaultView.scrollY != scrolly)
++		document.defaultView.scrollTo(0, scrolly);
++}
++
+ if (this instanceof Window && this.document) {
+ 	this.document.onload = function() { Evo.initializeAndPostContentLoaded(this); };
+ 
+@@ -807,9 +839,8 @@ Evo.mailDisplayResizeContentToPreviewWid
+ 				local_width -= 2; /* 1 + 1 frame borders */
+ 			} else if (!iframes.length) {
+ 				/* Message main body */
+-				local_width -= 8; /* 8 + 8 margins of body without iframes */
+-				if (level > 1)
+-					local_width -= 8;
++				local_width -= level * 20; /* 10 + 10 margins of body without iframes */
++				local_width -= 4;
+ 
+ 				Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", "body", "width: " + local_width + "px;");
+ 				Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", ".part-container", "width: " + local_width + "px;");
+@@ -819,7 +850,7 @@ Evo.mailDisplayResizeContentToPreviewWid
+ 				Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", "body",
+ 					"width: " + local_width + "px;");
+ 
+-				local_width -= 2; /* 1 + 1 frame borders */
++				local_width -= 4; /* 2 + 2 frame borders */
+ 
+ 				Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", ".part-container-nostyle iframe",
+ 					"width: " + local_width + "px;");
+@@ -831,19 +862,15 @@ Evo.mailDisplayResizeContentToPreviewWid
+ 				Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", ".part-container iframe",
+ 					"width: " + (local_width - 10) + "px;");
+ 			} else {
+-				local_width -= 20; /* 10 + 10 margins of body with iframes */
+-				local_width -= 8; /* attachment margin */
+-				local_width -= 2; /* 1 + 1 frame borders */
++				local_width -= (level - 1) * 20; /* 10 + 10 margins of body with iframes */
++				local_width -= 4; /* 2 + 2 frame borders */
++				local_width -= 10; /* attachment margin */
+ 
+-				/* We need to subtract another 10 pixels from the iframe width to
+-				 * have the iframe's borders on the correct place. We can't subtract
+-				 * it from local_width as we don't want to propagate this change
+-				 * further. */
+ 				Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", ".part-container-nostyle iframe",
+-					"width: " + (local_width - 10) + "px;");
++					"width: " + local_width + "px;");
+ 
+ 				Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", "body > .part-container-nostyle iframe",
+-					"width: " + (local_width - 10) + "px;");
++					"width: " + local_width + "px;");
+ 			}
+ 
+ 			/* Add rules to every sub document */
+@@ -854,7 +881,7 @@ Evo.mailDisplayResizeContentToPreviewWid
+ 				var tmp_local_width = local_width;
+ 
+ 				if (level == 0) {
+-					tmp_local_width -= 8; /* attachment's margin */
++					tmp_local_width -= 10; /* attachment's margin */
+ 
+ 					Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", ".attachment-wrapper iframe:not([src*=\"__formatas=\"])",
+ 						"width: " + tmp_local_width + "px;");
+@@ -863,7 +890,7 @@ Evo.mailDisplayResizeContentToPreviewWid
+ 						"width: " + tmp_local_width + "px;");
+ 
+ 					Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", "body > .part-container-nostyle iframe",
+-						"width: " + local_width + "px;");
++						"width: " + tmp_local_width + "px;");
+ 				}
+ 
+ 				this.set_iframe_and_body_width (iframes[ii].contentDocument, tmp_local_width, original_width, level + 1);
+@@ -876,6 +903,7 @@ Evo.mailDisplayResizeContentToPreviewWid
+ 	width -= 20; /* 10 + 10 margins of body */
+ 
+ 	traversar.set_iframe_and_body_width(document, width, width, 0);
++	window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
+ }
+ 
+ Evo.mailDisplayUpdateMagicSpacebarState = function()
+@@ -1241,6 +1269,8 @@ Evo.MailDisplayShowAttachment = function
+ 			window.webkit.messageHandlers.contentLoaded.postMessage(iframe_id);
+ 			Evo.mailDisplayUpdateMagicSpacebarState();
+ 		}
++	} else if (elem.ownerDocument.defaultView.frameElement) {
++		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
+ 	}
+ }
+ 
+@@ -1335,8 +1365,10 @@ EvoItip.SetElementInnerHTML = function(i
+ {
+ 	var elem = Evo.FindElement(iframe_id, element_id);
+ 
+-	if (elem)
++	if (elem) {
+ 		elem.innerHTML = html_content;
++		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
++	}
+ }
+ 
+ EvoItip.SetShowCheckbox = function(iframe_id, element_id, show, update_second)
+@@ -1362,6 +1394,8 @@ EvoItip.SetShowCheckbox = function(ifram
+ 		if (elem) {
+ 			elem.hidden = !show;
+ 		}
++
++		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
+ 	}
+ }
+ 
+@@ -1375,6 +1409,8 @@ EvoItip.SetAreaText = function(iframe_id
+ 		if (row.lastElementChild) {
+ 			row.lastElementChild.innerHTML = text;
+ 		}
++
++		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
+ 	}
+ }
+ 
+@@ -1392,6 +1428,8 @@ EvoItip.UpdateTimes = function(iframe_id
+ 		if (elem.lastElementChild) {
+ 			elem.lastElementChild.innerHTML = label;
+ 		}
++
++		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
+ 	}
+ }
+ 
+@@ -1419,6 +1457,8 @@ EvoItip.AppendInfoRow = function(iframe_
+ 
+ 	cell = row.insertCell(-1);
+ 	cell.innerHTML = message;
++
++	window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
+ }
+ 
+ EvoItip.RemoveInfoRow = function(iframe_id, row_id)
+@@ -1427,6 +1467,7 @@ EvoItip.RemoveInfoRow = function(iframe_
+ 
+ 	if (row && row.parentNode) {
+ 		row.parentNode.removeChild(row);
++		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
+ 	}
+ }
+ 
+@@ -1438,6 +1479,8 @@ EvoItip.RemoveChildNodes = function(ifra
+ 		while (elem.lastChild) {
+ 			elem.removeChild(elem.lastChild);
+ 		}
++
++		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
+ 	}
+ }
+ 
+@@ -1490,6 +1533,8 @@ EvoItip.HideButtons = function(iframe_id
+ 			if (button)
+ 				button.hidden = true;
+ 		}
++
++		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
+ 	}
+ }
+ 
+Index: evolution-3.38.3/data/webkit/webview.css
+===================================================================
+--- evolution-3.38.3.orig/data/webkit/webview.css
++++ evolution-3.38.3/data/webkit/webview.css
+@@ -8,8 +8,8 @@ img {
+ }
+ 
+ body {
+-  /* Use margin so that children can safely use width=100% */
+-  margin: 5px 10px 5px 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: 0px;
++  padding-left: 8px;
++  padding-right: 0px;
+ }
+ 
+ .attachment td {
+@@ -58,21 +58,21 @@ iframe:not([id$=".itip"]) {
+ 
+ .part-container {
+   height: 100%;
+-  margin-top: 2px;
+-  margin-bottom: 2px;
++  padding: 0px;
+ }
+ 
+ .part-container-nostyle iframe {
+-  margin-right: 10px;
++  margin: 0px;
++  padding-right: 0px;
+ }
+ 
+ .part-container-inner-margin {
+-  margin: 8px;
++  padding: 0px;
+ }
+ 
+ object { /* GtkWidgets */
+-  margin-top: 2px;
+-  margin-bottom: 2px;
++  padding-top: 2px;
++  padding-bottom: 2px;
+ }
+ 
+ .__evo-highlight {
+@@ -158,7 +158,7 @@ th.rtl {
+ /***** PRINTING *******/
+ 
+ .printing-header {
+-  margin-bottom: 20px;
++  padding-bottom: 20px;
+ }
+ 
+ .printing-header h1,
+@@ -178,7 +178,7 @@ th.rtl {
+ /******* ITIP *********/
+ .itip.icon {
+   float: left;
+-  margin-right: 5px;
++  padding-right: 5px;
+ }
+ 
+ .itip.content {
+@@ -187,7 +187,7 @@ th.rtl {
+ }
+ 
+ .itip.description {
+-  margin: 5px;
++  padding: 5px;
+ }
+ 
+ .itip tr {
+@@ -211,7 +211,7 @@ th.rtl {
+ }
+ 
+ #table_row_buttons img {
+-  margin-right: 5px;
++  padding-right: 5px;
+   vertical-align: middle;
+ }
+ 
+Index: evolution-3.38.3/src/em-format/e-mail-formatter-text-plain.c
+===================================================================
+--- evolution-3.38.3.orig/src/em-format/e-mail-formatter-text-plain.c
++++ evolution-3.38.3/src/em-format/e-mail-formatter-text-plain.c
+@@ -111,7 +111,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: 0; margin: 0;\">";
+ 
+ 		g_output_stream_write_all (
+ 			stream, string, strlen (string),
+Index: evolution-3.38.3/src/mail/e-mail-display.c
+===================================================================
+--- evolution-3.38.3.orig/src/mail/e-mail-display.c
++++ evolution-3.38.3/src/mail/e-mail-display.c
+@@ -83,6 +83,7 @@ struct _EMailDisplayPrivate {
+ 	GSettings *settings;
+ 
+ 	guint scheduled_reload;
++	guint iframes_height_update_id;
+ 
+ 	GHashTable *old_settings;
+ 
+@@ -537,6 +538,43 @@ initialize_web_view_colors (EMailDisplay
+ 		e_web_view_get_cancellable (E_WEB_VIEW (display)));
+ }
+ 
++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 gboolean
++mail_display_iframes_height_update_cb (gpointer user_data)
++{
++	EMailDisplay *mail_display = user_data;
++
++	mail_display->priv->iframes_height_update_id = 0;
++
++	e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (mail_display), e_web_view_get_cancellable (E_WEB_VIEW (mail_display)),
++		"Evo.MailDisplayUpdateIFramesHeight();");
++
++	return G_SOURCE_REMOVE;
++}
++
++static void
++mail_display_schedule_iframes_height_update (EMailDisplay *mail_display)
++{
++	if (mail_display_can_use_frame_flattening ())
++		return;
++
++	if (mail_display->priv->iframes_height_update_id)
++		g_source_remove (mail_display->priv->iframes_height_update_id);
++	mail_display->priv->iframes_height_update_id = g_timeout_add (100, mail_display_iframes_height_update_cb, mail_display);
++}
++
+ static void
+ mail_display_change_one_attachment_visibility (EMailDisplay *display,
+ 					       EAttachment *attachment,
+@@ -1353,6 +1391,8 @@ mail_display_content_loaded_cb (EWebView
+ 			gtk_widget_grab_focus (widget);
+ 		}
+ 	}
++
++	mail_display_schedule_iframes_height_update (mail_display);
+ }
+ 
+ static void
+@@ -1475,6 +1515,11 @@ mail_display_dispose (GObject *object)
+ 		priv->scheduled_reload = 0;
+ 	}
+ 
++	if (priv->iframes_height_update_id > 0) {
++		g_source_remove (priv->iframes_height_update_id);
++		priv->iframes_height_update_id = 0;
++	}
++
+ 	if (priv->settings != NULL) {
+ 		g_signal_handlers_disconnect_matched (
+ 			priv->settings, G_SIGNAL_MATCH_DATA,
+@@ -1608,6 +1653,18 @@ mail_display_magic_spacebar_state_change
+ }
+ 
+ static void
++mail_display_schedule_iframes_height_update_cb (WebKitUserContentManager *manager,
++						WebKitJavascriptResult *js_result,
++						gpointer user_data)
++{
++	EMailDisplay *mail_display = user_data;
++
++	g_return_if_fail (mail_display != NULL);
++
++	mail_display_schedule_iframes_height_update (mail_display);
++}
++
++static void
+ mail_display_constructed (GObject *object)
+ {
+ 	EContentRequest *content_request;
+@@ -1619,9 +1676,11 @@ mail_display_constructed (GObject *objec
+ 	/* Chain up to parent's constructed() method. */
+ 	G_OBJECT_CLASS (e_mail_display_parent_class)->constructed (object);
+ 
+-	g_object_set (webkit_web_view_get_settings (WEBKIT_WEB_VIEW (object)),
+-		"enable-frame-flattening", TRUE,
+-		NULL);
++	if (mail_display_can_use_frame_flattening ()) {
++		g_object_set (webkit_web_view_get_settings (WEBKIT_WEB_VIEW (object)),
++			"enable-frame-flattening", TRUE,
++			NULL);
++	}
+ 
+ 	display = E_MAIL_DISPLAY (object);
+ 	web_view = E_WEB_VIEW (object);
+@@ -1669,8 +1728,12 @@ mail_display_constructed (GObject *objec
+ 	g_signal_connect_object (manager, "script-message-received::mailDisplayMagicSpacebarStateChanged",
+ 		G_CALLBACK (mail_display_magic_spacebar_state_changed_cb), display, 0);
+ 
++	g_signal_connect_object (manager, "script-message-received::scheduleIFramesHeightUpdate",
++		G_CALLBACK (mail_display_schedule_iframes_height_update_cb), display, 0);
++
+ 	webkit_user_content_manager_register_script_message_handler (manager, "mailDisplayHeadersCollapsed");
+ 	webkit_user_content_manager_register_script_message_handler (manager, "mailDisplayMagicSpacebarStateChanged");
++	webkit_user_content_manager_register_script_message_handler (manager, "scheduleIFramesHeightUpdate");
+ 
+ 	e_extensible_load_extensions (E_EXTENSIBLE (object));
+ }
+Index: evolution-3.38.3/src/modules/text-highlight/e-mail-formatter-text-highlight.c
+===================================================================
+--- evolution-3.38.3.orig/src/modules/text-highlight/e-mail-formatter-text-highlight.c
++++ evolution-3.38.3/src/modules/text-highlight/e-mail-formatter-text-highlight.c
+@@ -135,16 +135,26 @@ text_hightlight_read_data_thread (gpoint
+ {
+ 	TextHighlightClosure *closure = user_data;
+ 	gint nbuffer = 10240;
++	gssize read;
++	gsize wrote = 0;
+ 	gchar *buffer;
+ 
+ 	g_return_val_if_fail (closure != NULL, NULL);
+ 
+ 	buffer = g_new (gchar, nbuffer);
+ 
++	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) {
++		g_free (buffer);
++		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, nbuffer, closure->cancellable, &closure->error);
+ 		if (read < 0 || closure->error)
diff -Nru evolution-3.38.3/debian/patches/series evolution-3.38.3/debian/patches/series
--- evolution-3.38.3/debian/patches/series	2022-10-18 22:36:42.000000000 +0200
+++ evolution-3.38.3/debian/patches/series	2023-05-04 00:33:14.000000000 +0200
@@ -3,3 +3,4 @@
 ubuntu_gettext_domain.patch
 eds-I-281-GLibTools.cmake-Use-basename-in-glib-mkenums-te.patch
 0001-Addressbook-Switch-from-GData-Contacts-API-to-CardDA.patch
+frame-flattening.patch

Reply via email to