MCPcopy Create free account
hub / github.com/foxcpp/maddy / Apply

Method Apply

internal/dmarc/verifier.go:129–174  ·  view source on GitHub ↗

Apply actually performs all actions necessary to apply a DMARC policy to the message. The authRes slice should contain results for DKIM and SPF checks. FetchRecord should be caled before calling this function. It returns the Authentication-Result field to be included in the message (as a part of t

(authRes []authres.Result)

Source from the content-addressed store, hash-verified

127// Additionally, it relies on the math/rand default source to be initialized to determine
128// whether to apply a policy with the pct key.
129func (v *Verifier) Apply(authRes []authres.Result) (EvalResult, Policy) {
130 data := <-v.fetchCh
131 if data.recordErr != nil {
132 result := authres.DMARCResult{
133 Value: authres.ResultPermError,
134 Reason: "Policy lookup failed: " + data.recordErr.Error(),
135 // If may be empty, but it is fine (it will not be included in the field then).
136 From: data.fromDomain,
137 }
138 if dnsErr, ok := data.recordErr.(*net.DNSError); ok && dnsErr.Temporary() {
139 result.Value = authres.ResultTempError
140 // 'fail closed' behavior, reject the message if a temporary error
141 // occurs.
142 return EvalResult{
143 Authres: result,
144 }, dmarc.PolicyReject
145 }
146 return EvalResult{
147 Authres: result,
148 }, dmarc.PolicyNone
149 }
150 if data.record == nil {
151 return EvalResult{
152 Authres: authres.DMARCResult{
153 Value: authres.ResultNone,
154 From: data.fromDomain,
155 },
156 }, dmarc.PolicyNone
157 }
158
159 result := EvaluateAlignment(data.fromDomain, data.record, authRes)
160 if result.Authres.Value == authres.ResultPass || result.Authres.Value == authres.ResultNone {
161 return result, dmarc.PolicyNone
162 }
163
164 if data.record.Percent != nil && rand.Int31n(100) > int32(*data.record.Percent) {
165 return result, dmarc.PolicyNone
166 }
167
168 policy := data.record.Policy
169 if !strings.EqualFold(data.policyDomain, data.fromDomain) && data.record.SubdomainPolicy != "" {
170 policy = data.record.SubdomainPolicy
171 }
172
173 return result, policy
174}

Callers 1

TestDMARCFunction · 0.95

Calls 3

EvaluateAlignmentFunction · 0.85
TemporaryMethod · 0.65
ErrorMethod · 0.45

Tested by 1

TestDMARCFunction · 0.76