1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-02-23 14:41:08 +00:00

Allow colors

This commit is contained in:
M66B 2019-09-23 19:51:17 +02:00
parent 5b243b5a0f
commit ec7ea93642

View file

@ -133,6 +133,7 @@ public class HtmlHelper {
Whitelist whitelist = Whitelist.relaxed()
.addTags("hr", "abbr", "big")
.addAttributes("span", "style")
.removeTags("col", "colgroup", "thead", "tbody")
.removeAttributes("table", "width")
.removeAttributes("td", "colspan", "rowspan", "width")
@ -141,6 +142,27 @@ public class HtmlHelper {
.addProtocols("img", "src", "data");
final Document document = new Cleaner(whitelist).clean(parsed);
// Sanitize span styles
for (Element span : document.select("span")) {
String style = span.attr("style");
if (!TextUtils.isEmpty(style)) {
StringBuilder sb = new StringBuilder();
String[] params = style.split(";");
for (String param : params) {
String[] kv = param.split(":");
if (kv.length == 2)
switch (kv[0].trim().toLowerCase()) {
case "color":
sb.append(param).append(";");
break;
}
}
span.attr("style", sb.toString());
}
}
// Remove new lines without surrounding content
for (Element br : document.select("br"))
if (br.parent() != null && !hasVisibleContent(br.parent().childNodes()))