# class RMail::Address::Parser

This class provides a facility to parse a string containing one or more RFC2822 addresses into an array of `RMail::Address` objects. You can use it directly, but it is more conveniently used with the `RMail::Address.parse` method.

### Constants

SYM_ATOM
SYM_ATOM_NON_ASCII
SYM_AT_SIGN
SYM_COLON
SYM_COMMA
SYM_DOMAIN_LITERAL
SYM_GREATER_THAN
SYM_LESS_THAN
SYM_PERIOD
SYM_QTEXT
SYM_SEMI_COLON

### Public Class Methods

new(string) click to toggle source

Create a `RMail::Address::Parser` object that will parse `string`. See also the `RMail::Address.parse` method.

    # File lib/rmail/address.rb, line 279
    def initialize(string)
      @string = string
    end

### Public Instance Methods

parse() click to toggle source

This function attempts to extract mailing addresses from the string passed to new. The function returns an `RMail::Address::List` of `RMail::Address` objects (`RMail::Address::List` is a subclass of Array). A malformed input string will not generate an exception. Instead, the array returned will simply not contained the malformed addresses.

The string is expected to be in a valid format as documented in RFC2822's mailbox-list grammar. This will work for lists of addresses in the `To:`, `From:`, etc. headers in email.

    # File lib/rmail/address.rb, line 295
    def parse
      @lexemes = []
      @tokens = []
      @addresses = RMail::Address::List.new
      @errors = 0
      new_address
      get
      address_list
      reset_errors
      @addresses.delete_if { |a|
        !a.local || !a.domain
      }
    end