mirror of
https://github.com/1f349/simplemail.git
synced 2025-01-20 22:26:33 +00:00
29 lines
504 B
Go
29 lines
504 B
Go
package simplemail
|
|
|
|
import (
|
|
"encoding"
|
|
"github.com/emersion/go-message/mail"
|
|
)
|
|
|
|
type FromAddress mail.Address
|
|
|
|
var _ encoding.TextUnmarshaler = &FromAddress{}
|
|
|
|
func (f FromAddress) String() string {
|
|
return f.toMailAddress().String()
|
|
}
|
|
|
|
func (f *FromAddress) UnmarshalText(b []byte) error {
|
|
address, err := mail.ParseAddress(string(b))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*f = FromAddress(*address)
|
|
return nil
|
|
}
|
|
|
|
func (f FromAddress) toMailAddress() *mail.Address {
|
|
m := mail.Address(f)
|
|
return &m
|
|
}
|