Skip to content

Commit

Permalink
Add support for no service resource records "null mx" (#192)
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Schmidt <florian.schmidt.801187200@gmail.com>
  • Loading branch information
elmolm and Florian Schmidt committed Nov 20, 2023
1 parent 970e7a8 commit 1209b01
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/com/sanctionco/jmail/dns/DNSLookupUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public final class DNSLookupUtil {
private static final int DEFAULT_INITIAL_TIMEOUT = 100;
private static final int DEFAULT_RETRIES = 2;
private static final String NO_SERVICE_MX_PR_RDATA = "0 .";

/**
* Private constructor to prevent instantiation.
Expand Down Expand Up @@ -48,7 +49,7 @@ public static boolean hasMXRecord(String domain, int initialTimeout, int numRetr
DirContext ctx = new InitialDirContext(env);
Attribute attr = ctx.getAttributes(domain, new String[]{"MX"}).get("MX");

return attr != null && attr.size() > 0;
return attr != null && attr.size() > 0 && !attr.get(0).equals(NO_SERVICE_MX_PR_RDATA);
} catch (NamingException e) {
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/com/sanctionco/jmail/dns/DNSLookupUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ void failsToFindInvalidMXRecord() {
assertThat(DNSLookupUtil.hasMXRecord("whatis.hello")).isFalse();
}

@Test
void failsToNoServiceMXRecord() {
assertThat(DNSLookupUtil.hasMXRecord("gmail.de")).isFalse();
}

@Test
void customTimeoutWorksAsExpected() {
long startTime = System.currentTimeMillis();
Expand Down

0 comments on commit 1209b01

Please sign in to comment.