mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 17:44:35 +03:00
in smtpserver, accept delivery to postmaster@<hostname>, and also postmaster@ addresses for domains that don't have a postmaster address configured.
This commit is contained in:
@ -270,7 +270,7 @@ func MakeDomainConfig(ctx context.Context, domain, hostname dns.Domain, accountN
|
||||
// DomainAdd adds the domain to the domains config, rewriting domains.conf and
|
||||
// marking it loaded.
|
||||
//
|
||||
// accountName is used for DMARC/TLS report.
|
||||
// accountName is used for DMARC/TLS report and potentially for the postmaster address.
|
||||
// If the account does not exist, it is created with localpart. Localpart must be
|
||||
// set only if the account does not yet exist.
|
||||
func DomainAdd(ctx context.Context, domain dns.Domain, accountName string, localpart smtp.Localpart) (rerr error) {
|
||||
@ -325,6 +325,16 @@ func DomainAdd(ctx context.Context, domain dns.Domain, accountName string, local
|
||||
return fmt.Errorf("account name is empty")
|
||||
} else if !ok {
|
||||
nc.Accounts[accountName] = MakeAccountConfig(smtp.Address{Localpart: localpart, Domain: domain})
|
||||
} else if accountName != Conf.Static.Postmaster.Account {
|
||||
nacc := nc.Accounts[accountName]
|
||||
nd := map[string]config.Destination{}
|
||||
for k, v := range nacc.Destinations {
|
||||
nd[k] = v
|
||||
}
|
||||
pmaddr := smtp.Address{Localpart: "postmaster", Domain: domain}
|
||||
nd[pmaddr.String()] = config.Destination{}
|
||||
nacc.Destinations = nd
|
||||
nc.Accounts[accountName] = nacc
|
||||
}
|
||||
|
||||
nc.Domains[domain.Name()] = confDomain
|
||||
|
@ -22,8 +22,21 @@ func FindAccount(localpart smtp.Localpart, domain dns.Domain, allowPostmaster bo
|
||||
if strings.EqualFold(string(localpart), "postmaster") {
|
||||
localpart = "postmaster"
|
||||
}
|
||||
var zerodomain dns.Domain
|
||||
if localpart == "postmaster" && domain == zerodomain {
|
||||
|
||||
postmasterDomain := func() bool {
|
||||
var zerodomain dns.Domain
|
||||
if domain == zerodomain || domain == Conf.Static.HostnameDomain {
|
||||
return true
|
||||
}
|
||||
for _, l := range Conf.Static.Listeners {
|
||||
if l.SMTP.Enabled && domain == l.HostnameDomain {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
if localpart == "postmaster" && postmasterDomain() {
|
||||
if !allowPostmaster {
|
||||
return "", "", config.Destination{}, ErrAccountNotFound
|
||||
}
|
||||
@ -44,6 +57,9 @@ func FindAccount(localpart smtp.Localpart, domain dns.Domain, allowPostmaster bo
|
||||
accAddr, ok := Conf.AccountDestination(canonical)
|
||||
if !ok {
|
||||
if accAddr, ok = Conf.AccountDestination("@" + domain.Name()); !ok {
|
||||
if localpart == "postmaster" && allowPostmaster {
|
||||
return Conf.Static.Postmaster.Account, "postmaster", config.Destination{Mailbox: Conf.Static.Postmaster.Mailbox}, nil
|
||||
}
|
||||
return "", "", config.Destination{}, ErrAccountNotFound
|
||||
}
|
||||
canonical = "@" + domain.Name()
|
||||
|
Reference in New Issue
Block a user