mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-01 04:35:57 +00:00
Permanent favicon blacklisting
This commit is contained in:
parent
2c8137d31d
commit
19fc6eb827
3 changed files with 41 additions and 29 deletions
|
@ -50,10 +50,8 @@ import java.net.HttpURLConnection;
|
|||
import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -74,7 +72,6 @@ public class ContactInfo {
|
|||
private static Map<String, Lookup> emailLookup = new ConcurrentHashMap<>();
|
||||
private static final Map<String, ContactInfo> emailContactInfo = new HashMap<>();
|
||||
private static final Map<String, Avatar> emailGravatar = new HashMap<>();
|
||||
private static final List<String> emailFaviconBlacklist = new ArrayList<>();
|
||||
|
||||
private static final ExecutorService executor =
|
||||
Helper.getBackgroundExecutor(1, "contact");
|
||||
|
@ -119,10 +116,26 @@ public class ContactInfo {
|
|||
return (new Date().getTime() - time > CACHE_CONTACT_DURATION);
|
||||
}
|
||||
|
||||
static void clearCache() {
|
||||
static void clearCache(Context context) {
|
||||
synchronized (emailContactInfo) {
|
||||
emailContactInfo.clear();
|
||||
}
|
||||
|
||||
final File dir = new File(context.getCacheDir(), "favicons");
|
||||
|
||||
executor.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
File[] favicons = dir.listFiles();
|
||||
if (favicons != null)
|
||||
for (File favicon : favicons)
|
||||
favicon.delete();
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -265,25 +278,22 @@ public class ContactInfo {
|
|||
int at = (info.email == null ? -1 : info.email.indexOf('@'));
|
||||
String domain = (at < 0 ? null : info.email.substring(at + 1).toLowerCase(Locale.ROOT));
|
||||
|
||||
synchronized (emailFaviconBlacklist) {
|
||||
if (emailFaviconBlacklist.contains(domain)) {
|
||||
Log.i("Favicon blacklisted domain=" + domain);
|
||||
domain = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (domain != null) {
|
||||
if ("gmail.com".equals(domain))
|
||||
domain = "google.com";
|
||||
|
||||
File dir = new File(context.getCacheDir(), "favicons");
|
||||
if (!dir.exists())
|
||||
dir.mkdir();
|
||||
File file = new File(dir, domain);
|
||||
|
||||
try {
|
||||
// check cache
|
||||
File dir = new File(context.getCacheDir(), "favicons");
|
||||
if (!dir.exists())
|
||||
dir.mkdir();
|
||||
File file = new File(dir, domain);
|
||||
if (file.exists())
|
||||
info.bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
|
||||
if (file.length() == 0)
|
||||
Log.i("Favicon blacklisted domain=" + domain);
|
||||
else
|
||||
info.bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
|
||||
else {
|
||||
info.bitmap = getFavicon(new URL("https://" + domain));
|
||||
if (info.bitmap == null)
|
||||
|
@ -299,8 +309,10 @@ public class ContactInfo {
|
|||
Log.w(ex);
|
||||
} finally {
|
||||
if (info.bitmap == null)
|
||||
synchronized (emailFaviconBlacklist) {
|
||||
emailFaviconBlacklist.add(domain);
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -334,7 +334,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
|||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("avatars", checked).apply();
|
||||
ContactInfo.clearCache();
|
||||
ContactInfo.clearCache(getContext());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -342,7 +342,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
|||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("gravatars", checked).apply();
|
||||
ContactInfo.clearCache();
|
||||
ContactInfo.clearCache(getContext());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -350,7 +350,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
|||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("favicons", checked).apply();
|
||||
ContactInfo.clearCache();
|
||||
ContactInfo.clearCache(getContext());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -370,7 +370,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
|||
sbSaturation.setEnabled(checked);
|
||||
sbBrightness.setEnabled(checked);
|
||||
sbThreshold.setEnabled(checked);
|
||||
ContactInfo.clearCache();
|
||||
ContactInfo.clearCache(getContext());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -378,7 +378,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
|||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("identicons", checked).apply();
|
||||
ContactInfo.clearCache();
|
||||
ContactInfo.clearCache(getContext());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -387,7 +387,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
|||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("circular", checked).apply();
|
||||
updateColor();
|
||||
ContactInfo.clearCache();
|
||||
ContactInfo.clearCache(getContext());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -396,7 +396,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
|||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
prefs.edit().putInt("saturation", progress).apply();
|
||||
updateColor();
|
||||
ContactInfo.clearCache();
|
||||
ContactInfo.clearCache(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -415,7 +415,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
|||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
prefs.edit().putInt("brightness", progress).apply();
|
||||
updateColor();
|
||||
ContactInfo.clearCache();
|
||||
ContactInfo.clearCache(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -434,7 +434,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
|||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
prefs.edit().putInt("threshold", progress).apply();
|
||||
updateColor();
|
||||
ContactInfo.clearCache();
|
||||
ContactInfo.clearCache(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1023,7 +1023,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
|||
public void onClick(DialogInterface dialog, int which) {
|
||||
getActivity().getIntent().putExtra("tab", "display");
|
||||
|
||||
ContactInfo.clearCache();
|
||||
ContactInfo.clearCache(getContext());
|
||||
|
||||
boolean reverse = (swReverse.isEnabled() && swReverse.isChecked());
|
||||
boolean dark = (swDark.isEnabled() && swDark.isChecked());
|
||||
|
|
|
@ -124,7 +124,7 @@ public class WorkerCleanup extends Worker {
|
|||
ServiceSynchronize.reschedule(context);
|
||||
|
||||
// Contact info cache
|
||||
ContactInfo.clearCache();
|
||||
ContactInfo.clearCache(context);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
Log.i("Checking notification channels");
|
||||
|
|
Loading…
Reference in a new issue