Skip to content

Commit

Permalink
Merge pull request #7393 from thunderbird/fix_mx_lookup_crash
Browse files Browse the repository at this point in the history
Avoid crash when MX lookup returns invalid hostname
  • Loading branch information
cketti authored Nov 30, 2023
2 parents 0fcc98f + b4f255c commit 582c5bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ value class Domain(val value: String) {
}

fun String.toDomain() = Domain(this)

@Suppress("SwallowedException")
fun String.toDomainOrNull(): Domain? {
return try {
toDomain()
} catch (e: IllegalArgumentException) {
null
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app.k9mail.autodiscovery.autoconfig

import app.k9mail.core.common.net.Domain
import app.k9mail.core.common.net.toDomain
import app.k9mail.core.common.net.toDomainOrNull
import org.minidns.hla.ResolverApi
import org.minidns.record.MX

Expand All @@ -11,7 +11,7 @@ internal class MiniDnsMxResolver : MxResolver {

val mxNames = result.answersOrEmptySet
.sortedBy { it.priority }
.map { it.target.toString().toDomain() }
.mapNotNull { it.target.toString().toDomainOrNull() }

return MxLookupResult(
mxNames = mxNames,
Expand Down

0 comments on commit 582c5bb

Please sign in to comment.