Add license information.
[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 type Server struct {
24 // Domain is the second component of a mail address: <local-part@domain.com>.
25 Domain string
26
27 TLSKeyPath string
28 TLSCertPath string
29
30 // Password for the POP3 mailbox user, mailbox@domain.com.
31 MailboxPassword string
32
33 // Location to store the mail messages.
34 MaildropPath string
35
36 // Blacklisted addresses that should not accept mail.
37 BlacklistedAddresses []string
38 }
39
40 func (c Config) GetTLSConfig() (*tls.Config, error) {
41 certs := make([]tls.Certificate, 0, len(c.Servers))
42 for _, server := range c.Servers {
43 if server.TLSCertPath == "" {
44 continue
45 }
46
47 cert, err := tls.LoadX509KeyPair(server.TLSCertPath, server.TLSKeyPath)
48 if err != nil {
49 return nil, err
50 }
51 certs = append(certs, cert)
52 }
53
54 if len(certs) == 0 {
55 return nil, nil
56 }
57
58 config := &tls.Config{
59 Certificates: certs,
60 }
61 config.BuildNameToCertificate()
62 return config, nil
63 }