-
Notifications
You must be signed in to change notification settings - Fork 2
/
mailpopbox.go
69 lines (58 loc) · 1.42 KB
/
mailpopbox.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
// mailpopbox
// Copyright 2020 Blue Static <https://www.bluestatic.org>
// This program is free software licensed under the GNU General Public License,
// version 3.0. The full text of the license can be found in LICENSE.txt.
// SPDX-License-Identifier: GPL-3.0-only
package main
import (
"encoding/json"
"fmt"
"os"
"go.uber.org/zap"
)
func main() {
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "Usage: %s config.json\n", os.Args[0])
os.Exit(1)
}
if os.Args[1] == "version" {
fmt.Print(versionString)
os.Exit(0)
}
configFile, err := os.Open(os.Args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "config file: %s\n", err)
os.Exit(2)
}
var config Config
if err := json.NewDecoder(configFile).Decode(&config); err != nil {
fmt.Fprintf(os.Stderr, "config file: %s\n", err)
os.Exit(3)
}
configFile.Close()
logConfig := zap.NewDevelopmentConfig()
logConfig.Development = false
logConfig.DisableStacktrace = true
logConfig.Level.SetLevel(zap.DebugLevel)
log, err := logConfig.Build()
if err != nil {
fmt.Fprintf(os.Stderr, "create logger: %v\n", err)
os.Exit(4)
}
log.Info("starting mailpopbox", zap.String("hostname", config.Hostname))
pop3 := runPOP3Server(config, log)
smtp := runSMTPServer(config, log)
for {
select {
case cm := <-pop3:
if cm == ServerControlRestart {
pop3 = runPOP3Server(config, log)
} else {
break
}
case <-smtp:
// smtp never reloads.
break
}
}
}