Move the mailbox@ string to a MailboxAccount constant.
[mailpopbox.git] / config.go
1 package main
2
3 import (
4 "crypto/tls"
5 )
6
7 type Config struct {
8 SMTPPort int
9 POP3Port int
10
11 // Hostname is the name of the MX server that is running.
12 Hostname string
13
14 Servers []Server
15 }
16
17 const MailboxAccount = "mailbox@"
18
19 type Server struct {
20 // Domain is the second component of a mail address: <local-part@domain.com>.
21 Domain string
22
23 TLSKeyPath string
24 TLSCertPath string
25
26 // Password for the POP3 mailbox user, mailbox@domain.com.
27 MailboxPassword string
28
29 // Location to store the mail messages.
30 MaildropPath string
31
32 // Blacklisted addresses that should not accept mail.
33 BlacklistedAddresses []string
34 }
35
36 func (c Config) GetTLSConfig() (*tls.Config, error) {
37 certs := make([]tls.Certificate, 0, len(c.Servers))
38 for _, server := range c.Servers {
39 if server.TLSCertPath == "" {
40 continue
41 }
42
43 cert, err := tls.LoadX509KeyPair(server.TLSCertPath, server.TLSKeyPath)
44 if err != nil {
45 return nil, err
46 }
47 certs = append(certs, cert)
48 }
49
50 if len(certs) == 0 {
51 return nil, nil
52 }
53
54 config := &tls.Config{
55 Certificates: certs,
56 }
57 config.BuildNameToCertificate()
58 return config, nil
59 }