#13: implement Outbound Queue, Retry Backoff Engine & DSN Bounce Generator (RFC 3464)
This commit is contained in:
1 parent
45aaf2a279
commit
af35211094
12 files changed
+886
-68
No files matched your search
@@ -0,0 +1,40 @@
|
||||
package netdns
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type NetMXResolver struct{}
|
||||
|
||||
func NewNetMXResolver() *NetMXResolver {
|
||||
return &NetMXResolver{}
|
||||
}
|
||||
|
||||
func (r *NetMXResolver) LookupMX(ctx context.Context, domain string) ([]string, error) {
|
||||
mxs, err := net.DefaultResolver.LookupMX(ctx, domain)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("lookup mx for %s: %w", domain, err)
|
||||
}
|
||||
|
||||
sort.Slice(mxs, func(i, j int) bool {
|
||||
return mxs[i].Pref < mxs[j].Pref
|
||||
})
|
||||
|
||||
var hosts []string
|
||||
for _, mx := range mxs {
|
||||
h := strings.TrimSuffix(mx.Host, ".")
|
||||
if h != "" {
|
||||
hosts = append(hosts, h)
|
||||
}
|
||||
}
|
||||
|
||||
if len(hosts) == 0 {
|
||||
hosts = []string{domain}
|
||||
}
|
||||
|
||||
return hosts, nil
|
||||
}
|
||||
Reference in new issue
Block a user