Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trim addresses #19

Merged
merged 5 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
15 changes: 15 additions & 0 deletions internal/email/smtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down