deprecate having only localparts in an Account's Destinations, it should always be a full email address

current behaviour isn't intuitive. it's not great to have to attempt parsing
the strings as both localpart and email address. so we deprecate the
localpart-only behaviour. when we load the config file, and it has
localpart-only Destinations keys, we'll change them to full addresses in
memory. when an admin causes a write of domains.conf, it'll automatically be
fixed. we log an error with a deprecated notice for each localpart-only
destinations key.

sometime in the future, we can remove the old localpart-only destination
support. will be in the release notes then.

also start keeping track of update notes that need to make it in the release
notes of the next release.

for issue #18
This commit is contained in:
Mechiel Lukkien
2023-03-09 22:07:37 +01:00
parent 5742ed1537
commit 2c07645ab4
20 changed files with 57 additions and 41 deletions

View File

@ -847,6 +847,9 @@ func prepareDynamicConfig(ctx context.Context, dynamicPath string, static config
}
c.Accounts[accName] = acc
// todo deprecated: only localpart as keys for Destinations, we are replacing them with full addresses. if domains.conf is written, we won't have to do this again.
replaceLocalparts := map[string]string{}
for addrName, dest := range acc.Destinations {
checkMailboxNormf(dest.Mailbox, "account %q, destination %q", accName, addrName)
@ -906,6 +909,7 @@ func prepareDynamicConfig(ctx context.Context, dynamicPath string, static config
}
}
// todo deprecated: remove support for parsing destination as just a localpart instead full address.
var address smtp.Address
localpart, err := smtp.ParseLocalpart(addrName)
if err != nil && errors.Is(err, smtp.ErrBadLocalpart) {
@ -927,6 +931,7 @@ func prepareDynamicConfig(ctx context.Context, dynamicPath string, static config
addErrorf("unknown domain %s for account %q", acc.DNSDomain.Name(), accName)
continue
}
replaceLocalparts[addrName] = address.Pack(true)
}
addrFull := address.Pack(true)
if _, ok := accDests[addrFull]; ok {
@ -934,6 +939,17 @@ func prepareDynamicConfig(ctx context.Context, dynamicPath string, static config
}
accDests[addrFull] = AccountDestination{address.Localpart, accName, dest}
}
for lp, addr := range replaceLocalparts {
dest, ok := acc.Destinations[lp]
if !ok {
addErrorf("could not find localpart %q to replace with address in destinations", lp)
} else {
log.Error("deprecated: destination with localpart-only key will be removed in the future, replace it with a full email address, by appending the default domain", mlog.Field("localpart", lp), mlog.Field("address", addr), mlog.Field("account", accName))
acc.Destinations[addr] = dest
delete(acc.Destinations, lp)
}
}
}
// Set DMARC destinations.