peroxide: Make the server address configurable

Issue #6
create-reload-action
Lukasz Janyst 4 years ago
parent 69befee6d3
commit feee18b1f6
No known key found for this signature in database
GPG Key ID: 32DE641041F17A9A
  1. 7
      pkg/bridge/bridge.go
  2. 2
      pkg/config/settings/settings.go
  3. 5
      pkg/imap/server.go
  4. 9
      pkg/smtp/server.go

@ -132,13 +132,15 @@ func (b *Bridge) Run() error {
imapBackend := imap.NewIMAPBackend(b.listener, b.settings, b.Users)
smtpBackend := smtp.NewSMTPBackend(b.listener, b.Users)
serverAddress := b.settings.Get(settings.ServerAddress)
go func() {
imapPort := b.settings.GetInt(settings.IMAPPortKey)
imap.NewIMAPServer(
false, // log client
false, // log server
imapPort, tlsConfig, imapBackend, b.listener).ListenAndServe()
serverAddress, imapPort, tlsConfig,
imapBackend, b.listener).ListenAndServe()
}()
go func() {
@ -146,7 +148,8 @@ func (b *Bridge) Run() error {
useSSL := false
smtp.NewSMTPServer(
false,
smtpPort, useSSL, tlsConfig, smtpBackend, b.listener).ListenAndServe()
serverAddress, smtpPort, useSSL, tlsConfig,
smtpBackend, b.listener).ListenAndServe()
}()
done := make(chan os.Signal, 1)

@ -41,6 +41,7 @@ const (
X509Key = "X509Key"
X509Cert = "X509Cert"
CookieJar = "CookieJar"
ServerAddress = "ServerAddress"
)
type Settings struct {
@ -85,4 +86,5 @@ func (s *Settings) setDefaultValues() {
s.setDefault(X509Key, filepath.Join(s.settingsDir, "key.pem"))
s.setDefault(X509Cert, filepath.Join(s.settingsDir, "cert.pem"))
s.setDefault(CookieJar, filepath.Join(s.settingsDir, "cookies.json"))
s.setDefault(ServerAddress, "127.0.0.1")
}

@ -43,6 +43,7 @@ import (
type Server struct {
debugClient bool
debugServer bool
address string
port int
server *imapserver.Server
@ -52,6 +53,7 @@ type Server struct {
// NewIMAPServer constructs a new IMAP server configured with the given options.
func NewIMAPServer(
debugClient, debugServer bool,
address string,
port int,
tls *tls.Config,
imapBackend backend.Backend,
@ -60,6 +62,7 @@ func NewIMAPServer(
server := &Server{
debugClient: debugClient,
debugServer: debugServer,
address: address,
port: port,
}
@ -112,7 +115,7 @@ func (s *Server) Close() { s.controller.Close() }
func (Server) Protocol() serverutil.Protocol { return serverutil.IMAP }
func (s *Server) UseSSL() bool { return false }
func (s *Server) Address() string { return fmt.Sprintf("%s:%d", "127.0.0.1", s.port) }
func (s *Server) Address() string { return fmt.Sprintf("%s:%d", s.address, s.port) }
func (s *Server) TLSConfig() *tls.Config { return s.server.TLSConfig }
func (s *Server) DebugServer() bool { return s.debugServer }

@ -34,6 +34,7 @@ type Server struct {
backend goSMTP.Backend
debug bool
useSSL bool
address string
port int
tls *tls.Config
@ -43,7 +44,10 @@ type Server struct {
// NewSMTPServer returns an SMTP server configured with the given options.
func NewSMTPServer(
debug bool, port int, useSSL bool,
debug bool,
address string,
port int,
useSSL bool,
tls *tls.Config,
smtpBackend goSMTP.Backend,
eventListener listener.Listener,
@ -52,6 +56,7 @@ func NewSMTPServer(
backend: smtpBackend,
debug: debug,
useSSL: useSSL,
address: address,
port: port,
tls: tls,
}
@ -94,7 +99,7 @@ func (s *Server) Close() { s.controller.Close() }
func (Server) Protocol() serverutil.Protocol { return serverutil.SMTP }
func (s *Server) UseSSL() bool { return s.useSSL }
func (s *Server) Address() string { return fmt.Sprintf("%s:%d", "127.0.0.1", s.port) }
func (s *Server) Address() string { return fmt.Sprintf("%s:%d", s.address, s.port) }
func (s *Server) TLSConfig() *tls.Config { return s.tls }
func (s *Server) DebugServer() bool { return s.debug }

Loading…
Cancel
Save