Class: Mail::AddressList
Overview
:nodoc:
Instance Method Summary collapse
-
#addresses ⇒ Object
Returns a list of address objects from the parsed line.
- #addresses_grouped_by_group ⇒ Object
-
#group_names ⇒ Object
Returns the names as an array of strings of all groups.
-
#initialize(string) ⇒ AddressList
constructor
Mail::AddressList is the class that parses To, From and other address fields from emails passed into Mail.
Constructor Details
#initialize(string) ⇒ AddressList
Mail::AddressList is the class that parses To, From and other address fields from emails passed into Mail.
AddressList provides a way to query the groups and mailbox lists of the passed in string.
It can supply all addresses in an array, or return each address as an address object.
Mail::AddressList requires a correctly formatted group or mailbox list per RFC2822 or RFC822. It also handles all obsolete versions in those RFCs.
list = '[email protected], My Group: [email protected], Bob <[email protected]>;'
a = AddressList.new(list)
a.addresses #=> [#<Mail::Address:14943130 Address: |[email protected]...
a.group_names #=> ["My Group"]
20 21 22 23 |
# File 'lib/mail/elements/address_list.rb', line 20 def initialize(string) @addresses_grouped_by_group = nil @address_list = Parsers::AddressListsParser.new.parse(string) end |
Instance Method Details
#addresses ⇒ Object
Returns a list of address objects from the parsed line
26 27 28 29 30 |
# File 'lib/mail/elements/address_list.rb', line 26 def addresses @addresses ||= @address_list.addresses.map do |address_data| Mail::Address.new(address_data) end end |
#addresses_grouped_by_group ⇒ Object
32 33 34 |
# File 'lib/mail/elements/address_list.rb', line 32 def addresses_grouped_by_group addresses.select(&:group).group_by(&:group) end |
#group_names ⇒ Object
Returns the names as an array of strings of all groups
37 38 39 |
# File 'lib/mail/elements/address_list.rb', line 37 def group_names # :nodoc: @address_list.group_names end |