simplemail/fromaddress.go

28 lines
430 B
Go
Raw Permalink Normal View History

2024-02-20 23:51:48 +00:00
package simplemail
import (
"encoding"
2024-02-20 23:51:48 +00:00
"encoding/json"
"github.com/emersion/go-message/mail"
2024-02-20 23:51:48 +00:00
)
type FromAddress struct {
*mail.Address
}
var _ encoding.TextUnmarshaler = &FromAddress{}
2024-02-20 23:51:48 +00:00
func (f *FromAddress) UnmarshalText(b []byte) error {
2024-02-20 23:51:48 +00:00
var a string
err := json.Unmarshal(b, &a)
if err != nil {
return err
}
address, err := mail.ParseAddress(a)
if err != nil {
return err
}
f.Address = address
return nil
}