Added Public Suffix List

pull/200/head
M66B 3 years ago
parent b1419b32f1
commit 6375a502c0

@ -33,3 +33,4 @@ FairEmail uses:
* [GoSquared's Flag Icon Set](https://github.com/gosquared/flags). Copyright (c) 2017 Go Squared Ltd. [MIT License](https://github.com/gosquared/flags/blob/master/LICENSE.txt).
* [OpenDyslexic](https://github.com/antijingoist/opendyslexic). Copyright (c) 12/2012 - 2019. Copyright (c) 2019-07-29, Abbie Gonzalez. [SIL Open Font License 1.1](https://github.com/antijingoist/opendyslexic/blob/master/OFL.txt).
* [AndroidSVG](https://github.com/BigBadaboom/androidsvg). Copyright 2013 Paul LeBeau, Cave Rock Software Ltd. [Apache License 2.0](https://github.com/BigBadaboom/androidsvg/blob/master/LICENSE).
* [Public Suffix List](https://publicsuffix.org/). Copyright © 200720 Mozilla Foundation. [Mozilla Public License, v. 2.0](https://mozilla.org/MPL/2.0/).

@ -33,3 +33,4 @@ FairEmail uses:
* [GoSquared's Flag Icon Set](https://github.com/gosquared/flags). Copyright (c) 2017 Go Squared Ltd. [MIT License](https://github.com/gosquared/flags/blob/master/LICENSE.txt).
* [OpenDyslexic](https://github.com/antijingoist/opendyslexic). Copyright (c) 12/2012 - 2019. Copyright (c) 2019-07-29, Abbie Gonzalez. [SIL Open Font License 1.1](https://github.com/antijingoist/opendyslexic/blob/master/OFL.txt).
* [AndroidSVG](https://github.com/BigBadaboom/androidsvg). Copyright 2013 Paul LeBeau, Cave Rock Software Ltd. [Apache License 2.0](https://github.com/BigBadaboom/androidsvg/blob/master/LICENSE).
* [Public Suffix List](https://publicsuffix.org/). Copyright © 200720 Mozilla Foundation. [Mozilla Public License, v. 2.0](https://mozilla.org/MPL/2.0/).

File diff suppressed because it is too large Load Diff

@ -316,14 +316,14 @@ public class EntityMessage implements Serializable {
int rat = (r == null ? -1 : r.indexOf('@'));
if (rat < 0)
continue;
String rdomain = UriHelper.getParentDomain(r.substring(rat + 1));
String rdomain = UriHelper.getParentDomain(context, r.substring(rat + 1));
for (Address _from : from) {
String f = ((InternetAddress) _from).getAddress();
int fat = (f == null ? -1 : f.indexOf('@'));
if (fat < 0)
continue;
String fdomain = UriHelper.getParentDomain(f.substring(fat + 1));
String fdomain = UriHelper.getParentDomain(context, f.substring(fat + 1));
if (!rdomain.equalsIgnoreCase(fdomain))
return context.getString(R.string.title_reply_domain, fdomain, rdomain);

@ -867,7 +867,7 @@ public class EntityRule {
int at = sender.indexOf('@');
if (at > 0) {
boolean whitelisted = false;
String domain = UriHelper.getParentDomain(sender.substring(at + 1));
String domain = UriHelper.getParentDomain(context, sender.substring(at + 1));
for (String d : whitelist)
if (domain.matches(d)) {
whitelisted = true;

@ -1095,7 +1095,7 @@ public class FragmentAccount extends FragmentBase {
db.beginTransaction();
if (account != null && !account.password.equals(password)) {
String domain = UriHelper.getParentDomain(account.host);
String domain = UriHelper.getParentDomain(context, account.host);
String match = (Objects.equals(account.host, domain) ? account.host : "%." + domain);
int count = db.identity().setIdentityPassword(account.id, account.user, password, match);
Log.i("Updated passwords=" + count + " match=" + match);

@ -488,7 +488,7 @@ public class FragmentPop extends FragmentBase {
db.beginTransaction();
if (account != null && !account.password.equals(password)) {
String domain = UriHelper.getParentDomain(account.host);
String domain = UriHelper.getParentDomain(context, account.host);
String match = (Objects.equals(account.host, domain) ? account.host : "%." + domain);
int count = db.identity().setIdentityPassword(account.id, account.user, password, match);
Log.i("Updated passwords=" + count + " match=" + match);

@ -19,16 +19,47 @@ package eu.faircode.email;
Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/
import android.content.Context;
import android.text.TextUtils;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.zip.ZipInputStream;
public class UriHelper {
static String getParentDomain(String host) {
// https://publicsuffix.org/
private static final HashSet<String> suffixList = new HashSet<>();
private static final String SUFFIX_LIST_NAME = "effective_tld_names.dat.txt";
static String getParentDomain(Context context, String host) {
if (host == null)
return null;
String[] h = host.split("\\.");
if (h.length >= 2)
return h[h.length - 2] + "." + h[h.length - 1];
ensureSuffixList(context);
String h = host;
while (true) {
int dot = h.indexOf('.');
if (dot < 0)
return host;
String prefix = h.substring(0, dot);
h = h.substring(dot + 1);
int d = h.indexOf('.');
String w = (d < 0 ? null : '*' + h.substring(d));
synchronized (suffixList) {
if ((suffixList.contains(h) || suffixList.contains(w)) &&
!suffixList.contains('!' + h)) {
String parent = prefix + "." + h;
Log.i("Host=" + host + " parent=" + parent);
return parent;
}
}
}
}
static String getEmailUser(String address) {
@ -52,4 +83,28 @@ public class UriHelper {
return null;
}
static void ensureSuffixList(Context context) {
synchronized (suffixList) {
if (suffixList.size() > 0)
return;
Log.i("Reading " + SUFFIX_LIST_NAME);
try (InputStream is = context.getAssets().open(SUFFIX_LIST_NAME)) {
BufferedReader br = new BufferedReader(new InputStreamReader((is)));
String line;
while ((line = br.readLine()) != null) {
line = line.trim();
if (TextUtils.isEmpty(line))
continue;
if (line.startsWith("//"))
continue;
suffixList.add(line);
}
Log.i(SUFFIX_LIST_NAME + "=" + suffixList.size());
} catch (Throwable ex) {
Log.e(ex);
}
}
}
}

Loading…
Cancel
Save