Class: Mail::AddressList

Inherits:
Object
  • Object
show all
Defined in:
lib/mail/elements/address_list.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

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"]


24
25
26
27
28
# File 'lib/mail/elements/address_list.rb', line 24

def initialize(string)
  address_list = Parsers::AddressListsParser.parse(string)
  @addresses = address_list.addresses.map { |a| Address.new(a) }
  @group_names = address_list.group_names
end

Instance Attribute Details

#addressesObject (readonly)

Returns the value of attribute addresses.



7
8
9
# File 'lib/mail/elements/address_list.rb', line 7

def addresses
  @addresses
end

#group_namesObject (readonly)

Returns the value of attribute group_names.



7
8
9
# File 'lib/mail/elements/address_list.rb', line 7

def group_names
  @group_names
end

Instance Method Details

#addresses_grouped_by_groupObject



30
31
32
# File 'lib/mail/elements/address_list.rb', line 30

def addresses_grouped_by_group
  addresses.select(&:group).group_by(&:group)
end