-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
77 lines (66 loc) · 1.46 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"flag"
"log"
"sync"
"github.com/mailhog/MailHog-MTA/config"
"github.com/mailhog/MailHog-MTA/smtp"
"github.com/mailhog/backends/auth"
sconfig "github.com/mailhog/backends/config"
"github.com/mailhog/backends/delivery"
"github.com/mailhog/backends/resolver"
)
var conf *config.Config
var wg sync.WaitGroup
func configure() {
config.RegisterFlags()
flag.Parse()
conf = config.Configure()
}
func main() {
configure()
for _, s := range conf.Servers {
wg.Add(1)
go func(s *config.Server) {
defer wg.Done()
err := newServer(conf, s)
if err != nil {
log.Fatal(err)
}
}(s)
}
wg.Wait()
}
func newServer(cfg *config.Config, server *config.Server) error {
var a, d, r sconfig.BackendConfig
var err error
if server.Backends.Auth != nil {
a, err = server.Backends.Auth.Resolve(cfg.Backends)
if err != nil {
return err
}
}
if server.Backends.Delivery != nil {
d, err = server.Backends.Delivery.Resolve(cfg.Backends)
if err != nil {
return err
}
}
if server.Backends.Resolver != nil {
r, err = server.Backends.Resolver.Resolve(cfg.Backends)
if err != nil {
return err
}
}
s := &smtp.Server{
BindAddr: server.BindAddr,
Hostname: server.Hostname,
PolicySet: server.PolicySet,
AuthBackend: auth.Load(a, *cfg),
DeliveryBackend: delivery.Load(d, *cfg),
ResolverBackend: resolver.Load(r, *cfg),
Config: cfg,
Server: server,
}
return s.Listen()
}