Skip to content

Commit

Permalink
feat: do recursive forward resolves (in case one address is forwardin…
Browse files Browse the repository at this point in the history
…g to another address that is forwarding to an external address)
  • Loading branch information
d--j committed Apr 17, 2023
1 parent 53ded4f commit b90899f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func emailWithoutExtension(local string, asciiDomain string) string {
}

func (c *Configuration) ResolveForward(email *addr.RcptTo) (emails []*addr.RcptTo) {
return c.resolveForward(email, make(map[string]bool))
}

func (c *Configuration) resolveForward(email *addr.RcptTo, seen map[string]bool) (emails []*addr.RcptTo) {
if c.db == nil {
return []*addr.RcptTo{email}
}
Expand All @@ -102,7 +106,12 @@ func (c *Configuration) ResolveForward(email *addr.RcptTo) (emails []*addr.RcptT
return []*addr.RcptTo{email}
}
for _, a := range addresses {
emails = append(emails, addr.NewRcptTo(a.Address, "", email.Transport()))
if !seen[a.Address] {
seen[a.Address] = true
for _, r := range c.resolveForward(addr.NewRcptTo(a.Address, "", email.Transport()), seen) {
emails = append(emails, r)
}
}
}
}
if len(emails) > 0 {
Expand Down

0 comments on commit b90899f

Please sign in to comment.