-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
configuration.go
50 lines (45 loc) · 1.92 KB
/
configuration.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
package truemail
import (
"context"
"regexp"
)
// Configuration structure
type Configuration struct {
ctx context.Context
VerifierEmail, VerifierDomain, ValidationTypeDefault, Dns string
ConnectionTimeout, ResponseTimeout, ConnectionAttempts, SmtpPort int
WhitelistedDomains, BlacklistedDomains, BlacklistedMxIpAddresses []string
ValidationTypeByDomain map[string]string
WhitelistValidation, NotRfcMxLookupFlow, SmtpFailFast, SmtpSafeCheck bool
EmailPattern, SmtpErrorBodyPattern *regexp.Regexp
}
// NewConfiguration returns new valid newConfiguration structure
func NewConfiguration(config ConfigurationAttr) (*Configuration, error) {
config.assignDefaultValues()
err := config.validate()
if err != nil {
return nil, err
}
newConfiguration := Configuration{
ctx: config.ctx,
VerifierEmail: config.VerifierEmail,
VerifierDomain: config.VerifierDomain,
ValidationTypeDefault: config.ValidationTypeDefault,
ConnectionTimeout: config.ConnectionTimeout,
ResponseTimeout: config.ResponseTimeout,
ConnectionAttempts: config.ConnectionAttempts,
WhitelistedDomains: config.WhitelistedDomains,
BlacklistedDomains: config.BlacklistedDomains,
BlacklistedMxIpAddresses: config.BlacklistedMxIpAddresses,
Dns: config.Dns,
ValidationTypeByDomain: config.ValidationTypeByDomain,
WhitelistValidation: config.WhitelistValidation,
NotRfcMxLookupFlow: config.NotRfcMxLookupFlow,
SmtpPort: config.SmtpPort,
SmtpFailFast: config.SmtpFailFast,
SmtpSafeCheck: config.SmtpSafeCheck,
EmailPattern: config.RegexEmail,
SmtpErrorBodyPattern: config.RegexSmtpErrorBody,
}
return &newConfiguration, err
}