1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-03-19 02:15:28 +00:00

Ignore unrecoverable DNS errors

This commit is contained in:
M66B 2020-04-18 19:58:39 +02:00
parent 6dfec7a202
commit dc19b2c8f6
2 changed files with 25 additions and 19 deletions

View file

@ -106,17 +106,15 @@ public class DnsHelper {
Log.i("Lookup name=" + name + " @" + resolver.getAddress() + " type=" + rtype);
Record[] records = lookup.run();
if (lookup.getResult() != Lookup.SUCCESSFUL)
if (lookup.getResult() == Lookup.HOST_NOT_FOUND ||
lookup.getResult() == Lookup.TYPE_NOT_FOUND)
throw new UnknownHostException(name);
else
throw new UnknownHostException(lookup.getErrorString());
if (records.length == 0)
throw new UnknownHostException(name);
else if (lookup.getResult() != Lookup.SUCCESSFUL)
Log.w("DNS error=" + lookup.getErrorString());
List<DnsRecord> result = new ArrayList<>();
if (records != null)
for (Record record : records) {
Log.i("Found record=" + record);
if (record instanceof MXRecord) {
@ -198,6 +196,8 @@ public class DnsHelper {
checkMx(context, new Address[]{Log.myAddress()});
InetAddress iaddr = lookupMx(context, domain);
DnsRecord[] records = DnsHelper.lookup(context, "_imaps._tcp." + domain, "srv");
if (records.length == 0)
throw new UnknownHostException(domain);
Log.i("DNS iaddr=" + iaddr + " srv=" + records[0].name + ":" + records[0].port);
} catch (Throwable ex) {
Log.e("DNS", ex);

View file

@ -501,6 +501,8 @@ public class EmailProvider {
try {
// Identifies an IMAP server where TLS is initiated directly upon connection to the IMAP server.
DnsHelper.DnsRecord[] records = DnsHelper.lookup(context, "_imaps._tcp." + domain, "srv");
if (records.length == 0)
throw new UnknownHostException(domain);
// ... service is not supported at all at a particular domain by setting the target of an SRV RR to "."
provider.imap.host = records[0].name;
provider.imap.port = records[0].port;
@ -508,6 +510,8 @@ public class EmailProvider {
} catch (UnknownHostException ex) {
// Identifies an IMAP server that MAY ... require the MUA to use the "STARTTLS" command
DnsHelper.DnsRecord[] records = DnsHelper.lookup(context, "_imap._tcp." + domain, "srv");
if (records.length == 0)
throw new UnknownHostException(domain);
provider.imap.host = records[0].name;
provider.imap.port = records[0].port;
provider.imap.starttls = (provider.imap.port == 143);
@ -517,6 +521,8 @@ public class EmailProvider {
if (discover == Discover.ALL || discover == Discover.SMTP) {
// Note that this covers connections both with and without Transport Layer Security (TLS)
DnsHelper.DnsRecord[] records = DnsHelper.lookup(context, "_submission._tcp." + domain, "srv");
if (records.length == 0)
throw new UnknownHostException(domain);
provider.smtp.host = records[0].name;
provider.smtp.port = records[0].port;
provider.smtp.starttls = (provider.smtp.port == 587);