initial, rought, not-user-friendly support for multi-domain setup
This commit is contained in:
10
smtp/msa.go
10
smtp/msa.go
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user