forked from mailhog/smtp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmtputf8.go
62 lines (47 loc) · 976 Bytes
/
smtputf8.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package smtp
import (
"fmt"
"strings"
"unicode"
)
type smtpUTF8Key int
const (
clientUTF8Status smtpUTF8Key = iota + 1
)
type smtpUTF8 struct{}
func (ex *smtpUTF8) EHLOKeyword() string {
return "SMTPUTF8"
}
func (ex *smtpUTF8) TLSOnly() bool {
return false
}
func (ex *smtpUTF8) Process(proto *Protocol, verb, args string) *Reply {
switch verb {
case "MAIL":
for _, part := range strings.Split(args, " ") {
if part != "SMTPUTF8" {
continue
}
proto.ExtensionData[clientUTF8Status] = struct{}{}
return nil
}
case "RCPT":
rcpt, err := proto.ParseRCPT(args)
if err != nil {
return nil
}
if _, exists := proto.ExtensionData[clientUTF8Status]; !exists && ex.IsNotASCII(rcpt) {
return ReplySyntaxError(fmt.Sprintf("unexpected non-ASCII address: %s", rcpt))
}
return nil
}
return nil
}
func (*smtpUTF8) IsNotASCII(s string) bool {
for _, r := range s {
if r > unicode.MaxASCII {
return true
}
}
return false
}