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

Function ForLookup

framework/dns/norm.go:41–53  ·  view source on GitHub ↗

ForLookup converts the domain into a canonical form suitable for table lookups and other comparisons. TL;DR Use this instead of strings.ToLower to prepare domain for lookups. Domains that contain invalid UTF-8 or invalid A-label domains are simply converted to local-case using strings.ToLower, but

(domain string)

Source from the content-addressed store, hash-verified

39// domains are simply converted to local-case using strings.ToLower, but the
40// error is also returned.
41func ForLookup(domain string) (string, error) {
42 uDomain, err := idna.ToUnicode(domain)
43 if err != nil {
44 return strings.ToLower(domain), err
45 }
46
47 // Side note: strings.ToLower does not support full case-folding, so it is
48 // important to apply NFC normalization first.
49 uDomain = norm.NFC.String(uDomain)
50 uDomain = strings.ToLower(uDomain)
51 uDomain = strings.TrimSuffix(uDomain, ".")
52 return uDomain, nil
53}
54
55// Equal reports whether domain1 and domain2 are equivalent as defined by
56// IDNA2008 (RFC 5890).

Callers 7

ForLookupFunction · 0.92
precisEmailFunction · 0.92
ConfigureMethod · 0.92
RewriteBodyMethod · 0.92
parseMsgPipelineRootCfgFunction · 0.92
parseMsgPipelineSrcCfgFunction · 0.92
EqualFunction · 0.70

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected