Filter SPF records

pull/214/head
M66B 1 year ago
parent a15293a73a
commit 4033d07417

@ -600,10 +600,9 @@ public class ActivityDMARC extends ActivityBase {
List<Pair<String, DnsHelper.DnsRecord>> result = new ArrayList<>();
try {
DnsHelper.DnsRecord[] records = DnsHelper.lookup(context, domain, "txt");
DnsHelper.DnsRecord[] records = DnsHelper.lookup(context, domain, "txt:v=spf1 ");
ssb.append(domain).append('=').append(Integer.toString(records.length)).append('\n');
for (DnsHelper.DnsRecord r : records)
if (r.response.contains("spf")) {
for (DnsHelper.DnsRecord r : records) {
result.add(new Pair<>(domain, r));
for (String part : r.response.split("\\s+"))
if (part.toLowerCase(Locale.ROOT).startsWith("include:")) {

@ -48,6 +48,7 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.Executor;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
@ -81,6 +82,13 @@ public class DnsHelper {
@NonNull
static DnsRecord[] lookup(Context context, String name, String type, int timeout) throws UnknownHostException {
String filter = null;
int colon = type.indexOf(':');
if (colon > 0) {
filter = type.substring(colon + 1);
type = type.substring(0, colon);
}
int rtype;
switch (type) {
case "ns":
@ -214,6 +222,9 @@ public class DnsHelper {
TXTRecord txt = (TXTRecord) record;
for (Object content : txt.getStrings()) {
String text = content.toString();
if (filter != null &&
(TextUtils.isEmpty(text) || !text.toLowerCase(Locale.ROOT).startsWith(filter)))
continue;
int i = 0;
int slash = text.indexOf('\\', i);
while (slash >= 0 && slash + 4 < text.length()) {

Loading…
Cancel
Save