mirror of
https://github.com/1f349/tulip.git
synced 2024-12-23 00:34:07 +00:00
27 lines
404 B
Go
27 lines
404 B
Go
|
package mail
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"github.com/emersion/go-message/mail"
|
||
|
)
|
||
|
|
||
|
type FromAddress struct {
|
||
|
*mail.Address
|
||
|
}
|
||
|
|
||
|
var _ json.Unmarshaler = &FromAddress{}
|
||
|
|
||
|
func (f *FromAddress) UnmarshalJSON(b []byte) error {
|
||
|
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
|
||
|
}
|