Sha256: 4febb5dfd3519e322510e0cf4e8bf1c8f855142117e3bcb6da42e0611bf02744

Contents?: true

Size: 1.38 KB

Versions: 13

Compression:

Stored size: 1.38 KB

Contents

# encoding: utf-8
module Mail
  class AddressList # :nodoc:

    # 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 = 'ada@test.lindsaar.net, My Group: mikel@test.lindsaar.net, Bob <bob@test.lindsaar.net>;'
    #  a = AddressList.new(list)
    #  a.addresses    #=> [#<Mail::Address:14943130 Address: |ada@test.lindsaar.net...
    #  a.group_names  #=> ["My Group"]
    def initialize(string)
      @addresses_grouped_by_group = nil
      @address_list = Parsers::AddressListsParser.new.parse(string)
    end
    
    # Returns a list of address objects from the parsed line
    def addresses
      @addresses ||= @address_list.addresses.map do |address_data|
        Mail::Address.new(address_data)
      end
    end

    def addresses_grouped_by_group
      addresses.select(&:group).group_by(&:group)
    end
    
    # Returns the names as an array of strings of all groups
    def group_names # :nodoc:
      @address_list.group_names
    end
  end
end

Version data entries

13 entries across 12 versions & 6 rubygems

Version Path
mail-2.6.4.rc2 lib/mail/elements/address_list.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/mail-2.6.3/lib/mail/elements/address_list.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/mail-2.6.3/lib/mail/elements/address_list.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/mail-2.6.3/lib/mail/elements/address_list.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/mail-2.6.3/lib/mail/elements/address_list.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/mail-2.6.3/lib/mail/elements/address_list.rb
mail-2.6.4.rc1 lib/mail/elements/address_list.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/mail-2.6.3/lib/mail/elements/address_list.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/mail-2.6.3/lib/mail/elements/address_list.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/mail-2.6.3/lib/mail/elements/address_list.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/mail-2.6.3/lib/mail/elements/address_list.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/mail-2.6.3/lib/mail/elements/address_list.rb
mail-2.6.3 lib/mail/elements/address_list.rb