mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
b6030ecd83
commit
c44bac2238
|
@ -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 {
|
||||
|
|
|
@ -23,16 +23,20 @@ import android.content.Context;
|
|||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Base64;
|
||||
import android.util.Pair;
|
||||
import android.webkit.URLUtil;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.net.MailTo;
|
||||
import androidx.core.util.PatternsCompat;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.IDN;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -422,6 +426,14 @@ public class UriHelper {
|
|||
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) {
|
||||
String[] hosts = new String[]{
|
||||
"child.parent.example.com", "parent.example.com", "example.com", "com",
|
||||
|
|
Loading…
Reference in New Issue