MCPcopy Index your code
hub / github.com/foxcpp/maddy / ValidMailboxName

Function ValidMailboxName

framework/address/validation.go:68–110  ·  view source on GitHub ↗

ValidMailboxName checks whether the specified string is a valid mailbox-name element of e-mail address (left part of it, before at-sign).

(mbox string)

Source from the content-addressed store, hash-verified

66// ValidMailboxName checks whether the specified string is a valid mailbox-name
67// element of e-mail address (left part of it, before at-sign).
68func ValidMailboxName(mbox string) bool {
69 if strings.HasPrefix(mbox, `"`) {
70 raw, err := UnquoteMbox(mbox)
71 if err != nil {
72 return false
73 }
74
75 // Inside quotes, any ASCII graphic and space is allowed.
76 // Additionally, RFC 6531 extends that to allow any Unicode (UTF-8).
77 for _, ch := range raw {
78 if ch < ' ' || ch == 0x7F /* DEL */ {
79 // ASCII control characters.
80 return false
81 }
82 }
83 return true
84 }
85
86 // Without quotes, limited set of ASCII graphics is allowed + ASCII
87 // alphanumeric characters.
88 // RFC 6531 extends that to allow any Unicode (UTF-8).
89 for _, ch := range mbox {
90 if validGraphic[ch] {
91 continue
92 }
93 if ch >= '0' && ch <= '9' {
94 continue
95 }
96 if ch >= 'A' && ch <= 'Z' {
97 continue
98 }
99 if ch >= 'a' && ch <= 'z' {
100 continue
101 }
102 if ch > 0x7F { // Unicode
103 continue
104 }
105
106 return false
107 }
108
109 return true
110}
111
112// ValidDomain checks whether the specified string is a valid DNS domain.
113func ValidDomain(domain string) bool {

Callers 2

TestValidMailboxNameFunction · 0.92
ValidFunction · 0.85

Calls 1

UnquoteMboxFunction · 0.85

Tested by 1

TestValidMailboxNameFunction · 0.74