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

86b8f8
diff -up evolution-3.40.4/data/webkit/e-web-view.js.6 evolution-3.40.4/data/webkit/e-web-view.js
86b8f8
--- evolution-3.40.4/data/webkit/e-web-view.js.6	2023-01-03 18:41:01.198700722 +0100
86b8f8
+++ evolution-3.40.4/data/webkit/e-web-view.js	2023-01-03 18:41:01.215700736 +0100
86b8f8
@@ -730,6 +730,38 @@ Evo.EnsureMainDocumentInitialized = func
86b8f8
 	Evo.initializeAndPostContentLoaded(null);
86b8f8
 }
86b8f8
 
86b8f8
+Evo.mailDisplayUpdateIFramesHeightRecursive = function(doc)
86b8f8
+{
86b8f8
+	if (!doc)
86b8f8
+		return;
86b8f8
+
86b8f8
+	var ii, iframes;
86b8f8
+
86b8f8
+	iframes = doc.getElementsByTagName("iframe");
86b8f8
+
86b8f8
+	/* Update from bottom to top */
86b8f8
+	for (ii = 0; ii < iframes.length; ii++) {
86b8f8
+		Evo.mailDisplayUpdateIFramesHeightRecursive(iframes[ii].contentDocument);
86b8f8
+	}
86b8f8
+
86b8f8
+	if (!doc.scrollingElement || !doc.defaultView || !doc.defaultView.frameElement)
86b8f8
+		return;
86b8f8
+
86b8f8
+	if (doc.defaultView.frameElement.height == doc.scrollingElement.scrollHeight)
86b8f8
+		doc.defaultView.frameElement.height = 10;
86b8f8
+	doc.defaultView.frameElement.height = doc.scrollingElement.scrollHeight + 2 + (doc.scrollingElement.scrollWidth > doc.scrollingElement.clientWidth ? 20 : 0);
86b8f8
+}
86b8f8
+
86b8f8
+Evo.MailDisplayUpdateIFramesHeight = function()
86b8f8
+{
86b8f8
+	var scrolly = document.defaultView ? document.defaultView.scrollY : -1;
86b8f8
+
86b8f8
+	Evo.mailDisplayUpdateIFramesHeightRecursive(document);
86b8f8
+
86b8f8
+	if (scrolly != -1 && document.defaultView.scrollY != scrolly)
86b8f8
+		document.defaultView.scrollTo(0, scrolly);
86b8f8
+}
86b8f8
+
86b8f8
 if (this instanceof Window && this.document) {
86b8f8
 	this.document.onload = function() { Evo.initializeAndPostContentLoaded(this); };
86b8f8
 
86b8f8
@@ -815,9 +847,8 @@ Evo.mailDisplayResizeContentToPreviewWid
86b8f8
 				local_width -= 2; /* 1 + 1 frame borders */
86b8f8
 			} else if (!iframes.length) {
86b8f8
 				/* Message main body */
86b8f8
-				local_width -= 8; /* 8 + 8 margins of body without iframes */
86b8f8
-				if (level > 1)
86b8f8
-					local_width -= 8;
86b8f8
+				local_width -= level * 20; /* 10 + 10 margins of body without iframes */
86b8f8
+				local_width -= 4;
86b8f8
 
86b8f8
 				Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", "body", "width: " + local_width + "px;");
86b8f8
 				Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", ".part-container", "width: " + local_width + "px;");
86b8f8
@@ -827,7 +858,7 @@ Evo.mailDisplayResizeContentToPreviewWid
86b8f8
 				Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", "body",
86b8f8
 					"width: " + local_width + "px;");
86b8f8
 
86b8f8
-				local_width -= 2; /* 1 + 1 frame borders */
86b8f8
+				local_width -= 4; /* 2 + 2 frame borders */
86b8f8
 
86b8f8
 				Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", ".part-container-nostyle iframe",
86b8f8
 					"width: " + local_width + "px;");
86b8f8
@@ -839,19 +870,15 @@ Evo.mailDisplayResizeContentToPreviewWid
86b8f8
 				Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", ".part-container iframe",
86b8f8
 					"width: " + (local_width - 10) + "px;");
86b8f8
 			} else {
86b8f8
-				local_width -= 20; /* 10 + 10 margins of body with iframes */
86b8f8
-				local_width -= 8; /* attachment margin */
86b8f8
-				local_width -= 2; /* 1 + 1 frame borders */
86b8f8
+				local_width -= (level - 1) * 20; /* 10 + 10 margins of body with iframes */
86b8f8
+				local_width -= 4; /* 2 + 2 frame borders */
86b8f8
+				local_width -= 10; /* attachment margin */
86b8f8
 
86b8f8
-				/* We need to subtract another 10 pixels from the iframe width to
86b8f8
-				 * have the iframe's borders on the correct place. We can't subtract
86b8f8
-				 * it from local_width as we don't want to propagate this change
86b8f8
-				 * further. */
86b8f8
 				Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", ".part-container-nostyle iframe",
86b8f8
-					"width: " + (local_width - 10) + "px;");
86b8f8
+					"width: " + local_width + "px;");
86b8f8
 
86b8f8
 				Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", "body > .part-container-nostyle iframe",
86b8f8
-					"width: " + (local_width - 10) + "px;");
86b8f8
+					"width: " + local_width + "px;");
86b8f8
 			}
86b8f8
 
86b8f8
 			/* Add rules to every sub document */
86b8f8
@@ -862,7 +889,7 @@ Evo.mailDisplayResizeContentToPreviewWid
86b8f8
 				var tmp_local_width = local_width;
86b8f8
 
86b8f8
 				if (level == 0) {
86b8f8
-					tmp_local_width -= 8; /* attachment's margin */
86b8f8
+					tmp_local_width -= 10; /* attachment's margin */
86b8f8
 
86b8f8
 					Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", ".attachment-wrapper iframe:not([src*=\"__formatas=\"])",
86b8f8
 						"width: " + tmp_local_width + "px;");
86b8f8
@@ -871,7 +898,7 @@ Evo.mailDisplayResizeContentToPreviewWid
86b8f8
 						"width: " + tmp_local_width + "px;");
86b8f8
 
86b8f8
 					Evo.addRuleIntoStyleSheetDocument(doc, "-e-mail-formatter-style-sheet", "body > .part-container-nostyle iframe",
86b8f8
-						"width: " + local_width + "px;");
86b8f8
+						"width: " + tmp_local_width + "px;");
86b8f8
 				}
86b8f8
 
86b8f8
 				this.set_iframe_and_body_width (iframes[ii].contentDocument, tmp_local_width, original_width, level + 1);
86b8f8
@@ -884,6 +911,7 @@ Evo.mailDisplayResizeContentToPreviewWid
86b8f8
 	width -= 20; /* 10 + 10 margins of body */
86b8f8
 
86b8f8
 	traversar.set_iframe_and_body_width(document, width, width, 0);
86b8f8
+	window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
86b8f8
 }
86b8f8
 
86b8f8
 Evo.mailDisplayUpdateMagicSpacebarState = function()
86b8f8
@@ -1249,6 +1277,8 @@ Evo.MailDisplayShowAttachment = function
86b8f8
 			window.webkit.messageHandlers.contentLoaded.postMessage(iframe_id);
86b8f8
 			Evo.mailDisplayUpdateMagicSpacebarState();
86b8f8
 		}
86b8f8
+	} else if (elem.ownerDocument.defaultView.frameElement) {
86b8f8
+		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
86b8f8
 	}
86b8f8
 }
86b8f8
 
86b8f8
@@ -1343,8 +1373,10 @@ EvoItip.SetElementInnerHTML = function(i
86b8f8
 {
86b8f8
 	var elem = Evo.FindElement(iframe_id, element_id);
86b8f8
 
86b8f8
-	if (elem)
86b8f8
+	if (elem) {
86b8f8
 		elem.innerHTML = html_content;
86b8f8
+		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
86b8f8
+	}
86b8f8
 }
86b8f8
 
86b8f8
 EvoItip.SetShowCheckbox = function(iframe_id, element_id, show, update_second)
86b8f8
@@ -1370,6 +1402,8 @@ EvoItip.SetShowCheckbox = function(ifram
86b8f8
 		if (elem) {
86b8f8
 			elem.hidden = !show;
86b8f8
 		}
86b8f8
+
86b8f8
+		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
86b8f8
 	}
86b8f8
 }
86b8f8
 
86b8f8
@@ -1383,6 +1417,8 @@ EvoItip.SetAreaText = function(iframe_id
86b8f8
 		if (row.lastElementChild) {
86b8f8
 			row.lastElementChild.innerHTML = text;
86b8f8
 		}
86b8f8
+
86b8f8
+		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
86b8f8
 	}
86b8f8
 }
86b8f8
 
86b8f8
@@ -1400,6 +1436,8 @@ EvoItip.UpdateTimes = function(iframe_id
86b8f8
 		if (elem.lastElementChild) {
86b8f8
 			elem.lastElementChild.innerHTML = label;
86b8f8
 		}
86b8f8
+
86b8f8
+		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
86b8f8
 	}
86b8f8
 }
86b8f8
 
86b8f8
@@ -1427,6 +1465,8 @@ EvoItip.AppendInfoRow = function(iframe_
86b8f8
 
86b8f8
 	cell = row.insertCell(-1);
86b8f8
 	cell.innerHTML = message;
86b8f8
+
86b8f8
+	window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
86b8f8
 }
86b8f8
 
86b8f8
 EvoItip.RemoveInfoRow = function(iframe_id, row_id)
86b8f8
@@ -1435,6 +1475,7 @@ EvoItip.RemoveInfoRow = function(iframe_
86b8f8
 
86b8f8
 	if (row && row.parentNode) {
86b8f8
 		row.parentNode.removeChild(row);
86b8f8
+		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
86b8f8
 	}
86b8f8
 }
86b8f8
 
86b8f8
@@ -1446,6 +1487,8 @@ EvoItip.RemoveChildNodes = function(ifra
86b8f8
 		while (elem.lastChild) {
86b8f8
 			elem.removeChild(elem.lastChild);
86b8f8
 		}
86b8f8
+
86b8f8
+		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
86b8f8
 	}
86b8f8
 }
86b8f8
 
86b8f8
@@ -1498,6 +1541,8 @@ EvoItip.HideButtons = function(iframe_id
86b8f8
 			if (button)
86b8f8
 				button.hidden = true;
86b8f8
 		}
86b8f8
+
86b8f8
+		window.webkit.messageHandlers.scheduleIFramesHeightUpdate.postMessage(0);
86b8f8
 	}
86b8f8
 }
86b8f8
 
86b8f8
diff -up evolution-3.40.4/data/webkit/webview.css.6 evolution-3.40.4/data/webkit/webview.css
86b8f8
--- evolution-3.40.4/data/webkit/webview.css.6	2021-08-13 11:50:35.000000000 +0200
86b8f8
+++ evolution-3.40.4/data/webkit/webview.css	2023-01-03 18:41:01.214700735 +0100
86b8f8
@@ -12,8 +12,8 @@ img {
86b8f8
 }
86b8f8
 
86b8f8
 body {
86b8f8
-  /* Use margin so that children can safely use width=100% */
86b8f8
-  margin: 5px 10px 5px 10px;
86b8f8
+  /* Use padding so that children can safely use width=100% */
86b8f8
+  padding: 8px;
86b8f8
 }
86b8f8
 
86b8f8
 body, div, p, td {
86b8f8
@@ -38,21 +38,21 @@ img#__evo-contact-photo {
86b8f8
 
86b8f8
 img.navigable {
86b8f8
   cursor: pointer;
86b8f8
-  margin-right: 4px;
86b8f8
+  padding-right: 4px;
86b8f8
 }
86b8f8
 
86b8f8
 .attachments {
86b8f8
   background: #FFF;
86b8f8
   border: 1px solid silver;
86b8f8
-  margin: 10px 10px 10px 10px;
86b8f8
+  padding: 10px 10px 10px 10px;
86b8f8
   border-left: 0;
86b8f8
   border-right: 0;
86b8f8
   border-bottom: 0;
86b8f8
 }
86b8f8
 
86b8f8
 .attachment {
86b8f8
-  margin-left: 8px;
86b8f8
-  margin-right: 0px;
86b8f8
+  padding-left: 8px;
86b8f8
+  padding-right: 0px;
86b8f8
 }
86b8f8
 
86b8f8
 .attachment td {
86b8f8
@@ -66,21 +66,21 @@ iframe:not([id$=".itip"]) {
86b8f8
 
86b8f8
 .part-container {
86b8f8
   height: 100%;
86b8f8
-  margin-top: 2px;
86b8f8
-  margin-bottom: 2px;
86b8f8
+  padding: 0px;
86b8f8
 }
86b8f8
 
86b8f8
 .part-container-nostyle iframe {
86b8f8
-  margin-right: 10px;
86b8f8
+  margin: 0px;
86b8f8
+  padding-right: 0px;
86b8f8
 }
86b8f8
 
86b8f8
 .part-container-inner-margin {
86b8f8
-  margin: 8px;
86b8f8
+  padding: 0px;
86b8f8
 }
86b8f8
 
86b8f8
 object { /* GtkWidgets */
86b8f8
-  margin-top: 2px;
86b8f8
-  margin-bottom: 2px;
86b8f8
+  padding-top: 2px;
86b8f8
+  padding-bottom: 2px;
86b8f8
 }
86b8f8
 
86b8f8
 .__evo-highlight {
86b8f8
@@ -166,7 +166,7 @@ th.rtl {
86b8f8
 /***** PRINTING *******/
86b8f8
 
86b8f8
 .printing-header {
86b8f8
-  margin-bottom: 20px;
86b8f8
+  padding-bottom: 20px;
86b8f8
 }
86b8f8
 
86b8f8
 .printing-header h1,
86b8f8
@@ -186,7 +186,7 @@ th.rtl {
86b8f8
 /******* ITIP *********/
86b8f8
 .itip.icon {
86b8f8
   float: left;
86b8f8
-  margin-right: 5px;
86b8f8
+  padding-right: 5px;
86b8f8
 }
86b8f8
 
86b8f8
 .itip.content {
86b8f8
@@ -195,7 +195,7 @@ th.rtl {
86b8f8
 }
86b8f8
 
86b8f8
 .itip.description {
86b8f8
-  margin: 5px;
86b8f8
+  padding: 5px;
86b8f8
 }
86b8f8
 
86b8f8
 .itip tr {
86b8f8
@@ -219,7 +219,7 @@ th.rtl {
86b8f8
 }
86b8f8
 
86b8f8
 #table_row_buttons img {
86b8f8
-  margin-right: 5px;
86b8f8
+  padding-right: 5px;
86b8f8
   vertical-align: middle;
86b8f8
 }
86b8f8
 
86b8f8
diff -up evolution-3.40.4/src/em-format/e-mail-formatter-text-plain.c.6 evolution-3.40.4/src/em-format/e-mail-formatter-text-plain.c
86b8f8
--- evolution-3.40.4/src/em-format/e-mail-formatter-text-plain.c.6	2021-08-13 11:50:35.000000000 +0200
86b8f8
+++ evolution-3.40.4/src/em-format/e-mail-formatter-text-plain.c	2023-01-03 18:41:01.214700735 +0100
86b8f8
@@ -111,7 +111,7 @@ emfe_text_plain_format (EMailFormatterEx
86b8f8
 		string =
86b8f8
 			"
86b8f8
 			"-e-web-view-background-color -e-web-view-text-color\" "
86b8f8
-			"style=\"border: none; padding: 8px; margin: 0;\">";
86b8f8
+			"style=\"border: none; padding: 0; margin: 0;\">";
86b8f8
 
86b8f8
 		g_output_stream_write_all (
86b8f8
 			stream, string, strlen (string),
86b8f8
diff -up evolution-3.40.4/src/mail/e-mail-display.c.6 evolution-3.40.4/src/mail/e-mail-display.c
86b8f8
--- evolution-3.40.4/src/mail/e-mail-display.c.6	2021-08-13 11:50:35.000000000 +0200
86b8f8
+++ evolution-3.40.4/src/mail/e-mail-display.c	2023-01-03 18:41:01.215700736 +0100
86b8f8
@@ -83,6 +83,7 @@ struct _EMailDisplayPrivate {
86b8f8
 	GSettings *settings;
86b8f8
 
86b8f8
 	guint scheduled_reload;
86b8f8
+	guint iframes_height_update_id;
86b8f8
 
86b8f8
 	GHashTable *old_settings;
86b8f8
 
86b8f8
@@ -537,6 +538,43 @@ initialize_web_view_colors (EMailDisplay
86b8f8
 		e_web_view_get_cancellable (E_WEB_VIEW (display)));
86b8f8
 }
86b8f8
 
86b8f8
+static gboolean
86b8f8
+mail_display_can_use_frame_flattening (void)
86b8f8
+{
86b8f8
+	guint wk_major, wk_minor;
86b8f8
+
86b8f8
+	wk_major = webkit_get_major_version ();
86b8f8
+	wk_minor = webkit_get_minor_version ();
86b8f8
+
86b8f8
+	/* The 2.38 is the last version, which supports frame-flattening;
86b8f8
+	   prefer it over the manual and expensive calculations. */
86b8f8
+	return (wk_major < 2) || (wk_major == 2 && wk_minor <= 38);
86b8f8
+}
86b8f8
+
86b8f8
+static gboolean
86b8f8
+mail_display_iframes_height_update_cb (gpointer user_data)
86b8f8
+{
86b8f8
+	EMailDisplay *mail_display = user_data;
86b8f8
+
86b8f8
+	mail_display->priv->iframes_height_update_id = 0;
86b8f8
+
86b8f8
+	e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (mail_display), e_web_view_get_cancellable (E_WEB_VIEW (mail_display)),
86b8f8
+		"Evo.MailDisplayUpdateIFramesHeight();");
86b8f8
+
86b8f8
+	return G_SOURCE_REMOVE;
86b8f8
+}
86b8f8
+
86b8f8
+static void
86b8f8
+mail_display_schedule_iframes_height_update (EMailDisplay *mail_display)
86b8f8
+{
86b8f8
+	if (mail_display_can_use_frame_flattening ())
86b8f8
+		return;
86b8f8
+
86b8f8
+	if (mail_display->priv->iframes_height_update_id)
86b8f8
+		g_source_remove (mail_display->priv->iframes_height_update_id);
86b8f8
+	mail_display->priv->iframes_height_update_id = g_timeout_add (100, mail_display_iframes_height_update_cb, mail_display);
86b8f8
+}
86b8f8
+
86b8f8
 static void
86b8f8
 mail_display_change_one_attachment_visibility (EMailDisplay *display,
86b8f8
 					       EAttachment *attachment,
86b8f8
@@ -1353,6 +1391,8 @@ mail_display_content_loaded_cb (EWebView
86b8f8
 			gtk_widget_grab_focus (widget);
86b8f8
 		}
86b8f8
 	}
86b8f8
+
86b8f8
+	mail_display_schedule_iframes_height_update (mail_display);
86b8f8
 }
86b8f8
 
86b8f8
 static void
86b8f8
@@ -1475,6 +1515,11 @@ mail_display_dispose (GObject *object)
86b8f8
 		priv->scheduled_reload = 0;
86b8f8
 	}
86b8f8
 
86b8f8
+	if (priv->iframes_height_update_id > 0) {
86b8f8
+		g_source_remove (priv->iframes_height_update_id);
86b8f8
+		priv->iframes_height_update_id = 0;
86b8f8
+	}
86b8f8
+
86b8f8
 	if (priv->settings != NULL) {
86b8f8
 		g_signal_handlers_disconnect_matched (
86b8f8
 			priv->settings, G_SIGNAL_MATCH_DATA,
86b8f8
@@ -1600,6 +1645,18 @@ mail_display_magic_spacebar_state_change
86b8f8
 }
86b8f8
 
86b8f8
 static void
86b8f8
+mail_display_schedule_iframes_height_update_cb (WebKitUserContentManager *manager,
86b8f8
+						WebKitJavascriptResult *js_result,
86b8f8
+						gpointer user_data)
86b8f8
+{
86b8f8
+	EMailDisplay *mail_display = user_data;
86b8f8
+
86b8f8
+	g_return_if_fail (mail_display != NULL);
86b8f8
+
86b8f8
+	mail_display_schedule_iframes_height_update (mail_display);
86b8f8
+}
86b8f8
+
86b8f8
+static void
86b8f8
 mail_display_constructed (GObject *object)
86b8f8
 {
86b8f8
 	EContentRequest *content_request;
86b8f8
@@ -1611,9 +1668,11 @@ mail_display_constructed (GObject *objec
86b8f8
 	/* Chain up to parent's constructed() method. */
86b8f8
 	G_OBJECT_CLASS (e_mail_display_parent_class)->constructed (object);
86b8f8
 
86b8f8
-	g_object_set (webkit_web_view_get_settings (WEBKIT_WEB_VIEW (object)),
86b8f8
-		"enable-frame-flattening", TRUE,
86b8f8
-		NULL);
86b8f8
+	if (mail_display_can_use_frame_flattening ()) {
86b8f8
+		g_object_set (webkit_web_view_get_settings (WEBKIT_WEB_VIEW (object)),
86b8f8
+			"enable-frame-flattening", TRUE,
86b8f8
+			NULL);
86b8f8
+	}
86b8f8
 
86b8f8
 	display = E_MAIL_DISPLAY (object);
86b8f8
 	web_view = E_WEB_VIEW (object);
86b8f8
@@ -1661,8 +1720,12 @@ mail_display_constructed (GObject *objec
86b8f8
 	g_signal_connect_object (manager, "script-message-received::mailDisplayMagicSpacebarStateChanged",
86b8f8
 		G_CALLBACK (mail_display_magic_spacebar_state_changed_cb), display, 0);
86b8f8
 
86b8f8
+	g_signal_connect_object (manager, "script-message-received::scheduleIFramesHeightUpdate",
86b8f8
+		G_CALLBACK (mail_display_schedule_iframes_height_update_cb), display, 0);
86b8f8
+
86b8f8
 	webkit_user_content_manager_register_script_message_handler (manager, "mailDisplayHeadersCollapsed");
86b8f8
 	webkit_user_content_manager_register_script_message_handler (manager, "mailDisplayMagicSpacebarStateChanged");
86b8f8
+	webkit_user_content_manager_register_script_message_handler (manager, "scheduleIFramesHeightUpdate");
86b8f8
 
86b8f8
 	e_extensible_load_extensions (E_EXTENSIBLE (object));
86b8f8
 }
86b8f8
diff -up evolution-3.40.4/src/modules/text-highlight/e-mail-formatter-text-highlight.c.6 evolution-3.40.4/src/modules/text-highlight/e-mail-formatter-text-highlight.c
86b8f8
--- evolution-3.40.4/src/modules/text-highlight/e-mail-formatter-text-highlight.c.6	2021-08-13 11:50:35.000000000 +0200
86b8f8
+++ evolution-3.40.4/src/modules/text-highlight/e-mail-formatter-text-highlight.c	2023-01-03 18:41:01.215700736 +0100
86b8f8
@@ -135,16 +135,26 @@ text_hightlight_read_data_thread (gpoint
86b8f8
 {
86b8f8
 	TextHighlightClosure *closure = user_data;
86b8f8
 	gint nbuffer = 10240;
86b8f8
+	gssize read;
86b8f8
+	gsize wrote = 0;
86b8f8
 	gchar *buffer;
86b8f8
 
86b8f8
 	g_return_val_if_fail (closure != NULL, NULL);
86b8f8
 
86b8f8
 	buffer = g_new (gchar, nbuffer);
86b8f8
 
86b8f8
+	strcpy (buffer, "<style>body{margin:0; padding:8px;}</style>");
86b8f8
+	read = strlen (buffer);
86b8f8
+
86b8f8
+	if (!g_output_stream_write_all (closure->output_stream, buffer, read, &wrote, closure->cancellable, &closure->error) ||
86b8f8
+	    (gssize) wrote != read || closure->error) {
86b8f8
+		g_free (buffer);
86b8f8
+		return NULL;
86b8f8
+	}
86b8f8
+
86b8f8
 	while (!camel_stream_eos (closure->read_stream) &&
86b8f8
 	       !g_cancellable_set_error_if_cancelled (closure->cancellable, &closure->error)) {
86b8f8
-		gssize read;
86b8f8
-		gsize wrote = 0;
86b8f8
+		wrote = 0;
86b8f8
 
86b8f8
 		read = camel_stream_read (closure->read_stream, buffer, nbuffer, closure->cancellable, &closure->error);
86b8f8
 		if (read < 0 || closure->error)