From 88bc43f836b5515bd34ea811f7b053adc4abc9c8 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 29 Mar 2022 21:59:25 +0200 Subject: [PATCH] Added support for background images --- .../main/java/eu/faircode/email/HtmlHelper.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index 48902600b6..4f4afd0831 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -653,6 +653,22 @@ public class HtmlHelper { for (String key : keys) { String value = kv.get(key); switch (key) { + case "background-image": + // https://developer.mozilla.org/en-US/docs/Web/CSS/background-image + String url = value.replace(" ", ""); + int us = url.indexOf("url("); + int ue = url.indexOf(')', us + 4); + if (us >= 0 && ue > us) { + url = url.substring(us + 4, ue); + if ((url.startsWith("'") && url.endsWith("'")) || + (url.startsWith("\"") && url.endsWith("\""))) + url = url.substring(1, url.length() - 1); + Element img = document.createElement("img") + .attr("src", url); + element.prependElement("br"); + element.prependChild(img); + } + break; case "color": case "background": case "background-color":