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

Function ForLookup

framework/address/norm.go:38–62  ·  view source on GitHub ↗

ForLookup transforms the local-part of the address into a canonical form usable for map lookups or direct comparisons. If Equal(addr1, addr2) == true, then ForLookup(addr1) == ForLookup(addr2). On error, case-folded addr is also returned.

(addr string)

Source from the content-addressed store, hash-verified

36//
37// On error, case-folded addr is also returned.
38func ForLookup(addr string) (string, error) {
39 if addr == "" { // Null return-path case.
40 return "", nil
41 }
42
43 mbox, domain, err := Split(addr)
44 if err != nil {
45 return strings.ToLower(addr), err
46 }
47
48 if domain != "" {
49 domain, err = dns.ForLookup(domain)
50 if err != nil {
51 return strings.ToLower(addr), err
52 }
53 }
54
55 mbox = strings.ToLower(norm.NFC.String(mbox))
56
57 if domain == "" {
58 return mbox, nil
59 }
60
61 return mbox + "@" + domain, nil
62}
63
64// CleanDomain returns the address with the domain part converted into its canonical form.
65//

Callers 6

rewriteMethod · 0.92
srcBlockForAddrMethod · 0.92
rcptBlockForAddrMethod · 0.92
parseMsgPipelineRootCfgFunction · 0.92
parseMsgPipelineSrcCfgFunction · 0.92
EqualFunction · 0.70

Calls 3

ForLookupFunction · 0.92
SplitFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected