Skip to content

Commit c545c7c

Browse files
committed
Add basic checking of mx records for mailto links
Helps ensure that the domain is registered and at least partially configured to recieve email.
1 parent d42cbee commit c545c7c

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

htmltest/check-link.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"path"
1212
"strings"
13+
"net"
1314
"fmt"
1415
)
1516

@@ -349,6 +350,34 @@ func (hT *HTMLTest) checkMailto(ref *htmldoc.Reference) {
349350
})
350351
return
351352
}
353+
domain := strings.Split(ref.URL.Opaque, "@")[1]
354+
_, err := net.LookupMX(domain)
355+
if err != nil {
356+
if dnserr, ok := err.(*net.DNSError); ok {
357+
switch dnserr.Err {
358+
case "no such host":
359+
hT.issueStore.AddIssue(issues.Issue{
360+
Level: issues.LevelError,
361+
Message: "domain contains no valid MX records",
362+
Reference: ref,
363+
})
364+
break
365+
default:
366+
hT.issueStore.AddIssue(issues.Issue{
367+
Level: issues.LevelError,
368+
Message: "unable to perform LookupMX, unkown error",
369+
Reference: ref,
370+
})
371+
}
372+
} else {
373+
hT.issueStore.AddIssue(issues.Issue{
374+
Level: issues.LevelWarning,
375+
Message: "unable to perform LookupMX, unkown error",
376+
Reference: ref,
377+
})
378+
}
379+
return
380+
}
352381
}
353382

354383
func (hT *HTMLTest) checkTel(ref *htmldoc.Reference) {

htmltest/check-link_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,20 @@ func TestMailtoBlank(t *testing.T) {
383383
tExpectIssue(t, hT, "mailto is empty", 1)
384384
}
385385

386-
func TestMailtoInvalid(t *testing.T) {
386+
func TestMailtoInvalidFormat(t *testing.T) {
387387
// fails for invalid mailto links
388388
hT := tTestFile("fixtures/links/invalid_mailto_link.html")
389389
tExpectIssueCount(t, hT, 1)
390390
tExpectIssue(t, hT, "contains an invalid email address", 1)
391391
}
392392

393+
func TestMailtoInvalidMx(t *testing.T) {
394+
// fails for invalid mailto links
395+
hT := tTestFile("fixtures/links/invalid_mailto_mx.html")
396+
tExpectIssueCount(t, hT, 1)
397+
tExpectIssue(t, hT, "domain contains no valid MX records", 1)
398+
}
399+
393400
func TestMailtoIgnore(t *testing.T) {
394401
// ignores mailto links when told to
395402
hT := tTestFileOpts("fixtures/links/blank_mailto_link.html",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
3+
<body>
4+
5+
<a href="mailto:[email protected]">Meow me</a>
6+
7+
</body>
8+
9+
</html>

0 commit comments

Comments
 (0)