mirror of https://github.com/M66B/FairEmail.git
Highlight mail-do domain name, refactoring
This commit is contained in:
parent
9dc7795320
commit
3449815e68
|
@ -227,15 +227,6 @@ public class DnsHelper {
|
|||
}
|
||||
}
|
||||
|
||||
static String getParentDomain(String host) {
|
||||
if (host != null) {
|
||||
String[] h = host.split("\\.");
|
||||
if (h.length >= 2)
|
||||
return h[h.length - 2] + "." + h[h.length - 1];
|
||||
}
|
||||
return host;
|
||||
}
|
||||
|
||||
private static String getDnsServer(Context context) {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (cm == null)
|
||||
|
|
|
@ -315,14 +315,14 @@ public class EntityMessage implements Serializable {
|
|||
int rat = (r == null ? -1 : r.indexOf('@'));
|
||||
if (rat < 0)
|
||||
continue;
|
||||
String rdomain = DnsHelper.getParentDomain(r.substring(rat + 1));
|
||||
String rdomain = UriHelper.getParentDomain(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 = DnsHelper.getParentDomain(f.substring(fat + 1));
|
||||
String fdomain = UriHelper.getParentDomain(f.substring(fat + 1));
|
||||
|
||||
if (!rdomain.equalsIgnoreCase(fdomain))
|
||||
return context.getString(R.string.title_reply_domain, fdomain, rdomain);
|
||||
|
|
|
@ -860,7 +860,7 @@ public class EntityRule {
|
|||
int at = sender.indexOf('@');
|
||||
if (at > 0) {
|
||||
boolean whitelisted = false;
|
||||
String domain = DnsHelper.getParentDomain(sender.substring(at + 1));
|
||||
String domain = UriHelper.getParentDomain(sender.substring(at + 1));
|
||||
for (String d : whitelist)
|
||||
if (domain.matches(d)) {
|
||||
whitelisted = true;
|
||||
|
|
|
@ -1077,7 +1077,7 @@ public class FragmentAccount extends FragmentBase {
|
|||
db.beginTransaction();
|
||||
|
||||
if (account != null && !account.password.equals(password)) {
|
||||
String domain = DnsHelper.getParentDomain(account.host);
|
||||
String domain = UriHelper.getParentDomain(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);
|
||||
|
|
|
@ -54,6 +54,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.core.net.MailTo;
|
||||
import androidx.core.util.PatternsCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
|
@ -502,14 +503,26 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
|
|||
private Spanned format(Uri uri, Context context) {
|
||||
String text = uri.toString();
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder(text);
|
||||
String host = uri.getHost();
|
||||
if (host != null) {
|
||||
int textColorLink = Helper.resolveColor(context, android.R.attr.textColorLink);
|
||||
int index = text.indexOf(host);
|
||||
if (index >= 0)
|
||||
ssb.setSpan(new ForegroundColorSpan(textColorLink),
|
||||
index, index + host.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
|
||||
try {
|
||||
String host = uri.getHost();
|
||||
|
||||
if (host == null && "mailto".equals(uri.getScheme())) {
|
||||
MailTo email = MailTo.parse(uri.toString());
|
||||
host = UriHelper.getEmailDomain(email.getTo());
|
||||
}
|
||||
|
||||
if (host != null) {
|
||||
int textColorLink = Helper.resolveColor(context, android.R.attr.textColorLink);
|
||||
int index = text.indexOf(host);
|
||||
if (index >= 0)
|
||||
ssb.setSpan(new ForegroundColorSpan(textColorLink),
|
||||
index, index + host.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
||||
return ssb;
|
||||
}
|
||||
}
|
|
@ -488,7 +488,7 @@ public class FragmentPop extends FragmentBase {
|
|||
db.beginTransaction();
|
||||
|
||||
if (account != null && !account.password.equals(password)) {
|
||||
String domain = DnsHelper.getParentDomain(account.host);
|
||||
String domain = UriHelper.getParentDomain(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);
|
||||
|
|
|
@ -45,10 +45,9 @@ public class IPInfo {
|
|||
static Pair<String, Organization> getOrganization(@NonNull Uri uri, Context context) throws IOException, ParseException {
|
||||
if ("mailto".equalsIgnoreCase(uri.getScheme())) {
|
||||
MailTo email = MailTo.parse(uri.toString());
|
||||
String to = email.getTo();
|
||||
if (to == null || !to.contains("@"))
|
||||
String domain = UriHelper.getEmailDomain(email.getTo());
|
||||
if (domain == null)
|
||||
throw new UnknownHostException();
|
||||
String domain = to.substring(to.indexOf('@') + 1);
|
||||
InetAddress address = DnsHelper.lookupMx(context, domain);
|
||||
if (address == null)
|
||||
throw new UnknownHostException();
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FairEmail is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018-2021 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
public class UriHelper {
|
||||
static String getParentDomain(String host) {
|
||||
if (host == null)
|
||||
return null;
|
||||
|
||||
String[] h = host.split("\\.");
|
||||
if (h.length >= 2)
|
||||
return h[h.length - 2] + "." + h[h.length - 1];
|
||||
|
||||
return host;
|
||||
}
|
||||
|
||||
static String getEmailDomain(String address) {
|
||||
if (address == null)
|
||||
return null;
|
||||
|
||||
int at = address.indexOf('@');
|
||||
if (at > 0)
|
||||
return address.substring(at + 1);
|
||||
|
||||
return address;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue