Remove small images from reformatted messages

This commit is contained in:
M66B 2020-08-06 17:13:23 +02:00
parent 7485ded3eb
commit c8b6ece9af
2 changed files with 12 additions and 5 deletions

View File

@ -2017,7 +2017,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean disable_tracking = prefs.getBoolean("disable_tracking", true);
if (disable_tracking)
HtmlHelper.removeTrackingPixels(context, document);
HtmlHelper.removeTrackingPixels(context, document, true);
if (debug) {
Document format = JsoupEx.parse(file);

View File

@ -833,7 +833,7 @@ public class HtmlHelper {
// Remove tracking pixels
if (disable_tracking)
removeTrackingPixels(context, document);
removeTrackingPixels(context, document, false);
// Images
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img
@ -1427,7 +1427,7 @@ public class HtmlHelper {
return sb.toString();
}
static void removeTrackingPixels(Context context, Document document) {
static void removeTrackingPixels(Context context, Document document, boolean full) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean disconnect_images = prefs.getBoolean("disconnect_images", false);
@ -1461,14 +1461,21 @@ public class HtmlHelper {
// Images
for (Element img : document.select("img")) {
img.removeAttr("x-tracking");
String src = img.attr("src");
if (TextUtils.isEmpty(src))
if (TextUtils.isEmpty(src)) {
if (!full)
img.remove();
continue;
}
Uri uri = Uri.parse(src);
String host = uri.getHost();
if (host == null || hosts.contains(host))
if (host == null || hosts.contains(host)) {
if (!full && isTrackingPixel(img)) // Is small image
img.remove();
continue;
}
if (isTrackingPixel(img) ||
(disconnect_images && DisconnectBlacklist.isTracking(host))) {