ToASCII converts the domain part of the email address to the A-label form and fails with ErrUnicodeMailbox if the local-part contains non-ASCII characters.
(addr string)
| 30 | // ToASCII converts the domain part of the email address to the A-label form and |
| 31 | // fails with ErrUnicodeMailbox if the local-part contains non-ASCII characters. |
| 32 | func ToASCII(addr string) (string, error) { |
| 33 | mbox, domain, err := Split(addr) |
| 34 | if err != nil { |
| 35 | return addr, err |
| 36 | } |
| 37 | |
| 38 | for _, ch := range mbox { |
| 39 | if ch > 128 { |
| 40 | return addr, ErrUnicodeMailbox |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | if domain == "" { |
| 45 | return mbox, nil |
| 46 | } |
| 47 | |
| 48 | aDomain, err := idna.ToASCII(domain) |
| 49 | if err != nil { |
| 50 | return addr, err |
| 51 | } |
| 52 | |
| 53 | return mbox + "@" + aDomain, nil |
| 54 | } |
| 55 | |
| 56 | // ToUnicode converts the domain part of the email address to the U-label form. |
| 57 | func ToUnicode(addr string) (string, error) { |
no test coverage detected