Check owner domain, not email server

pull/199/head
M66B 4 years ago
parent 97ec6f0bbf
commit 2df607dac8

@ -59,6 +59,7 @@ import androidx.core.util.PatternsCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import java.net.IDN; import java.net.IDN;
import java.net.InetAddress;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -296,7 +297,7 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putParcelable("uri", uri); args.putParcelable("uri", uri);
new SimpleTask<Pair<String, IPInfo.Organization>>() { new SimpleTask<Pair<InetAddress, IPInfo.Organization>>() {
@Override @Override
protected void onPreExecute(Bundle args) { protected void onPreExecute(Bundle args) {
btnOwner.setEnabled(false); btnOwner.setEnabled(false);
@ -312,14 +313,14 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
} }
@Override @Override
protected Pair<String, IPInfo.Organization> onExecute(Context context, Bundle args) throws Throwable { protected Pair<InetAddress, IPInfo.Organization> onExecute(Context context, Bundle args) throws Throwable {
Uri uri = args.getParcelable("uri"); Uri uri = args.getParcelable("uri");
return IPInfo.getOrganization(uri, context); return IPInfo.getOrganization(uri, context);
} }
@Override @Override
protected void onExecuted(Bundle args, Pair<String, IPInfo.Organization> data) { protected void onExecuted(Bundle args, Pair<InetAddress, IPInfo.Organization> data) {
tvHost.setText(data.first); tvHost.setText(data.first.toString());
tvOwner.setText(data.second.name == null ? "?" : data.second.name); tvOwner.setText(data.second.name == null ? "?" : data.second.name);
ApplicationEx.getMainHandler().post(new Runnable() { ApplicationEx.getMainHandler().post(new Runnable() {
@Override @Override

@ -42,22 +42,23 @@ public class IPInfo {
private final static int FETCH_TIMEOUT = 15 * 1000; // milliseconds private final static int FETCH_TIMEOUT = 15 * 1000; // milliseconds
static Pair<String, Organization> getOrganization(@NonNull Uri uri, Context context) throws IOException, ParseException { static Pair<InetAddress, Organization> getOrganization(@NonNull Uri uri, Context context) throws IOException, ParseException {
if ("mailto".equalsIgnoreCase(uri.getScheme())) { if ("mailto".equalsIgnoreCase(uri.getScheme())) {
MailTo email = MailTo.parse(uri.toString()); MailTo email = MailTo.parse(uri.toString());
String domain = UriHelper.getEmailDomain(email.getTo()); String domain = UriHelper.getEmailDomain(email.getTo());
if (domain == null) if (domain == null)
throw new UnknownHostException(); throw new UnknownHostException();
InetAddress address = DnsHelper.lookupMx(context, domain); //InetAddress address = DnsHelper.lookupMx(context, domain);
if (address == null) //if (address == null)
throw new UnknownHostException(); // throw new UnknownHostException();
return new Pair<>(domain, getOrganization(address, context)); InetAddress address = InetAddress.getByName(domain);
return new Pair<>(address, getOrganization(address, context));
} else { } else {
String host = uri.getHost(); String host = uri.getHost();
if (host == null) if (host == null)
throw new UnknownHostException(); throw new UnknownHostException();
InetAddress address = InetAddress.getByName(host); InetAddress address = InetAddress.getByName(host);
return new Pair<>(host, getOrganization(address, context)); return new Pair<>(address, getOrganization(address, context));
} }
} }

Loading…
Cancel
Save