MCPcopy Index your code
hub / github.com/foxcpp/maddy / FetchRecord

Function FetchRecord

internal/dmarc/evaluate.go:40–88  ·  view source on GitHub ↗

FetchRecord looks up the DMARC record relevant for the RFC5322.From domain. It returns the record and the domain it was found with (may not be equal to the RFC5322.From domain).

(ctx context.Context, r Resolver, fromDomain string)

Source from the content-addressed store, hash-verified

38// It returns the record and the domain it was found with (may not be
39// equal to the RFC5322.From domain).
40func FetchRecord(ctx context.Context, r Resolver, fromDomain string) (policyDomain string, rec *Record, err error) {
41 policyDomain = fromDomain
42
43 // 1. Lookup using From Domain.
44 txts, err := r.LookupTXT(ctx, dns.FQDN("_dmarc."+fromDomain))
45 if err != nil {
46 dnsErr, ok := err.(*net.DNSError)
47 if !ok || !dnsErr.IsNotFound {
48 return "", nil, err
49 }
50 }
51 if len(txts) == 0 {
52 // No records or 'no such host', try orgDomain.
53 orgDomain, err := publicsuffix.EffectiveTLDPlusOne(fromDomain)
54 if err != nil {
55 return "", nil, err
56 }
57
58 policyDomain = orgDomain
59
60 txts, err = r.LookupTXT(ctx, dns.FQDN("_dmarc."+orgDomain))
61 if err != nil {
62 dnsErr, ok := err.(*net.DNSError)
63 if !ok || !dnsErr.IsNotFound {
64 return "", nil, err
65 }
66 }
67 // Still nothing? Bail out.
68 if len(txts) == 0 {
69 return "", nil, nil
70 }
71 }
72
73 // Exclude records that are not DMARC policies.
74 records := txts[:0]
75 for _, txt := range txts {
76 if strings.HasPrefix(txt, "v=DMARC1") {
77 records = append(records, txt)
78 }
79 }
80 // Multiple records => no record.
81 if len(records) > 1 || len(records) == 0 {
82 return "", nil, nil
83 }
84
85 rec, err = dmarc.Parse(records[0])
86
87 return policyDomain, rec, err
88}
89
90type EvalResult struct {
91 // The Authentication-Results field generated as a result of the DMARC

Callers 1

FetchRecordMethod · 0.85

Calls 2

FQDNFunction · 0.92
LookupTXTMethod · 0.65

Tested by

no test coverage detected