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

Function ToASCII

framework/address/rfc6531.go:32–54  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
32func 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.
57func ToUnicode(addr string) (string, error) {

Callers 3

MailMethod · 0.92
RcptMethod · 0.92
SelectIDNAFunction · 0.85

Calls 1

SplitFunction · 0.85

Tested by

no test coverage detected