forked from alash3al/go-smtpsrv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
44 lines (36 loc) · 836 Bytes
/
helpers.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
package smtpsrv
import (
"errors"
"strings"
"time"
)
// SplitAddress split the [email protected] to <user>@<domain>
func SplitAddress(address string) (string, string, error) {
sepInd := strings.LastIndex(address, "@")
if sepInd == -1 {
return "", "", errors.New("Invalid Address:" + address)
}
localPart := address[:sepInd]
domainPart := address[sepInd+1:]
return localPart, domainPart, nil
}
func SetDefaultServerConfig(cfg *ServerConfig) {
if cfg == nil {
*cfg = ServerConfig{}
}
if cfg.ListenAddr == "" {
cfg.ListenAddr = "[::]:25025"
}
if cfg.BannerDomain == "" {
cfg.BannerDomain = "localhost"
}
if cfg.ReadTimeout < 1 {
cfg.ReadTimeout = 2 * time.Second
}
if cfg.WriteTimeout < 1 {
cfg.WriteTimeout = 2 * time.Second
}
if cfg.MaxMessageBytes < 1 {
cfg.MaxMessageBytes = 1024 * 1024 * 2
}
}