1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2026-01-04 17:27:02 +00:00

aliases: Exists does not need to return the "clean" address

The aliases.Resolver.Exists function currently returns the "clean"
address (with the drop characters and suffixes removed), which is relied
upon in its only caller.

That, however, makes the logic more difficult to follow, hiding some
of the address manipulation behind what should be a read-only check.

So this patch reorganizes that code a little bit, removing the
"cleaning" of the address as part of Exists, and making it explicit when
needed instead.

This patch does not have any user-visible change in behaviour, it is
just internal reorganization.

This is in preparation for further patches which will improve the
handling of some aliases corner cases.
This commit is contained in:
Alberto Bertogli
2023-09-23 10:32:32 +01:00
parent dc10031e1c
commit 8bbb6118e5
3 changed files with 63 additions and 60 deletions

View File

@@ -591,7 +591,7 @@ func (c *Conn) RCPT(params string) (code int, msg string) {
return 550, "5.1.3 Destination address is invalid"
}
ok, err := c.userExists(addr)
ok, err := c.localUserExists(addr)
if err != nil {
c.tr.Errorf("error checking if user %q exists: %v", addr, err)
maillog.Rejected(c.remoteAddr, c.mailFrom, []string{addr},
@@ -1096,17 +1096,14 @@ func (c *Conn) resetEnvelope() {
c.spfError = nil
}
func (c *Conn) userExists(addr string) (bool, error) {
var ok bool
addr, ok = c.aliasesR.Exists(c.tr, addr)
if ok {
func (c *Conn) localUserExists(addr string) (bool, error) {
if c.aliasesR.Exists(c.tr, addr) {
return true, nil
}
// Note we used the address returned by the aliases resolver, which has
// cleaned it up. This means that a check for "us.er@domain" will have us
// look up "user" in our databases if the domain is local, which is what
// we want.
// Remove the drop chars and suffixes, if any, so the database lookup is
// on a "clean" address.
addr = c.aliasesR.RemoveDropsAndSuffix(addr)
user, domain := envelope.Split(addr)
return c.authr.Exists(c.tr, user, domain)
}