diff options
Diffstat (limited to 'internal/authentication/types.go')
| -rw-r--r-- | internal/authentication/types.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/internal/authentication/types.go b/internal/authentication/types.go index ee4e47ba1..5299185fc 100644 --- a/internal/authentication/types.go +++ b/internal/authentication/types.go @@ -2,6 +2,7 @@ package authentication import ( "crypto/tls" + "net/mail" "github.com/go-ldap/ldap/v3" "golang.org/x/text/encoding/unicode" @@ -36,6 +37,24 @@ type UserDetails struct { Groups []string } +// Addresses returns the Emails []string as []mail.Address formatted with DisplayName as the Name attribute. +func (d UserDetails) Addresses() (addresses []mail.Address) { + if len(d.Emails) == 0 { + return nil + } + + addresses = make([]mail.Address, len(d.Emails)) + + for i, email := range d.Emails { + addresses[i] = mail.Address{ + Name: d.DisplayName, + Address: email, + } + } + + return addresses +} + type ldapUserProfile struct { DN string Emails []string |
