CleanDomain returns the address with the domain part converted into its canonical form. More specifically, converts the domain part of the address to U-labels, normalizes it to NFC and then case-folds it. Original value is also returned on the error.
(addr string)
| 68 | // |
| 69 | // Original value is also returned on the error. |
| 70 | func CleanDomain(addr string) (string, error) { |
| 71 | if addr == "" { // Null return-path |
| 72 | return "", nil |
| 73 | } |
| 74 | |
| 75 | mbox, domain, err := Split(addr) |
| 76 | if err != nil { |
| 77 | return addr, err |
| 78 | } |
| 79 | |
| 80 | uDomain, err := idna.ToUnicode(domain) |
| 81 | if err != nil { |
| 82 | return addr, err |
| 83 | } |
| 84 | uDomain = strings.ToLower(norm.NFC.String(uDomain)) |
| 85 | |
| 86 | if domain == "" { |
| 87 | return mbox, nil |
| 88 | } |
| 89 | |
| 90 | return mbox + "@" + uDomain, nil |
| 91 | } |
| 92 | |
| 93 | // Equal reports whether addr1 and addr2 are considered to be |
| 94 | // case-insensitively equivalent. |
no test coverage detected