2024-02-20 23:51:48 +00:00
|
|
|
package simplemail
|
|
|
|
|
|
|
|
import (
|
2024-09-21 16:08:07 +01:00
|
|
|
"encoding"
|
2024-02-20 23:51:48 +00:00
|
|
|
"encoding/json"
|
2024-09-21 16:08:07 +01:00
|
|
|
"github.com/emersion/go-message/mail"
|
2024-02-20 23:51:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type FromAddress struct {
|
|
|
|
*mail.Address
|
|
|
|
}
|
|
|
|
|
2024-09-21 16:08:07 +01:00
|
|
|
var _ encoding.TextUnmarshaler = &FromAddress{}
|
2024-02-20 23:51:48 +00:00
|
|
|
|
2024-09-21 16:08:07 +01: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
|
|
|
|
}
|