Skip to content

Commit

Permalink
trim addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
ddvk committed Nov 9, 2020
1 parent d0cffe1 commit e87d3b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion internal/email/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func Strip(msg string) string {
return msg
}

// workaround for go < 1.15
func TrimAddresses(address string) string {
return strings.Trim(strings.Trim(address, ","), " ")
}

func (b *EmailBuilder) AddFile(name string, data []byte) {
if b.fileNames == nil || b.files == nil {
b.fileNames = []string{name}
Expand All @@ -71,7 +76,7 @@ func (b *EmailBuilder) Send() (err error) {
if err != nil {
return err
}
to, err := mail.ParseAddressList(b.To)
to, err := mail.ParseAddressList(TrimAddresses(b.To))
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/email/smtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
)

func TestParseEmptyAddress(t *testing.T) {
addreses := ", email@domain.com , "
addreses := TrimAddresses(", email@domain.com , blah@blah, ")
to, err := mail.ParseAddressList(addreses)
if err != nil {
t.Error(err)
}
if len(to) > 1 {
if len(to) > 2 {
t.Error("more than 2")
}
t.Log(to)
Expand Down

0 comments on commit e87d3b5

Please sign in to comment.