mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-24 07:01:05 +00:00
Refactoring
This commit is contained in:
parent
b6030ecd83
commit
c44bac2238
2 changed files with 23 additions and 22 deletions
|
@ -25,7 +25,6 @@ import android.net.Uri;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.net.MailTo;
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -44,28 +43,18 @@ public class IPInfo {
|
||||||
private final static int FETCH_TIMEOUT = 15 * 1000; // milliseconds
|
private final static int FETCH_TIMEOUT = 15 * 1000; // milliseconds
|
||||||
|
|
||||||
static Pair<InetAddress, 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())) {
|
String host = UriHelper.getHost(uri);
|
||||||
MailTo email = MailTo.parse(uri.toString());
|
if (host == null)
|
||||||
String domain = UriHelper.getEmailDomain(email.getTo());
|
throw new UnknownHostException();
|
||||||
if (domain == null)
|
|
||||||
throw new UnknownHostException();
|
try {
|
||||||
//InetAddress address = DnsHelper.lookupMx(context, domain);
|
host = IDN.toASCII(host, IDN.ALLOW_UNASSIGNED);
|
||||||
//if (address == null)
|
} catch (Throwable ex) {
|
||||||
// throw new UnknownHostException();
|
Log.i(ex);
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InetAddress address = InetAddress.getByName(host);
|
||||||
|
return new Pair<>(address, getOrganization(address, context));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Organization getOrganization(InetAddress address, Context context) throws IOException {
|
static Organization getOrganization(InetAddress address, Context context) throws IOException {
|
||||||
|
|
|
@ -23,16 +23,20 @@ import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
import android.util.Pair;
|
||||||
import android.webkit.URLUtil;
|
import android.webkit.URLUtil;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.net.MailTo;
|
||||||
import androidx.core.util.PatternsCompat;
|
import androidx.core.util.PatternsCompat;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.IDN;
|
import java.net.IDN;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -422,6 +426,14 @@ public class UriHelper {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String getHost(Uri uri) {
|
||||||
|
if ("mailto".equalsIgnoreCase(uri.getScheme())) {
|
||||||
|
MailTo email = MailTo.parse(uri.toString());
|
||||||
|
return getEmailDomain(email.getTo());
|
||||||
|
} else
|
||||||
|
return uri.getHost();
|
||||||
|
}
|
||||||
|
|
||||||
static void test(Context context) {
|
static void test(Context context) {
|
||||||
String[] hosts = new String[]{
|
String[] hosts = new String[]{
|
||||||
"child.parent.example.com", "parent.example.com", "example.com", "com",
|
"child.parent.example.com", "parent.example.com", "example.com", "com",
|
||||||
|
|
Loading…
Reference in a new issue