diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index e79e45a1..84b0037f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v2 with: - go-version: ^1.13 + go-version: ^1.15 id: go - name: Check out code into the Go module directory diff --git a/internal/email/smtp.go b/internal/email/smtp.go index 33f6578d..c715f224 100644 --- a/internal/email/smtp.go +++ b/internal/email/smtp.go @@ -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} @@ -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 } diff --git a/internal/email/smtp_test.go b/internal/email/smtp_test.go index 64423f81..35b2a5d2 100644 --- a/internal/email/smtp_test.go +++ b/internal/email/smtp_test.go @@ -2,10 +2,25 @@ package email import ( "io/ioutil" + "net/mail" "testing" ) +func TestParseEmptyAddress(t *testing.T) { + addreses := TrimAddresses(", email@domain.com , blah@blah, ") + to, err := mail.ParseAddressList(addreses) + if err != nil { + t.Error(err) + } + if len(to) > 2 { + t.Error("more than 2") + } + t.Log(to) +} + func TestRead(t *testing.T) { + t.Skip("TODO: fake the sending") + file, _ := ioutil.ReadFile("test.txt") sender := EmailBuilder{ To: "bingobango@mailinator.com",