1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-26 09:47:13 +00:00

Normalize referenced message

This commit is contained in:
M66B 2020-12-29 09:04:29 +01:00
parent f0317197cb
commit aa279e5b57
2 changed files with 43 additions and 37 deletions

View file

@ -3797,6 +3797,7 @@ public class FragmentCompose extends FragmentBase {
if (TextUtils.isEmpty(s)) {
// Get referenced message body
d = JsoupEx.parse(ref.getFile(context));
HtmlHelper.normalizeNamespaces(d, false);
for (Element e : d.select("[x-plain=true]"))
e.removeAttr("x-plain");

View file

@ -399,43 +399,8 @@ public class HtmlHelper {
}
});
// <html xmlns:v="urn:schemas-microsoft-com:vml"
// xmlns:o="urn:schemas-microsoft-com:office:office"
// xmlns:w="urn:schemas-microsoft-com:office:word"
// xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
// xmlns="http://www.w3.org/TR/REC-html40">
// <o:p>&nbsp;</o:p></span>
// Default XHTML namespace: http://www.w3.org/1999/xhtml
String ns = null;
for (Element h : parsed.select("html"))
for (Attribute a : h.attributes()) {
String key = a.getKey();
String value = a.getValue();
if (value != null &&
key.startsWith("xmlns:") &&
value.startsWith("http://www.w3.org/")) {
ns = key.split(":")[1];
break;
}
}
for (Element e : parsed.select("*")) {
String tag = e.tagName();
if (tag.contains(":")) {
if (display_hidden ||
"body".equals(tag) ||
ns == null || tag.startsWith(ns)) {
String[] nstag = tag.split(":");
e.tagName(nstag[nstag.length > 1 ? 1 : 0]);
Log.i("Updated tag=" + tag + " to=" + e.tagName());
} else {
e.remove();
Log.i("Removed tag=" + tag);
}
}
}
// Fix Microsoft namespaces
normalizeNamespaces(parsed, display_hidden);
// Limit length
if (view && truncate(parsed, true)) {
@ -1148,6 +1113,46 @@ public class HtmlHelper {
return document;
}
static void normalizeNamespaces(Document parsed, boolean display_hidden) {
// <html xmlns:v="urn:schemas-microsoft-com:vml"
// xmlns:o="urn:schemas-microsoft-com:office:office"
// xmlns:w="urn:schemas-microsoft-com:office:word"
// xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
// xmlns="http://www.w3.org/TR/REC-html40">
// <o:p>&nbsp;</o:p></span>
// Default XHTML namespace: http://www.w3.org/1999/xhtml
String ns = null;
for (Element h : parsed.select("html"))
for (Attribute a : h.attributes()) {
String key = a.getKey();
String value = a.getValue();
if (value != null &&
key.startsWith("xmlns:") &&
value.startsWith("http://www.w3.org/")) {
ns = key.split(":")[1];
break;
}
}
for (Element e : parsed.select("*")) {
String tag = e.tagName();
if (tag.contains(":")) {
if (display_hidden ||
"body".equals(tag) ||
ns == null || tag.startsWith(ns)) {
String[] nstag = tag.split(":");
e.tagName(nstag[nstag.length > 1 ? 1 : 0]);
Log.i("Updated tag=" + tag + " to=" + e.tagName());
} else {
e.remove();
Log.i("Removed tag=" + tag);
}
}
}
}
static List<CSSStyleSheet> parseStyles(Elements styles) {
List<CSSStyleSheet> sheets = new ArrayList<>();
for (Element style : styles) {