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:
Mechiel Lukkien
2023-04-24 12:04:46 +02:00
parent 74dab5fc39
commit c1753b369d
8 changed files with 85 additions and 5 deletions

View File

@ -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()