mirror of https://github.com/M66B/FairEmail.git
Attempt to remove tracking from original messages
This commit is contained in:
parent
f2a1828e3a
commit
3ac49cb2a5
|
@ -1505,9 +1505,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||||
|
|
||||||
new SimpleTask<String>() {
|
new SimpleTask<String>() {
|
||||||
@Override
|
@Override
|
||||||
protected String onExecute(Context context, Bundle args) throws Throwable {
|
protected String onExecute(Context context, Bundle args) throws IOException {
|
||||||
long id = args.getLong("id");
|
long id = args.getLong("id");
|
||||||
return getHtmlEmbedded(id);
|
return HtmlHelper.removeTracking(context, getHtmlEmbedded(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2207,9 +2207,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||||
|
|
||||||
new SimpleTask<String>() {
|
new SimpleTask<String>() {
|
||||||
@Override
|
@Override
|
||||||
protected String onExecute(Context context, Bundle args) throws Throwable {
|
protected String onExecute(Context context, Bundle args) throws IOException {
|
||||||
long id = args.getLong("id");
|
long id = args.getLong("id");
|
||||||
return getHtmlEmbedded(id);
|
return HtmlHelper.removeTracking(context, getHtmlEmbedded(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -83,6 +83,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
||||||
private SwitchCompat swPreview;
|
private SwitchCompat swPreview;
|
||||||
private SwitchCompat swAddresses;
|
private SwitchCompat swAddresses;
|
||||||
private SwitchCompat swHtml;
|
private SwitchCompat swHtml;
|
||||||
|
private SwitchCompat swTracking;
|
||||||
private SwitchCompat swImages;
|
private SwitchCompat swImages;
|
||||||
private SwitchCompat swActionbar;
|
private SwitchCompat swActionbar;
|
||||||
|
|
||||||
|
@ -109,7 +110,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
||||||
private Group grpNotification;
|
private Group grpNotification;
|
||||||
|
|
||||||
static String[] OPTIONS_RESTART = new String[]{
|
static String[] OPTIONS_RESTART = new String[]{
|
||||||
"unified", "date", "threading", "avatars", "identicons", "name_email", "subject_italic", "flags", "preview", "addresses", "autoimages", "actionbar",
|
"unified", "date", "threading", "avatars", "identicons", "name_email", "subject_italic", "flags", "preview",
|
||||||
|
"addresses", "autohtml", "autoimages", "actionbar",
|
||||||
"pull", "swipenav", "autoexpand", "autoclose", "autonext",
|
"pull", "swipenav", "autoexpand", "autoclose", "autonext",
|
||||||
"debug"
|
"debug"
|
||||||
};
|
};
|
||||||
|
@ -117,7 +119,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
||||||
private final static String[] ADVANCED_OPTIONS = new String[]{
|
private final static String[] ADVANCED_OPTIONS = new String[]{
|
||||||
"enabled", "schedule_start", "schedule_end",
|
"enabled", "schedule_start", "schedule_end",
|
||||||
"metered", "download",
|
"metered", "download",
|
||||||
"unified", "date", "threading", "avatars", "identicons", "name_email", "subject_italic", "flags", "preview", "addresses", "autoimages", "actionbar",
|
"unified", "date", "threading", "avatars", "identicons", "name_email", "subject_italic", "flags", "preview",
|
||||||
|
"addresses", "autohtml", "remove_tracking", "autoimages", "actionbar",
|
||||||
"pull", "swipenav", "autoexpand", "autoclose", "autonext", "collapse", "autoread", "automove",
|
"pull", "swipenav", "autoexpand", "autoclose", "autonext", "collapse", "autoread", "automove",
|
||||||
"autoresize", "sender", "autosend",
|
"autoresize", "sender", "autosend",
|
||||||
"notify_preview", "search_local", "light", "sound",
|
"notify_preview", "search_local", "light", "sound",
|
||||||
|
@ -155,6 +158,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
||||||
swPreview = view.findViewById(R.id.swPreview);
|
swPreview = view.findViewById(R.id.swPreview);
|
||||||
swAddresses = view.findViewById(R.id.swAddresses);
|
swAddresses = view.findViewById(R.id.swAddresses);
|
||||||
swHtml = view.findViewById(R.id.swHtml);
|
swHtml = view.findViewById(R.id.swHtml);
|
||||||
|
swTracking = view.findViewById(R.id.swTracking);
|
||||||
swImages = view.findViewById(R.id.swImages);
|
swImages = view.findViewById(R.id.swImages);
|
||||||
swActionbar = view.findViewById(R.id.swActionbar);
|
swActionbar = view.findViewById(R.id.swActionbar);
|
||||||
|
|
||||||
|
@ -352,6 +356,13 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
swTracking.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||||
|
prefs.edit().putBoolean("remove_tracking", checked).apply();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
swImages.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
swImages.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||||
|
@ -576,6 +587,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
||||||
swPreview.setChecked(prefs.getBoolean("preview", false));
|
swPreview.setChecked(prefs.getBoolean("preview", false));
|
||||||
swAddresses.setChecked(prefs.getBoolean("addresses", true));
|
swAddresses.setChecked(prefs.getBoolean("addresses", true));
|
||||||
swHtml.setChecked(prefs.getBoolean("autohtml", false));
|
swHtml.setChecked(prefs.getBoolean("autohtml", false));
|
||||||
|
swTracking.setChecked(prefs.getBoolean("remove_tracking", true));
|
||||||
swImages.setChecked(prefs.getBoolean("autoimages", false));
|
swImages.setChecked(prefs.getBoolean("autoimages", false));
|
||||||
swImages.setEnabled(!swHtml.isChecked());
|
swImages.setEnabled(!swHtml.isChecked());
|
||||||
swActionbar.setChecked(prefs.getBoolean("actionbar", true));
|
swActionbar.setChecked(prefs.getBoolean("actionbar", true));
|
||||||
|
|
|
@ -20,11 +20,13 @@ package eu.faircode.email;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
@ -65,6 +67,25 @@ public class HtmlHelper {
|
||||||
private static final List<String> heads = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6", "p", "table", "ol", "ul", "br", "hr");
|
private static final List<String> heads = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6", "p", "table", "ol", "ul", "br", "hr");
|
||||||
private static final List<String> tails = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6", "p", "ol", "ul", "li");
|
private static final List<String> tails = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6", "p", "ol", "ul", "li");
|
||||||
|
|
||||||
|
static String removeTracking(Context context, String html) {
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
boolean remove_tracking = prefs.getBoolean("remove_tracking", true);
|
||||||
|
if (!remove_tracking)
|
||||||
|
return html;
|
||||||
|
|
||||||
|
Document document = Jsoup.parse(html);
|
||||||
|
|
||||||
|
for (Element img : document.select("img")) {
|
||||||
|
String src = img.attr("src");
|
||||||
|
String height = img.attr("height").trim();
|
||||||
|
String width = img.attr("width").trim();
|
||||||
|
if ("1".equals(height) && "1".equals(width) && !TextUtils.isEmpty(src))
|
||||||
|
img.removeAttr("src");
|
||||||
|
}
|
||||||
|
|
||||||
|
return document.outerHtml();
|
||||||
|
}
|
||||||
|
|
||||||
static String sanitize(Context context, String html, boolean showQuotes) {
|
static String sanitize(Context context, String html, boolean showQuotes) {
|
||||||
final Document document = Jsoup.parse(Jsoup.clean(html, Whitelist
|
final Document document = Jsoup.parse(Jsoup.clean(html, Whitelist
|
||||||
.relaxed()
|
.relaxed()
|
||||||
|
|
|
@ -428,6 +428,18 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/swHtml" />
|
app:layout_constraintTop_toBottomOf="@id/swHtml" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
|
android:id="@+id/swTracking"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="12dp"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:layout_marginEnd="12dp"
|
||||||
|
android:text="@string/title_advanced_tracking"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvHtmlHint"
|
||||||
|
app:switchPadding="12dp" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
android:id="@+id/swImages"
|
android:id="@+id/swImages"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -437,7 +449,7 @@
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
android:text="@string/title_advanced_images"
|
android:text="@string/title_advanced_images"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/tvHtmlHint"
|
app:layout_constraintTop_toBottomOf="@id/swTracking"
|
||||||
app:switchPadding="12dp" />
|
app:switchPadding="12dp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|
|
@ -163,6 +163,7 @@
|
||||||
<string name="title_advanced_preview">Show message preview</string>
|
<string name="title_advanced_preview">Show message preview</string>
|
||||||
<string name="title_advanced_addresses">Show address details by default</string>
|
<string name="title_advanced_addresses">Show address details by default</string>
|
||||||
<string name="title_advanced_html">Automatically show original message for known contacts</string>
|
<string name="title_advanced_html">Automatically show original message for known contacts</string>
|
||||||
|
<string name="title_advanced_tracking">Attempt to remove tracking from original messages</string>
|
||||||
<string name="title_advanced_images">Automatically show images for known contacts</string>
|
<string name="title_advanced_images">Automatically show images for known contacts</string>
|
||||||
<string name="title_advanced_actionbar">Conversation action bar</string>
|
<string name="title_advanced_actionbar">Conversation action bar</string>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue