Skip to content

Commit

Permalink
support for using an Address in Content.From (ignores Address.HeaderTo)
Browse files Browse the repository at this point in the history
  • Loading branch information
yargevad committed Jul 27, 2016
1 parent 6d52512 commit 9ccb304
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func ParseFrom(from interface{}) (f From, err error) {
case From:
f = fromVal

case Address:
f.Email = fromVal.Email
f.Name = fromVal.Name

case string: // simple string value
if fromVal == "" {
err = fmt.Errorf("Content.From may not be empty")
Expand Down
17 changes: 17 additions & 0 deletions templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ func TestTemplateValidation(t *testing.T) {
return
}

addrStruct := sp.Address{"a@b.com", "A B", "c@d.com"}
f, err = sp.ParseFrom(addrStruct)
if err != nil {
t.Error(err)
return
}
if addrStruct.Email != f.Email {
t.Error(fmt.Errorf("expected email [%s] didn't match actual [%s]",
addrStruct.Email, f.Email))
return
}
if addrStruct.Name != f.Name {
t.Error(fmt.Errorf("expected name [%s] didn't match actual [%s]",
addrStruct.Name, f.Name))
return
}

fromString := "a@b.com"
f, err = sp.ParseFrom(fromString)
if err != nil {
Expand Down

0 comments on commit 9ccb304

Please sign in to comment.