-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
66 lines (51 loc) · 1.37 KB
/
config.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
// 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 (
"crypto/tls"
)
type Config struct {
SMTPPort int
POP3Port int
// Hostname is the name of the MX server that is running.
Hostname string
Servers []Server
}
const MailboxAccount = "mailbox@"
type Server struct {
// Domain is the second component of a mail address: <[email protected]>.
Domain string
TLSKeyPath string
TLSCertPath string
// Password for the POP3 mailbox user, [email protected].
MailboxPassword string
// Location to store the mail messages.
MaildropPath string
// Addresses that should not accept mail. This should include the @domain
// component.
BlockedAddresses []string
}
func (c Config) GetTLSConfig() (*tls.Config, error) {
certs := make([]tls.Certificate, 0, len(c.Servers))
for _, server := range c.Servers {
if server.TLSCertPath == "" {
continue
}
cert, err := tls.LoadX509KeyPair(server.TLSCertPath, server.TLSKeyPath)
if err != nil {
return nil, err
}
certs = append(certs, cert)
}
if len(certs) == 0 {
return nil, nil
}
config := &tls.Config{
Certificates: certs,
}
config.BuildNameToCertificate()
return config, nil
}