initial, rought, not-user-friendly support for multi-domain setup

This commit is contained in:
Aine
2022-11-08 18:16:38 +02:00
parent 8954a7801a
commit 15d5afe90f
14 changed files with 70 additions and 45 deletions

View File

@@ -13,10 +13,10 @@ import (
// msa is mail submission agent, implements smtp.Backend
type msa struct {
log *logger.Logger
domain string
bot Bot
mta utils.MTA
log *logger.Logger
domains []string
bot Bot
mta utils.MTA
}
func (m *msa) newSession(from string, incoming bool) *msasession {
@@ -27,7 +27,7 @@ func (m *msa) newSession(from string, incoming bool) *msasession {
incoming: incoming,
log: m.log,
bot: m.bot,
domain: m.domain,
domains: m.domains,
}
}

View File

@@ -19,10 +19,10 @@ import (
// - receiving emails from remote servers, in which case: `incoming = true`
// - sending emails from local users, in which case: `incoming = false`
type msasession struct {
log *logger.Logger
bot Bot
mta utils.MTA
domain string
log *logger.Logger
bot Bot
mta utils.MTA
domains []string
ctx context.Context
incoming bool
@@ -46,8 +46,16 @@ func (s *msasession) Rcpt(to string) error {
sentry.GetHubFromContext(s.ctx).Scope().SetTag("to", to)
s.to = to
//nolint:nestif // TODO
if s.incoming {
if utils.Hostname(to) != s.domain {
var domainok bool
for _, domain := range s.domains {
if utils.Hostname(to) == domain {
domainok = true
break
}
}
if !domainok {
s.log.Debug("wrong domain of %s", to)
return smtp.ErrAuthRequired
}

View File

@@ -11,8 +11,8 @@ import (
)
type Config struct {
Domain string
Port string
Domains []string
Port string
TLSCert string
TLSKey string
@@ -39,15 +39,15 @@ func NewServer(cfg *Config) *Server {
log := logger.New("smtp/msa.", cfg.LogLevel)
sender := NewMTA(cfg.LogLevel)
receiver := &msa{
log: log,
mta: sender,
bot: cfg.Bot,
domain: cfg.Domain,
log: log,
mta: sender,
bot: cfg.Bot,
domains: cfg.Domains,
}
receiver.bot.SetMTA(sender)
s := smtp.NewServer(receiver)
s.Domain = cfg.Domain
s.Domain = cfg.Domains[0]
s.ReadTimeout = 10 * time.Second
s.WriteTimeout = 10 * time.Second
s.MaxMessageBytes = cfg.MaxSize * 1024 * 1024