Files
FairEmail/app/src/main/java/eu/faircode/email/EmailProvider.java

544 lines
22 KiB
Java
Raw Normal View History

2018-08-02 13:33:06 +00:00
package eu.faircode.email;
/*
2018-08-14 05:53:24 +00:00
This file is part of FairEmail.
2018-08-02 13:33:06 +00:00
2018-08-14 05:53:24 +00:00
FairEmail is free software: you can redistribute it and/or modify
2018-08-02 13:33:06 +00:00
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.
2018-10-29 10:46:49 +00:00
FairEmail is distributed in the hope that it will be useful,
2018-08-02 13:33:06 +00:00
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
2018-10-29 10:46:49 +00:00
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2018-08-02 13:33:06 +00:00
2018-12-31 08:04:33 +00:00
Copyright 2018-2019 by Marcel Bokhorst (M66B)
2018-08-02 13:33:06 +00:00
*/
import android.content.Context;
import android.content.res.XmlResourceParser;
2019-07-26 08:09:18 +02:00
import android.text.TextUtils;
2018-08-02 13:33:06 +00:00
2018-12-29 15:04:22 +00:00
import org.xbill.DNS.Lookup;
import org.xbill.DNS.Record;
import org.xbill.DNS.SRVRecord;
import org.xbill.DNS.SimpleResolver;
import org.xbill.DNS.TextParseException;
import org.xbill.DNS.Type;
2018-08-02 13:33:06 +00:00
import org.xmlpull.v1.XmlPullParser;
2018-12-29 15:04:22 +00:00
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
2018-08-02 13:33:06 +00:00
2018-12-29 15:04:22 +00:00
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
2018-12-29 15:04:22 +00:00
import java.net.URL;
import java.net.UnknownHostException;
2018-08-03 04:34:02 +00:00
import java.text.Collator;
2018-08-02 13:33:06 +00:00
import java.util.ArrayList;
2018-08-03 04:34:02 +00:00
import java.util.Collections;
import java.util.Comparator;
2018-08-02 13:33:06 +00:00
import java.util.List;
2018-08-03 04:34:02 +00:00
import java.util.Locale;
2019-07-23 16:08:28 +02:00
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
2018-08-02 13:33:06 +00:00
2019-01-13 15:23:04 +00:00
public class EmailProvider {
2018-08-02 13:33:06 +00:00
public String name;
public int order;
public int keepalive;
2018-08-24 16:41:22 +00:00
public String link;
2018-08-27 14:31:45 +00:00
public String type;
2018-08-02 13:33:06 +00:00
public String imap_host;
2018-11-09 14:48:21 +00:00
public boolean imap_starttls;
2018-08-02 13:33:06 +00:00
public int imap_port;
public String smtp_host;
public int smtp_port;
2018-11-09 14:48:21 +00:00
public boolean smtp_starttls;
2018-12-29 17:23:27 +00:00
public UserType user = UserType.EMAIL;
2019-07-06 16:24:03 +02:00
public String helpUrl = null;
2018-12-29 18:39:02 +00:00
public StringBuilder documentation = null; // html
2018-12-29 17:23:27 +00:00
enum UserType {LOCAL, EMAIL}
2018-08-02 13:33:06 +00:00
2019-07-23 15:15:18 +02:00
private static final int DNS_TIMEOUT = 5 * 1000; // milliseconds
private static final int ISPDB_TIMEOUT = 20 * 1000; // milliseconds
2018-12-29 18:40:14 +00:00
2019-01-13 15:23:04 +00:00
private EmailProvider() {
2018-08-02 13:33:06 +00:00
}
2019-01-13 15:23:04 +00:00
EmailProvider(String name) {
2018-08-02 13:33:06 +00:00
this.name = name;
}
2019-05-12 10:41:19 +02:00
private void checkValid() throws UnknownHostException {
if (this.imap_host == null || this.imap_port == 0 ||
this.smtp_host == null || this.smtp_port == 0)
throw new UnknownHostException(this.name + " invalid");
}
2019-01-13 15:23:04 +00:00
static List<EmailProvider> loadProfiles(Context context) {
List<EmailProvider> result = null;
2018-08-02 13:33:06 +00:00
try {
2019-01-13 15:23:04 +00:00
EmailProvider provider = null;
2018-08-02 13:33:06 +00:00
XmlResourceParser xml = context.getResources().getXml(R.xml.providers);
int eventType = xml.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
2018-12-29 18:39:02 +00:00
String name = xml.getName();
if ("providers".equals(name))
2018-08-02 13:33:06 +00:00
result = new ArrayList<>();
2018-12-29 18:39:02 +00:00
else if ("provider".equals(name)) {
2019-01-13 15:23:04 +00:00
provider = new EmailProvider();
2018-08-02 13:33:06 +00:00
provider.name = xml.getAttributeValue(null, "name");
provider.order = xml.getAttributeIntValue(null, "order", Integer.MAX_VALUE);
provider.keepalive = xml.getAttributeIntValue(null, "keepalive", 0);
2018-08-24 16:41:22 +00:00
provider.link = xml.getAttributeValue(null, "link");
2018-08-27 14:31:45 +00:00
provider.type = xml.getAttributeValue(null, "type");
2018-12-29 18:39:02 +00:00
} else if ("imap".equals(name)) {
2018-08-02 13:33:06 +00:00
provider.imap_host = xml.getAttributeValue(null, "host");
2018-08-08 06:55:47 +00:00
provider.imap_port = xml.getAttributeIntValue(null, "port", 0);
2018-11-09 14:48:21 +00:00
provider.imap_starttls = xml.getAttributeBooleanValue(null, "starttls", false);
2018-12-29 18:39:02 +00:00
} else if ("smtp".equals(name)) {
2018-08-02 13:33:06 +00:00
provider.smtp_host = xml.getAttributeValue(null, "host");
2018-08-08 06:55:47 +00:00
provider.smtp_port = xml.getAttributeIntValue(null, "port", 0);
2018-11-09 14:48:21 +00:00
provider.smtp_starttls = xml.getAttributeBooleanValue(null, "starttls", false);
2018-08-02 13:33:06 +00:00
} else
2018-12-29 18:39:02 +00:00
throw new IllegalAccessException(name);
2018-08-02 13:33:06 +00:00
} else if (eventType == XmlPullParser.END_TAG) {
if ("provider".equals(xml.getName())) {
2019-06-19 14:51:19 +02:00
addSpecials(context, provider);
2018-08-02 13:33:06 +00:00
result.add(provider);
provider = null;
}
}
eventType = xml.next();
}
} catch (Throwable ex) {
2018-12-24 12:27:45 +00:00
Log.e(ex);
2018-08-02 13:33:06 +00:00
}
2018-08-03 04:34:02 +00:00
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
2019-01-13 15:23:04 +00:00
Collections.sort(result, new Comparator<EmailProvider>() {
2018-08-03 04:34:02 +00:00
@Override
2019-01-13 15:23:04 +00:00
public int compare(EmailProvider p1, EmailProvider p2) {
int o = Integer.compare(p1.order, p2.order);
if (o == 0)
return collator.compare(p1.name, p2.name);
else
return o;
2018-08-03 04:34:02 +00:00
}
});
2018-08-02 13:33:06 +00:00
return result;
}
2019-01-13 15:23:04 +00:00
static EmailProvider fromDomain(Context context, String domain) throws IOException {
2019-07-15 15:11:01 +02:00
EmailProvider autoconfig = fromDomainInternal(context, domain);
2019-07-26 08:09:18 +02:00
// Always prefer built-in profiles (ISPDB is not always correct)
2019-07-15 15:11:01 +02:00
List<EmailProvider> providers = loadProfiles(context);
for (EmailProvider provider : providers)
if (provider.imap_host.equals(autoconfig.imap_host) ||
provider.smtp_host.equals(autoconfig.smtp_host)) {
Log.i("Replacing autoconfig by profile " + provider.name);
return provider;
}
return autoconfig;
}
private static EmailProvider fromDomainInternal(Context context, String domain) throws IOException {
2018-12-29 15:04:22 +00:00
try {
2019-07-26 08:09:18 +02:00
// Assume the provider knows best
Log.i("Provider from DNS domain=" + domain);
2019-07-15 16:15:37 +02:00
return addSpecials(context, fromDNS(context, domain));
2019-06-21 21:22:29 +02:00
} catch (Throwable ex) {
2018-12-29 15:04:22 +00:00
Log.w(ex);
2018-12-29 18:44:18 +00:00
try {
2019-07-26 08:09:18 +02:00
// Check ISPDB
Log.i("Provider from ISPDB domain=" + domain);
2019-07-15 16:15:37 +02:00
return addSpecials(context, fromISPDB(context, domain));
} catch (Throwable ex1) {
2018-12-29 18:44:18 +00:00
Log.w(ex1);
try {
2019-07-26 08:09:18 +02:00
// Scan ports
Log.i("Provider from template domain=" + domain);
2019-07-15 16:15:37 +02:00
return addSpecials(context, fromTemplate(context, domain));
2019-06-21 21:22:29 +02:00
} catch (Throwable ex2) {
Log.w(ex2);
throw new UnknownHostException(context.getString(R.string.title_setup_no_settings, domain));
}
2018-12-29 18:44:18 +00:00
}
2018-12-29 15:04:22 +00:00
}
}
2019-07-15 16:15:37 +02:00
private static EmailProvider fromISPDB(Context context, String domain) throws IOException, XmlPullParserException {
2019-01-13 15:23:04 +00:00
EmailProvider provider = new EmailProvider(domain);
2018-12-30 12:52:25 +00:00
2018-12-29 15:04:22 +00:00
// https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat
URL url = new URL("https://autoconfig.thunderbird.net/v1.1/" + domain);
Log.i("Fetching " + url);
HttpURLConnection request = (HttpURLConnection) url.openConnection();
2019-07-23 15:15:18 +02:00
request.setReadTimeout(ISPDB_TIMEOUT);
request.setConnectTimeout(ISPDB_TIMEOUT);
2018-12-29 15:04:22 +00:00
request.setRequestMethod("GET");
request.setDoInput(true);
request.connect();
// https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xml = factory.newPullParser();
xml.setInput(new InputStreamReader(request.getInputStream()));
boolean imap = false;
boolean smtp = false;
2018-12-29 18:39:02 +00:00
String href = null;
String title = null;
2018-12-29 15:04:22 +00:00
int eventType = xml.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
2018-12-29 18:39:02 +00:00
String name = xml.getName();
2018-12-30 15:50:22 +00:00
if ("displayShortName".equals(name)) {
// <displayShortName>GMail</displayShortName>
eventType = xml.next();
if (eventType == XmlPullParser.TEXT) {
String display = xml.getText();
Log.i("Name=" + display);
provider.name = display;
}
continue;
} else if ("incomingServer".equals(name)) {
2018-12-29 18:39:02 +00:00
// <incomingServer type="imap">
// <hostname>imap.gmail.com</hostname>
// <port>993</port>
// <socketType>SSL</socketType>
// <username>%EMAILADDRESS%</username>
// <authentication>OAuth2</authentication>
// <authentication>password-cleartext</authentication>
// </incomingServer>
2018-12-29 15:04:22 +00:00
imap = "imap".equals(xml.getAttributeValue(null, "type"));
2018-12-29 18:39:02 +00:00
} else if ("outgoingServer".equals(name)) {
// <outgoingServer type="smtp">
// <hostname>smtp.gmail.com</hostname>
// <port>465</port>
// <socketType>SSL</socketType>
// <username>%EMAILADDRESS%</username>
// <authentication>OAuth2</authentication>
// <authentication>password-cleartext</authentication>
// </outgoingServer>
2018-12-29 15:04:22 +00:00
smtp = "smtp".equals(xml.getAttributeValue(null, "type"));
2018-12-29 18:39:02 +00:00
} else if ("hostname".equals(name)) {
2018-12-29 15:04:22 +00:00
eventType = xml.next();
if (eventType == XmlPullParser.TEXT) {
String host = xml.getText();
Log.i("Host=" + host);
if (imap)
provider.imap_host = host;
else if (smtp)
provider.smtp_host = host;
}
continue;
2018-12-29 18:39:02 +00:00
} else if ("port".equals(name)) {
2018-12-29 15:04:22 +00:00
eventType = xml.next();
if (eventType == XmlPullParser.TEXT) {
String port = xml.getText();
Log.i("Port=" + port);
if (imap) {
provider.imap_port = Integer.parseInt(port);
provider.imap_starttls = (provider.imap_port == 143);
} else if (smtp) {
provider.smtp_port = Integer.parseInt(port);
provider.smtp_starttls = (provider.smtp_port == 587);
}
}
continue;
2018-12-29 18:39:02 +00:00
} else if ("socketType".equals(name)) {
2018-12-29 15:04:22 +00:00
eventType = xml.next();
if (eventType == XmlPullParser.TEXT) {
String socket = xml.getText();
Log.i("Socket=" + socket);
if ("SSL".equals(socket)) {
if (imap)
provider.imap_starttls = false;
else if (smtp)
provider.smtp_starttls = false;
} else if ("STARTTLS".equals(socket)) {
if (imap)
provider.imap_starttls = true;
else if (smtp)
provider.smtp_starttls = true;
2018-12-29 17:23:27 +00:00
} else
Log.w("Unknown socket type=" + socket);
2018-12-29 15:04:22 +00:00
}
2018-12-29 17:23:27 +00:00
continue;
2018-12-29 15:04:22 +00:00
2018-12-29 18:39:02 +00:00
} else if ("username".equals(name)) {
2018-12-29 17:23:27 +00:00
eventType = xml.next();
if (eventType == XmlPullParser.TEXT) {
String username = xml.getText();
Log.i("Username=" + username);
if ("%EMAILADDRESS%".equals(username))
provider.user = UserType.EMAIL;
else if ("%EMAILLOCALPART%".equals(username))
provider.user = UserType.LOCAL;
else
Log.w("Unknown username type=" + username);
}
2018-12-29 15:04:22 +00:00
continue;
2018-12-29 17:23:27 +00:00
2018-12-29 18:39:02 +00:00
} else if ("enable".equals(name)) {
// <enable visiturl="https://mail.google.com/mail/?ui=2&shva=1#settings/fwdandpop">
// <instruction>You need to enable IMAP access</instruction>
// </enable>
href = xml.getAttributeValue(null, "visiturl");
title = null;
} else if ("documentation".equals(name)) {
// <documentation url="http://mail.google.com/support/bin/answer.py?answer=13273">
// <descr>How to enable IMAP/POP3 in GMail</descr>
// </documentation>
href = xml.getAttributeValue(null, "url");
title = null;
} else if ("instruction".equals(name) || "descr".equals(name)) {
if (href != null) {
eventType = xml.next();
if (eventType == XmlPullParser.TEXT) {
if (title == null)
title = "";
else
title += "<br />";
title += xml.getText();
}
continue;
}
2018-12-29 15:04:22 +00:00
}
2018-12-29 17:23:27 +00:00
2018-12-29 15:04:22 +00:00
} else if (eventType == XmlPullParser.END_TAG) {
2018-12-29 18:39:02 +00:00
String name = xml.getName();
if ("incomingServer".equals(name))
2018-12-29 15:04:22 +00:00
imap = false;
2018-12-29 18:39:02 +00:00
else if ("outgoingServer".equals(name))
2018-12-29 15:04:22 +00:00
smtp = false;
2018-12-29 18:39:02 +00:00
else if ("enable".equals(name) || "documentation".equals(name)) {
if (href != null) {
if (title == null)
title = href;
2019-01-06 08:16:44 +00:00
addDocumentation(provider, href, title);
2018-12-29 18:39:02 +00:00
href = null;
title = null;
}
}
2018-12-29 15:04:22 +00:00
}
eventType = xml.next();
}
request.disconnect();
Log.i("imap=" + provider.imap_host + ":" + provider.imap_port + ":" + provider.imap_starttls);
Log.i("smtp=" + provider.smtp_host + ":" + provider.smtp_port + ":" + provider.smtp_starttls);
2019-01-06 08:16:44 +00:00
2019-05-12 10:41:19 +02:00
provider.checkValid();
2019-04-12 08:28:23 +02:00
return provider;
2018-12-29 15:04:22 +00:00
}
2019-07-15 16:15:37 +02:00
private static EmailProvider fromDNS(Context context, String domain) throws TextParseException, UnknownHostException {
2018-12-29 15:04:22 +00:00
// https://tools.ietf.org/html/rfc6186
2019-07-26 08:09:18 +02:00
SRVRecord imap;
boolean starttls;
try {
// Identifies an IMAP server where TLS is initiated directly upon connection to the IMAP server.
imap = lookup(context, "_imaps._tcp." + domain);
// ... service is not supported at all at a particular domain by setting the target of an SRV RR to "."
if (TextUtils.isEmpty(imap.getTarget().toString(true)))
throw new UnknownHostException(imap.toString());
starttls = false;
} catch (UnknownHostException ex) {
// Identifies an IMAP server that MAY ... require the MUA to use the "STARTTLS" command
imap = lookup(context, "_imap._tcp." + domain);
if (TextUtils.isEmpty(imap.getTarget().toString(true)))
throw new UnknownHostException(imap.toString());
starttls = (imap.getPort() == 143);
}
// Note that this covers connections both with and without Transport Layer Security (TLS)
2019-07-15 16:15:37 +02:00
SRVRecord smtp = lookup(context, "_submission._tcp." + domain);
2019-07-26 08:09:18 +02:00
if (TextUtils.isEmpty(smtp.getTarget().toString(true)))
throw new UnknownHostException(smtp.toString());
2018-12-29 15:04:22 +00:00
2019-01-13 15:23:04 +00:00
EmailProvider provider = new EmailProvider(domain);
2018-12-29 15:04:22 +00:00
provider.imap_host = imap.getTarget().toString(true);
provider.imap_port = imap.getPort();
2019-07-26 08:09:18 +02:00
provider.imap_starttls = starttls;
2018-12-29 15:04:22 +00:00
provider.smtp_host = smtp.getTarget().toString(true);
provider.smtp_port = smtp.getPort();
provider.smtp_starttls = (provider.smtp_port == 587);
2019-04-12 08:28:23 +02:00
return provider;
2019-01-06 08:16:44 +00:00
}
2019-04-12 08:38:15 +02:00
2019-07-24 08:42:37 +02:00
private static final ExecutorService executor =
Executors.newCachedThreadPool(Helper.backgroundThreadFactory);
2019-07-23 16:08:28 +02:00
private static class Server {
String host;
int port;
Future<Boolean> reachable;
Server(String domain, String prefix, int port) {
this.host = (prefix == null ? "" : prefix + ".") + domain;
this.port = port;
Log.i("Scanning " + host + ":" + port);
this.reachable = executor.submit(new Callable<Boolean>() {
@Override
public Boolean call() {
try (Socket socket = new Socket()) {
2019-07-27 16:39:45 +02:00
InetAddress[] iaddr = InetAddress.getAllByName(host);
for (int i = 0; i < iaddr.length; i++)
try {
Log.i("Connecting to " + iaddr[i]);
InetSocketAddress inetSocketAddress = new InetSocketAddress(iaddr[i], Server.this.port);
socket.connect(inetSocketAddress, DNS_TIMEOUT);
} catch (Throwable ex) {
if (i + 1 == iaddr.length)
throw ex;
}
2019-07-23 16:08:28 +02:00
Log.i("Reachable " + Server.this);
return true;
} catch (IOException ex) {
Log.i("Unreachable " + Server.this + ": " + Helper.formatThrowable(ex));
return false;
}
}
});
}
2019-04-12 08:38:15 +02:00
2019-07-23 16:08:28 +02:00
@Override
public String toString() {
return host + ":" + port;
}
}
2019-07-23 16:08:28 +02:00
private static EmailProvider fromTemplate(Context context, String domain)
throws ExecutionException, InterruptedException, UnknownHostException {
List<Server> imaps = new ArrayList<>();
List<Server> smtps = new ArrayList<>();
// SSL
imaps.add(new Server(domain, null, 993));
imaps.add(new Server(domain, "imap", 993));
imaps.add(new Server(domain, "mail", 993));
imaps.add(new Server(domain, "mx", 993));
// STARTTLS
imaps.add(new Server(domain, null, 143));
imaps.add(new Server(domain, "imap", 143));
imaps.add(new Server(domain, "mail", 143));
imaps.add(new Server(domain, "mx", 143));
// SSL
smtps.add(new Server(domain, null, 465));
smtps.add(new Server(domain, "smtp", 465));
smtps.add(new Server(domain, "mail", 465));
smtps.add(new Server(domain, "mx", 465));
// STARTTLS
smtps.add(new Server(domain, null, 587));
smtps.add(new Server(domain, "smtp", 587));
smtps.add(new Server(domain, "mail", 587));
smtps.add(new Server(domain, "mx", 587));
for (Server imap : imaps)
if (imap.reachable.get())
for (Server smtp : smtps)
if (smtp.reachable.get()) {
EmailProvider provider = new EmailProvider();
provider.name = domain;
provider.imap_host = imap.host;
provider.imap_port = imap.port;
provider.imap_starttls = (imap.port == 143);
provider.smtp_host = smtp.host;
provider.smtp_port = smtp.port;
provider.smtp_starttls = (smtp.port == 587);
return provider;
}
2019-07-23 16:08:28 +02:00
throw new UnknownHostException(domain + " template");
2019-04-12 08:38:15 +02:00
}
2019-01-06 08:16:44 +00:00
2019-01-13 15:23:04 +00:00
private static void addDocumentation(EmailProvider provider, String href, String title) {
2019-01-06 08:16:44 +00:00
if (provider.documentation == null)
provider.documentation = new StringBuilder();
else
provider.documentation.append("<br /><br />");
provider.documentation.append("<a href=\"").append(href).append("\">").append(title).append("</a>");
}
2019-01-13 15:23:04 +00:00
private static EmailProvider addSpecials(Context context, EmailProvider provider) {
2019-01-06 08:16:44 +00:00
if ("imap.gmail.com".equals(provider.imap_host))
2019-07-06 16:24:03 +02:00
provider.helpUrl = Helper.FAQ_URI + "#user-content-faq6";
if (provider.imap_host.endsWith("office365.com") ||
provider.imap_host.endsWith("live.com"))
provider.helpUrl = Helper.FAQ_URI + "#user-content-faq14";
2019-01-06 08:16:44 +00:00
2019-04-12 08:50:46 +02:00
if (provider.imap_host.endsWith("yahoo.com"))
2019-07-06 16:24:03 +02:00
provider.helpUrl = Helper.FAQ_URI + "#user-content-faq88";
2019-04-12 08:50:46 +02:00
2018-12-29 15:04:22 +00:00
return provider;
}
2019-07-15 16:15:37 +02:00
private static SRVRecord lookup(Context context, String record) throws TextParseException, UnknownHostException {
Lookup lookup = new Lookup(record, Type.SRV);
2018-12-29 15:04:22 +00:00
2019-07-15 16:15:37 +02:00
SimpleResolver resolver = new SimpleResolver(ConnectionHelper.getDnsServer(context));
2018-12-29 15:04:22 +00:00
lookup.setResolver(resolver);
2019-07-15 16:15:37 +02:00
Log.i("Lookup record=" + record + " @" + resolver.getAddress());
2018-12-29 15:04:22 +00:00
Record[] records = lookup.run();
2019-01-06 08:16:44 +00:00
2018-12-29 15:04:22 +00:00
if (lookup.getResult() != Lookup.SUCCESSFUL)
2019-07-14 13:30:04 +02:00
if (lookup.getResult() == Lookup.HOST_NOT_FOUND ||
lookup.getResult() == Lookup.TYPE_NOT_FOUND)
2019-07-15 16:15:37 +02:00
throw new UnknownHostException(record);
2018-12-29 15:04:22 +00:00
else
throw new IllegalArgumentException(lookup.getErrorString());
2019-01-06 08:16:44 +00:00
2019-07-15 16:15:37 +02:00
SRVRecord result = (records == null || records.length == 0 ? null : (SRVRecord) records[0]);
Log.i("Found record=" + (records == null ? -1 : records.length) +
" result=" + (result == null ? "" : result.toString()));
return result;
2018-12-29 15:04:22 +00:00
}
2018-08-02 13:33:06 +00:00
@Override
public String toString() {
return name;
}
}