mirror of https://github.com/M66B/FairEmail.git
Added support for cname records on looking op srv records
This commit is contained in:
parent
bdaaf46e86
commit
80a2b032bc
|
@ -28,6 +28,7 @@ import android.os.Build;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import org.xbill.DNS.CNAMERecord;
|
||||||
import org.xbill.DNS.Lookup;
|
import org.xbill.DNS.Lookup;
|
||||||
import org.xbill.DNS.MXRecord;
|
import org.xbill.DNS.MXRecord;
|
||||||
import org.xbill.DNS.Record;
|
import org.xbill.DNS.Record;
|
||||||
|
@ -102,6 +103,11 @@ public class DnsHelper {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
static DnsRecord[] lookup(Context context, String name, String type) throws UnknownHostException {
|
static DnsRecord[] lookup(Context context, String name, String type) throws UnknownHostException {
|
||||||
|
return _lookup(context, name, type, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
static DnsRecord[] _lookup(Context context, String name, String type, int redirects) throws UnknownHostException {
|
||||||
int rtype;
|
int rtype;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "mx":
|
case "mx":
|
||||||
|
@ -139,6 +145,11 @@ public class DnsHelper {
|
||||||
} else if (record instanceof SRVRecord) {
|
} else if (record instanceof SRVRecord) {
|
||||||
SRVRecord srv = (SRVRecord) record;
|
SRVRecord srv = (SRVRecord) record;
|
||||||
result.add(new DnsRecord(srv.getTarget().toString(true), srv.getPort()));
|
result.add(new DnsRecord(srv.getTarget().toString(true), srv.getPort()));
|
||||||
|
} else if (record instanceof CNAMERecord) {
|
||||||
|
if (++redirects > 3)
|
||||||
|
throw new UnknownHostException("Too many cname records");
|
||||||
|
CNAMERecord cname = (CNAMERecord) record;
|
||||||
|
return _lookup(context, cname.getTarget().toString(true), type, redirects);
|
||||||
} else
|
} else
|
||||||
throw new IllegalArgumentException(record.getClass().getName());
|
throw new IllegalArgumentException(record.getClass().getName());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue