diff --git a/internal/authz/lookup.go b/internal/authz/lookup.go index 5549b3a..f19c3f8 100644 --- a/internal/authz/lookup.go +++ b/internal/authz/lookup.go @@ -9,28 +9,30 @@ import ( ) func AuthorizeEmailUse(ctx context.Context, username string, addrs []string, mapping module.Table) (bool, error) { + var validEmails []string + + if multi, ok := mapping.(module.MultiTable); ok { + var err error + validEmails, err = multi.LookupMulti(ctx, username) + if err != nil { + return false, fmt.Errorf("authz: %w", err) + } + } else { + validEmail, ok, err := mapping.Lookup(ctx, username) + if err != nil { + return false, fmt.Errorf("authz: %w", err) + } + if ok { + validEmails = []string{validEmail} + } + } + for _, addr := range addrs { _, domain, err := address.Split(addr) if err != nil { return false, fmt.Errorf("authz: %w", err) } - var validEmails []string - if multi, ok := mapping.(module.MultiTable); ok { - validEmails, err = multi.LookupMulti(ctx, username) - if err != nil { - return false, fmt.Errorf("authz: %w", err) - } - } else { - validEmail, ok, err := mapping.Lookup(ctx, username) - if err != nil { - return false, fmt.Errorf("authz: %w", err) - } - if ok { - validEmails = []string{validEmail} - } - } - for _, ent := range validEmails { if ent == domain || ent == "*" || ent == addr { return true, nil