From 6b814a2d2a0a64ba398765d271ccec514832b180 Mon Sep 17 00:00:00 2001 From: ddvk Date: Mon, 9 Nov 2020 10:06:37 +0100 Subject: [PATCH 1/5] kick the ci with 1.13 --- internal/email/smtp_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/email/smtp_test.go b/internal/email/smtp_test.go index 64423f81..609ea71a 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 := ", email@domain.com , " + to, err := mail.ParseAddressList(addreses) + if err != nil { + t.Error(err) + } + if len(to) > 1 { + 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", From d0cffe1869e3f9732a1bd917eb53980a81d47ce4 Mon Sep 17 00:00:00 2001 From: ddvk Date: Mon, 9 Nov 2020 10:16:40 +0100 Subject: [PATCH 2/5] force 1.13 --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index e79e45a1..ff9060c8 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.13 id: go - name: Check out code into the Go module directory From e87d3b55abee3db0de9c6a4b74c0ad1ee955fd63 Mon Sep 17 00:00:00 2001 From: ddvk Date: Mon, 9 Nov 2020 10:18:27 +0100 Subject: [PATCH 3/5] trim addresses --- internal/email/smtp.go | 7 ++++++- internal/email/smtp_test.go | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/email/smtp.go b/internal/email/smtp.go index 33f6578d..f25881ee 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 609ea71a..35b2a5d2 100644 --- a/internal/email/smtp_test.go +++ b/internal/email/smtp_test.go @@ -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) From 3b13d2bdb3a1c15333bba3296e86b2f7c42c1e5d Mon Sep 17 00:00:00 2001 From: ddvk Date: Mon, 9 Nov 2020 10:25:15 +0100 Subject: [PATCH 4/5] fix trim order --- internal/email/smtp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/email/smtp.go b/internal/email/smtp.go index f25881ee..c715f224 100644 --- a/internal/email/smtp.go +++ b/internal/email/smtp.go @@ -49,7 +49,7 @@ func Strip(msg string) string { // workaround for go < 1.15 func TrimAddresses(address string) string { - return strings.Trim(strings.Trim(address, ","), " ") + return strings.Trim(strings.Trim(address, " "), ",") } func (b *EmailBuilder) AddFile(name string, data []byte) { From ef6127264ff292ab161e04f18e7ec69b0cb33509 Mon Sep 17 00:00:00 2001 From: ddvk Date: Mon, 9 Nov 2020 10:40:25 +0100 Subject: [PATCH 5/5] ci, set min go version to 1.15 --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ff9060c8..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