6 "github.com/mjl-/mox/dkim"
7 "github.com/mjl-/mox/dns"
8 "github.com/mjl-/mox/mlog"
9 "github.com/mjl-/mox/publicsuffix"
10 "github.com/mjl-/mox/spf"
11 "github.com/mjl-/mox/store"
14// Alignment compares the msgFromDomain with the dkim and spf results, and returns
15// a validation, one of: Strict, Relaxed, None.
16func alignment(ctx context.Context, log mlog.Log, msgFromDomain dns.Domain, dkimResults []dkim.Result, spfStatus spf.Status, spfIdentity *dns.Domain) store.Validation {
17 var strict, relaxed bool
18 msgFromOrgDomain := publicsuffix.Lookup(ctx, log.Logger, msgFromDomain)
20 // todo: should take temperror and permerror into account.
21 for _, dr := range dkimResults {
22 if dr.Status != dkim.StatusPass || dr.Sig == nil {
25 if dr.Sig.Domain == msgFromDomain {
29 relaxed = relaxed || msgFromOrgDomain == publicsuffix.Lookup(ctx, log.Logger, dr.Sig.Domain)
32 if !strict && spfStatus == spf.StatusPass {
33 strict = msgFromDomain == *spfIdentity
34 relaxed = relaxed || msgFromOrgDomain == publicsuffix.Lookup(ctx, log.Logger, *spfIdentity)
37 return store.ValidationStrict
40 return store.ValidationRelaxed
42 return store.ValidationNone