mirror of
https://github.com/hanzoai/mail.git
synced 2026-09-23 23:53:02 +00:00
Fork of github.com/mjl-/mox at 5656ca6d1b
(upstream v0.0.15 plus 55 commits).
Rename the module path in go.mod and the import paths in 268 Go files. Also
update the five scripts that "go install" the module (genwebsite.sh,
docker-release.sh, apidiff.sh, test-upgrade.sh, Dockerfile.release), which
would otherwise build upstream rather than this fork.
Add NOTICE recording the upstream project, author, license, and fork point,
and stating which license covers which files: MIT for the mox source and our
changes, MPL-2.0 for publicsuffix/public_suffix_list.txt alone, and the
vendored dependencies' own licenses under licenses/. Embed NOTICE so
"mail licenses" prints the lineage from the running binary. LICENSE.MIT,
LICENSE.MPLv2.0 and the licenses/ tree are preserved verbatim; no code is
relicensed.
The mox command name, config keys, data directory layout and website content
are unchanged. LLM.md records the fork point, the rename, what was left alone,
and the steps to stand the server up.
Co-authored-by: Hanzo Dev <[email protected]>
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package smtpserver
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
|
|
"github.com/hanzoai/mail/dns"
|
|
)
|
|
|
|
// checks if domain can accept email.
|
|
// i.e. if it has no null mx record, regular mx records or resolve to an address.
|
|
func checkMXRecords(ctx context.Context, resolver dns.Resolver, d dns.Domain) (bool, error) {
|
|
// Note: LookupMX can return an error and still return records.
|
|
mx, _, err := resolver.LookupMX(ctx, d.ASCII+".")
|
|
if err == nil && len(mx) == 1 && mx[0].Host == "." {
|
|
// Null MX record, explicit signal that remote does not accept email.
|
|
return false, nil
|
|
}
|
|
// Treat all errors that are not "no mx record" as temporary. E.g. timeout, malformed record, remote server error.
|
|
if err != nil && !dns.IsNotFound(err) {
|
|
return false, err
|
|
}
|
|
if len(mx) == 0 {
|
|
mx = []*net.MX{{Host: d.ASCII + "."}}
|
|
}
|
|
var lastErr error
|
|
for _, x := range mx {
|
|
ips, _, err := resolver.LookupIPAddr(ctx, x.Host)
|
|
if len(ips) > 0 {
|
|
return true, nil
|
|
}
|
|
if err != nil && !dns.IsNotFound(err) {
|
|
lastErr = err
|
|
}
|
|
}
|
|
return false, lastErr
|
|
}
|