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)
| 36 | // |
| 37 | // On error, case-folded addr is also returned. |
| 38 | func 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 | // |
no test coverage detected