Refactoring

This commit is contained in:
M66B
2022-09-04 08:41:43 +02:00
parent b6030ecd83
commit c44bac2238
2 changed files with 23 additions and 22 deletions

View File

@@ -25,7 +25,6 @@ import android.net.Uri;
import android.util.Pair;
import androidx.annotation.NonNull;
import androidx.core.net.MailTo;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -44,28 +43,18 @@ public class IPInfo {
private final static int FETCH_TIMEOUT = 15 * 1000; // milliseconds
static Pair<InetAddress, Organization> getOrganization(@NonNull Uri uri, Context context) throws IOException, ParseException {
if ("mailto".equalsIgnoreCase(uri.getScheme())) {
MailTo email = MailTo.parse(uri.toString());
String domain = UriHelper.getEmailDomain(email.getTo());
if (domain == null)
throw new UnknownHostException();
//InetAddress address = DnsHelper.lookupMx(context, domain);
//if (address == null)
// throw new UnknownHostException();
InetAddress address = InetAddress.getByName(domain);
return new Pair<>(address, getOrganization(address, context));
} else {
String host = uri.getHost();
if (host == null)
throw new UnknownHostException();
try {
host = IDN.toASCII(host, IDN.ALLOW_UNASSIGNED);
} catch (Throwable ex) {
Log.i(ex);
}
InetAddress address = InetAddress.getByName(host);
return new Pair<>(address, getOrganization(address, context));
String host = UriHelper.getHost(uri);
if (host == null)
throw new UnknownHostException();
try {
host = IDN.toASCII(host, IDN.ALLOW_UNASSIGNED);
} catch (Throwable ex) {
Log.i(ex);
}
InetAddress address = InetAddress.getByName(host);
return new Pair<>(address, getOrganization(address, context));
}
static Organization getOrganization(InetAddress address, Context context) throws IOException {