extractAddressList parses an RFC 5322 address-list header (To/Cc) into bare email addresses, dropping display names. Returns nil if the header is empty or unparseable; group addresses and malformed entries are silently skipped.
(header string)
| 785 | // email addresses, dropping display names. Returns nil if the header is empty |
| 786 | // or unparseable; group addresses and malformed entries are silently skipped. |
| 787 | func extractAddressList(header string) []string { |
| 788 | if header == "" { |
| 789 | return nil |
| 790 | } |
| 791 | addrs, err := mail.ParseAddressList(header) |
| 792 | if err != nil { |
| 793 | return nil |
| 794 | } |
| 795 | out := make([]string, 0, len(addrs)) |
| 796 | for _, a := range addrs { |
| 797 | if a.Address != "" { |
| 798 | out = append(out, a.Address) |
| 799 | } |
| 800 | } |
| 801 | if len(out) == 0 { |
| 802 | return nil |
| 803 | } |
| 804 | return out |
| 805 | } |
| 806 | |
| 807 | func extractDomain(addr string) string { |
| 808 | email := extractEmail(addr) |