DMARC: simplification

pull/214/head
M66B 2 years ago
parent 89a4d3ea6d
commit 9c09ce442f

@ -500,18 +500,13 @@ public class ActivityDmarc extends ActivityBase {
if (ip.startsWith("ip4:") || ip.startsWith("ip6:")) { if (ip.startsWith("ip4:") || ip.startsWith("ip6:")) {
String[] net = ip.substring(4).split("/"); String[] net = ip.substring(4).split("/");
Integer prefix = (net.length > 1 ? Helper.parseInt(net[1]) : null); Integer prefix = (net.length > 1 ? Helper.parseInt(net[1]) : null);
if (prefix == null) { if (prefix == null
if (text.equals(net[0])) { ? text.equals(net[0])
: ConnectionHelper.inSubnet(text, net[0], prefix)) {
valid = allow; valid = allow;
because = (allow ? '+' : '-') + ip + " in " + p.first; because = (allow ? '+' : '-') + ip + " in " + p.first;
break; break;
} }
} else {
if (ConnectionHelper.inSubnet(text, net[0], prefix)) {
valid = allow;
because = (allow ? '+' : '-') + ip + " in " + p.first + "/" + prefix;
}
}
} else if ("a".equals(ip) || ip.startsWith("a:")) { } else if ("a".equals(ip) || ip.startsWith("a:")) {
String domain = (ip.startsWith("a:") ? ip.substring(2) : p.first); String domain = (ip.startsWith("a:") ? ip.substring(2) : p.first);
String[] net = domain.split("/"); String[] net = domain.split("/");
@ -526,19 +521,14 @@ public class ActivityDmarc extends ActivityBase {
} catch (UnknownHostException ignored) { } catch (UnknownHostException ignored) {
} }
for (DnsHelper.DnsRecord a : as) for (DnsHelper.DnsRecord a : as)
if (prefix == null) { if (prefix == null
if (text.equals(a.response)) { ? text.equals(a.response)
valid = allow; : ConnectionHelper.inSubnet(text, a.response, prefix)) {
because = (allow ? '+' : '-') + ip + " in " + domain;
break;
}
} else {
if (ConnectionHelper.inSubnet(text, a.response, prefix)) {
valid = allow; valid = allow;
because = (allow ? '+' : '-') + ip + " in " + domain + "/" + prefix; because = (allow ? '+' : '-') + ip +
" in " + domain + (prefix == null ? "" : "/" + prefix);
break; break;
} }
}
} else if ("mx".equals(ip) || ip.startsWith("mx:")) { } else if ("mx".equals(ip) || ip.startsWith("mx:")) {
try { try {
String domain = (ip.startsWith("mx:") ? ip.substring(3) : p.first); String domain = (ip.startsWith("mx:") ? ip.substring(3) : p.first);
@ -556,19 +546,14 @@ public class ActivityDmarc extends ActivityBase {
} catch (UnknownHostException ignored) { } catch (UnknownHostException ignored) {
} }
for (DnsHelper.DnsRecord a : as) { for (DnsHelper.DnsRecord a : as) {
if (prefix == null) { if (prefix == null
if (text.equals(a.response)) { ? text.equals(a.response)
: ConnectionHelper.inSubnet(text, a.response, prefix)) {
valid = allow; valid = allow;
because = (allow ? '+' : '-') + ip + " in " + domain; because = (allow ? '+' : '-') + ip +
" in " + domain + (prefix == null ? "" : "/" + prefix);
break; break;
} }
} else {
if (ConnectionHelper.inSubnet(text, a.response, prefix)) {
valid = allow;
because = (allow ? '+' : '-') + ip + " in " + domain + "/" + prefix;
break;
}
}
} }
if (valid != null) if (valid != null)
break; break;

Loading…
Cancel
Save