lib/parse: simplify parseAddressList
This commit is contained in:
parent
c06a2e61fc
commit
fda424bebc
1 changed files with 5 additions and 13 deletions
|
@ -198,23 +198,15 @@ func parseReceivedHeader(h *mail.Header) (time.Time, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseAddressList(h *mail.Header, key string) ([]*mail.Address, error) {
|
func parseAddressList(h *mail.Header, key string) ([]*mail.Address, error) {
|
||||||
var converted []*mail.Address
|
|
||||||
addrs, err := h.AddressList(key)
|
addrs, err := h.AddressList(key)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
if hdr, err := h.Text(key); err == nil {
|
return addrs, nil
|
||||||
return []*mail.Address{&mail.Address{
|
|
||||||
Name: hdr,
|
|
||||||
}}, nil
|
|
||||||
}
|
}
|
||||||
|
hdr, err := h.Text(key)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, addr := range addrs {
|
return []*mail.Address{{Name: hdr}}, nil
|
||||||
converted = append(converted, &mail.Address{
|
|
||||||
Name: addr.Name,
|
|
||||||
Address: addr.Address,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return converted, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RawMessage is an interface that describes a raw message
|
// RawMessage is an interface that describes a raw message
|
||||||
|
|
Loading…
Reference in a new issue