Small improvements

pull/162/head
M66B 5 years ago
parent a60de82922
commit 5b670a61bc

@ -23,6 +23,8 @@ import android.content.Context;
import android.content.res.XmlResourceParser; import android.content.res.XmlResourceParser;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.NonNull;
import org.xbill.DNS.Lookup; import org.xbill.DNS.Lookup;
import org.xbill.DNS.Record; import org.xbill.DNS.Record;
import org.xbill.DNS.SRVRecord; import org.xbill.DNS.SRVRecord;
@ -154,6 +156,7 @@ public class EmailProvider {
return result; return result;
} }
@NonNull
static EmailProvider fromDomain(Context context, String domain, Discover discover) throws IOException { static EmailProvider fromDomain(Context context, String domain, Discover discover) throws IOException {
List<EmailProvider> providers = loadProfiles(context); List<EmailProvider> providers = loadProfiles(context);
for (EmailProvider provider : providers) for (EmailProvider provider : providers)
@ -177,6 +180,7 @@ public class EmailProvider {
return autoconfig; return autoconfig;
} }
@NonNull
private static EmailProvider _fromDomain(Context context, String domain, Discover discover) throws IOException { private static EmailProvider _fromDomain(Context context, String domain, Discover discover) throws IOException {
try { try {
// Assume the provider knows best // Assume the provider knows best
@ -202,6 +206,7 @@ public class EmailProvider {
} }
} }
@NonNull
private static EmailProvider fromISPDB(Context context, String domain) throws IOException, XmlPullParserException { private static EmailProvider fromISPDB(Context context, String domain) throws IOException, XmlPullParserException {
EmailProvider provider = new EmailProvider(domain); EmailProvider provider = new EmailProvider(domain);
@ -382,6 +387,7 @@ public class EmailProvider {
return provider; return provider;
} }
@NonNull
private static EmailProvider fromDNS(Context context, String domain, Discover discover) throws TextParseException, UnknownHostException { private static EmailProvider fromDNS(Context context, String domain, Discover discover) throws TextParseException, UnknownHostException {
// https://tools.ietf.org/html/rfc6186 // https://tools.ietf.org/html/rfc6186
EmailProvider provider = new EmailProvider(domain); EmailProvider provider = new EmailProvider(domain);
@ -423,6 +429,7 @@ public class EmailProvider {
return provider; return provider;
} }
@NonNull
private static EmailProvider fromTemplate(Context context, String domain, Discover discover) private static EmailProvider fromTemplate(Context context, String domain, Discover discover)
throws ExecutionException, InterruptedException, UnknownHostException { throws ExecutionException, InterruptedException, UnknownHostException {
Server imap = null; Server imap = null;
@ -502,27 +509,31 @@ public class EmailProvider {
provider.documentation.append("<a href=\"").append(href).append("\">").append(title).append("</a>"); provider.documentation.append("<a href=\"").append(href).append("\">").append(title).append("</a>");
} }
private static SRVRecord lookup(Context context, String record) throws TextParseException, UnknownHostException { @NonNull
Lookup lookup = new Lookup(record, Type.SRV); private static SRVRecord lookup(Context context, String name) throws TextParseException, UnknownHostException {
Lookup lookup = new Lookup(name, Type.SRV);
SimpleResolver resolver = new SimpleResolver(ConnectionHelper.getDnsServer(context)); SimpleResolver resolver = new SimpleResolver(ConnectionHelper.getDnsServer(context));
lookup.setResolver(resolver); lookup.setResolver(resolver);
Log.i("Lookup record=" + record + " @" + resolver.getAddress()); Log.i("Lookup name=" + name + " @" + resolver.getAddress());
Record[] records = lookup.run(); Record[] records = lookup.run();
if (lookup.getResult() != Lookup.SUCCESSFUL) if (lookup.getResult() != Lookup.SUCCESSFUL)
if (lookup.getResult() == Lookup.HOST_NOT_FOUND || if (lookup.getResult() == Lookup.HOST_NOT_FOUND ||
lookup.getResult() == Lookup.TYPE_NOT_FOUND) lookup.getResult() == Lookup.TYPE_NOT_FOUND)
throw new UnknownHostException(record); throw new UnknownHostException(name);
else else
throw new IllegalArgumentException(lookup.getErrorString()); throw new IllegalArgumentException(lookup.getErrorString());
SRVRecord result = (records == null || records.length == 0 ? null : (SRVRecord) records[0]); if (records.length == 0)
Log.i("Found record=" + (records == null ? -1 : records.length) + throw new UnknownHostException(name);
" result=" + (result == null ? "" : result.toString()));
SRVRecord result = (SRVRecord) records[0];
Log.i("Found records=" + records.length + " result=" + result.toString());
return result; return result;
} }
@NonNull
@Override @Override
public String toString() { public String toString() {
return name; return name;
@ -567,6 +578,7 @@ public class EmailProvider {
}); });
} }
@NonNull
@Override @Override
public String toString() { public String toString() {
return host + ":" + port; return host + ":" + port;

Loading…
Cancel
Save