Add code to do a DNS MX lookup
This commit is contained in:
parent
32d76d04ae
commit
37196c6431
4 changed files with 52 additions and 0 deletions
|
@ -8,6 +8,7 @@ dependencies {
|
|||
|
||||
compileOnly(libs.xmlpull)
|
||||
implementation(libs.okhttp)
|
||||
implementation(libs.minidns.hla)
|
||||
|
||||
testImplementation(libs.kxml2)
|
||||
testImplementation(libs.jsoup)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package app.k9mail.autodiscovery.autoconfig
|
||||
|
||||
import org.minidns.hla.ResolverApi
|
||||
import org.minidns.record.MX
|
||||
|
||||
class MiniDnsMxResolver : MxResolver {
|
||||
override fun lookup(domain: String): List<String> {
|
||||
val result = ResolverApi.INSTANCE.resolve(domain, MX::class.java)
|
||||
return result.answersOrEmptySet
|
||||
.sortedBy { it.priority }
|
||||
.map { it.target.toString() }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package app.k9mail.autodiscovery.autoconfig
|
||||
|
||||
/**
|
||||
* Look up MX records for a domain.
|
||||
*/
|
||||
interface MxResolver {
|
||||
fun lookup(domain: String): List<String>
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package app.k9mail.autodiscovery.autoconfig
|
||||
|
||||
import assertk.all
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.containsExactlyInAnyOrder
|
||||
import assertk.assertions.index
|
||||
import assertk.assertions.isEqualTo
|
||||
import kotlin.test.Ignore
|
||||
import kotlin.test.Test
|
||||
|
||||
class MiniDnsMxResolverTest {
|
||||
private val resolver = MiniDnsMxResolver()
|
||||
|
||||
@Test
|
||||
@Ignore("Requires internet")
|
||||
fun `MX lookup for known domain`() {
|
||||
val result = resolver.lookup("thunderbird.net")
|
||||
|
||||
assertThat(result).all {
|
||||
index(0).isEqualTo("aspmx.l.google.com")
|
||||
containsExactlyInAnyOrder(
|
||||
"aspmx.l.google.com",
|
||||
"alt1.aspmx.l.google.com",
|
||||
"alt2.aspmx.l.google.com",
|
||||
"alt4.aspmx.l.google.com",
|
||||
"alt3.aspmx.l.google.com",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue