From aa279e5b57c1b33fb474c4ee839c3a4d1b8317bc Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 29 Dec 2020 09:04:29 +0100 Subject: [PATCH] Normalize referenced message --- .../eu/faircode/email/FragmentCompose.java | 1 + .../java/eu/faircode/email/HtmlHelper.java | 79 ++++++++++--------- 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 432cab69ca..0519176465 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -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"); diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index 42ac585ae9..94e99baf1e 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -399,43 +399,8 @@ public class HtmlHelper { } }); - // - - //   - - // 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) { + // + + //   + + // 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 parseStyles(Elements styles) { List sheets = new ArrayList<>(); for (Element style : styles) {