Bump the version to 2.1.0.
[mailpopbox.git] / config.go
1 // mailpopbox
2 // Copyright 2020 Blue Static <https://www.bluestatic.org>
3 // This program is free software licensed under the GNU General Public License,
4 // version 3.0. The full text of the license can be found in LICENSE.txt.
5 // SPDX-License-Identifier: GPL-3.0-only
6
7 package main
8
9 import (
10 "crypto/tls"
11 )
12
13 type Config struct {
14 SMTPPort int
15 POP3Port int
16
17 // Hostname is the name of the MX server that is running.
18 Hostname string
19
20 Servers []Server
21 }
22
23 const MailboxAccount = "mailbox@"
24
25 type Server struct {
26 // Domain is the second component of a mail address: <local-part@domain.com>.
27 Domain string
28
29 TLSKeyPath string
30 TLSCertPath string
31
32 // Password for the POP3 mailbox user, mailbox@domain.com.
33 MailboxPassword string
34
35 // Location to store the mail messages.
36 MaildropPath string
37
38 // Addresses that should not accept mail. This should include the @domain
39 // component.
40 BlockedAddresses []string
41 }
42
43 func (c Config) GetTLSConfig() (*tls.Config, error) {
44 certs := make([]tls.Certificate, 0, len(c.Servers))
45 for _, server := range c.Servers {
46 if server.TLSCertPath == "" {
47 continue
48 }
49
50 cert, err := tls.LoadX509KeyPair(server.TLSCertPath, server.TLSKeyPath)
51 if err != nil {
52 return nil, err
53 }
54 certs = append(certs, cert)
55 }
56
57 if len(certs) == 0 {
58 return nil, nil
59 }
60
61 config := &tls.Config{
62 Certificates: certs,
63 }
64 config.BuildNameToCertificate()
65 return config, nil
66 }