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

Function EvaluateAlignment

internal/dmarc/evaluate.go:118–203  ·  view source on GitHub ↗

EvaluateAlignment checks whether identifiers authenticated by SPF and DKIM are in alignment with the RFC5322.Domain. It returns EvalResult which contains the Authres field with the actual check result and a bunch of other trace information that can be useful for troubleshooting (and also report gen

(fromDomain string, record *Record, results []authres.Result)

Source from the content-addressed store, hash-verified

116// a bunch of other trace information that can be useful for troubleshooting
117// (and also report generation).
118func EvaluateAlignment(fromDomain string, record *Record, results []authres.Result) EvalResult {
119 var (
120 spfAligned = false
121 spfResult = authres.SPFResult{}
122 dkimAligned = false
123 dkimResult = authres.DKIMResult{}
124 dkimPresent = false
125 dkimTempFail = false
126 )
127 for _, res := range results {
128 if dkimRes, ok := res.(*authres.DKIMResult); ok {
129 dkimPresent = true
130
131 // We want to return DKIM result for a signature provided by the orgDomain,
132 // in case there is none - return any (possibly misaligned) for reference.
133 if dkimResult.Value == "" {
134 dkimResult = *dkimRes
135 }
136 if isAligned(fromDomain, dkimRes.Domain, record.DKIMAlignment) {
137 dkimResult = *dkimRes
138 switch dkimRes.Value {
139 case authres.ResultPass:
140 dkimAligned = true
141 case authres.ResultTempError:
142 dkimTempFail = true
143 }
144 }
145 }
146 if spfRes, ok := res.(*authres.SPFResult); ok {
147 spfResult = *spfRes
148 var aligned bool
149 if spfRes.From == "" {
150 aligned = isAligned(fromDomain, spfRes.Helo, record.SPFAlignment)
151 } else {
152 aligned = isAligned(fromDomain, spfRes.From, record.SPFAlignment)
153 }
154 if aligned && spfRes.Value == authres.ResultPass {
155 spfAligned = true
156 }
157 }
158 }
159
160 res := EvalResult{
161 SPFResult: spfResult,
162 SPFAligned: spfAligned,
163 DKIMResult: dkimResult,
164 DKIMAligned: dkimAligned,
165 }
166
167 if !dkimPresent || spfResult.Value == "" {
168 res.Authres = authres.DMARCResult{
169 Value: authres.ResultNone,
170 Reason: "Not enough information (required checks are disabled)",
171 From: fromDomain,
172 }
173 return res
174 }
175

Callers 2

ApplyMethod · 0.85
TestEvaluateAlignmentFunction · 0.85

Calls 1

isAlignedFunction · 0.85

Tested by 1

TestEvaluateAlignmentFunction · 0.68