Bump the version to 2.1.0.
[mailpopbox.git] / config.go
index c50104bf628b0cd9d896897acd88577b815f8226..961d2cb8f36ca36d15d32c2c8eec61428437c7f5 100644 (file)
--- a/config.go
+++ b/config.go
@@ -1,5 +1,15 @@
+// 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
@@ -10,6 +20,8 @@ type Config struct {
        Servers []Server
 }
 
+const MailboxAccount = "mailbox@"
+
 type Server struct {
        // Domain is the second component of a mail address: <local-part@domain.com>.
        Domain string
@@ -20,6 +32,35 @@ type Server struct {
        // Password for the POP3 mailbox user, mailbox@domain.com.
        MailboxPassword string
 
-       // Blacklisted addresses that should not accept mail.
-       BlacklistedAddresses []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
 }