Removed Spamhaus/DBL

pull/199/head
M66B 4 years ago
parent 470f86db91
commit 2d8f188cf1

@ -41,7 +41,7 @@ import java.util.Map;
import javax.mail.internet.MimeUtility; import javax.mail.internet.MimeUtility;
public class DnsBlockList { public class DnsBlockList {
static final List<BlockList> BLOCKLISTS = Collections.unmodifiableList(Arrays.asList( static final List<BlockList> BLOCK_LISTS = Collections.unmodifiableList(Arrays.asList(
// https://www.spamhaus.org/zen/ // https://www.spamhaus.org/zen/
new BlockList(true, "Spamhaus/zen", "zen.spamhaus.org", true, new String[]{ new BlockList(true, "Spamhaus/zen", "zen.spamhaus.org", true, new String[]{
// https://www.spamhaus.org/faq/section/DNSBL%20Usage#200 // https://www.spamhaus.org/faq/section/DNSBL%20Usage#200
@ -54,7 +54,7 @@ public class DnsBlockList {
}), }),
// https://www.spamhaus.org/dbl/ // https://www.spamhaus.org/dbl/
new BlockList(false, "Spamhaus/DBL", "dbl.spamhaus.org", false, new String[]{ new BlockList(null, "Spamhaus/DBL", "dbl.spamhaus.org", false, new String[]{
// https://www.spamhaus.org/faq/section/Spamhaus%20DBL#291 // https://www.spamhaus.org/faq/section/Spamhaus%20DBL#291
"127.0.1.2", // spam domain "127.0.1.2", // spam domain
"127.0.1.4", // phish domain "127.0.1.4", // phish domain
@ -83,7 +83,7 @@ public class DnsBlockList {
static void setEnabled(Context context, BlockList blocklist, boolean enabled) { static void setEnabled(Context context, BlockList blocklist, boolean enabled) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (blocklist.enabled == enabled) if (blocklist.enabled == null || blocklist.enabled == enabled)
prefs.edit().remove("blocklist." + blocklist.name).apply(); prefs.edit().remove("blocklist." + blocklist.name).apply();
else else
prefs.edit().putBoolean("blocklist." + blocklist.name, enabled).apply(); prefs.edit().putBoolean("blocklist." + blocklist.name, enabled).apply();
@ -94,14 +94,15 @@ public class DnsBlockList {
} }
static boolean isEnabled(Context context, BlockList blocklist) { static boolean isEnabled(Context context, BlockList blocklist) {
boolean def = (blocklist.enabled != null && blocklist.enabled);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean("blocklist." + blocklist.name, blocklist.enabled); return prefs.getBoolean("blocklist." + blocklist.name, def);
} }
static void reset(Context context) { static void reset(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
for (BlockList blocklist : BLOCKLISTS) for (BlockList blocklist : BLOCK_LISTS)
editor.remove("blocklist." + blocklist.name); editor.remove("blocklist." + blocklist.name);
editor.apply(); editor.apply();
@ -110,9 +111,17 @@ public class DnsBlockList {
} }
} }
static List<BlockList> getLists() {
List<BlockList> result = new ArrayList<>();
for (BlockList blockList : BLOCK_LISTS)
if (blockList.enabled != null)
result.add(blockList);
return result;
}
static List<String> getNames(Context context) { static List<String> getNames(Context context) {
List<String> names = new ArrayList<>(); List<String> names = new ArrayList<>();
for (BlockList blocklist : BLOCKLISTS) for (BlockList blocklist : BLOCK_LISTS)
if (isEnabled(context, blocklist)) if (isEnabled(context, blocklist))
names.add(blocklist.name); names.add(blocklist.name);
return names; return names;
@ -128,7 +137,7 @@ public class DnsBlockList {
if ("from".equalsIgnoreCase(words[i])) { if ("from".equalsIgnoreCase(words[i])) {
String host = words[i + 1].toLowerCase(Locale.ROOT); String host = words[i + 1].toLowerCase(Locale.ROOT);
if (!TextUtils.isEmpty(host)) if (!TextUtils.isEmpty(host))
return isJunk(context, host, BLOCKLISTS); return isJunk(context, host, BLOCK_LISTS);
} }
return null; return null;
@ -263,7 +272,7 @@ public class DnsBlockList {
static class BlockList { static class BlockList {
int id; int id;
boolean enabled; Boolean enabled;
String name; String name;
String address; String address;
boolean numeric; boolean numeric;
@ -271,7 +280,7 @@ public class DnsBlockList {
private static int nextid = 1; private static int nextid = 1;
BlockList(boolean enabled, String name, String address, boolean numeric, String[] responses) { BlockList(Boolean enabled, String name, String address, boolean numeric, String[] responses) {
this.id = nextid++; this.id = nextid++;
this.enabled = enabled; this.enabled = enabled;
this.name = name; this.name = name;

@ -356,7 +356,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
rvBlocklist.setHasFixedSize(false); rvBlocklist.setHasFixedSize(false);
rvBlocklist.setLayoutManager(new LinearLayoutManager(getContext())); rvBlocklist.setLayoutManager(new LinearLayoutManager(getContext()));
AdapterBlocklist badapter = new AdapterBlocklist(getContext(), DnsBlockList.BLOCKLISTS); AdapterBlocklist badapter = new AdapterBlocklist(getContext(), DnsBlockList.getLists());
rvBlocklist.setAdapter(badapter); rvBlocklist.setAdapter(badapter);
swTuneKeepAlive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swTuneKeepAlive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

Loading…
Cancel
Save