From 661f2e3732e65a17dc5b749e3e4508b340056a3d Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 3 Aug 2020 20:05:52 +0200 Subject: [PATCH] Consider images from same domain not as tracking images --- .../java/eu/faircode/email/HtmlHelper.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index 9cc1a3d4ea..38cabd60ac 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -1430,14 +1430,32 @@ public class HtmlHelper { sb.append("data:image/png;base64,"); sb.append(Base64.encodeToString(bos.toByteArray(), Base64.NO_WRAP)); + // Build list of allowed hosts + List hosts = new ArrayList<>(); + for (Element img : document.select("img")) { + String src = img.attr("src"); + if (!TextUtils.isEmpty(src) && !isTrackingPixel(img)) { + Uri uri = Uri.parse(img.attr("src")); + String host = uri.getHost(); + if (host != null && !hosts.contains(host)) + hosts.add(host); + } + } + // Images for (Element img : document.select("img")) { img.removeAttr("x-tracking"); String src = img.attr("src"); if (TextUtils.isEmpty(src)) continue; + + Uri uri = Uri.parse(src); + String host = uri.getHost(); + if (host == null || hosts.contains(host)) + continue; + if (isTrackingPixel(img) || - (disconnect_images && DisconnectBlacklist.isTracking(Uri.parse(src).getHost()))) { + (disconnect_images && DisconnectBlacklist.isTracking(host))) { img.attr("src", sb.toString()); img.attr("alt", context.getString(R.string.title_legend_tracking_pixel)); img.attr("height", "24");