Class RMail::Address::Parser
In: lib/rmail/address.rb
Parent: Object

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.

Methods

new   parse  

Constants

SYM_ATOM = :atom
SYM_ATOM_NON_ASCII = :atom_non_ascii
SYM_QTEXT = :qtext
SYM_COMMA = :comma
SYM_LESS_THAN = :less_than
SYM_GREATER_THAN = :greater_than
SYM_AT_SIGN = :at_sign
SYM_PERIOD = :period
SYM_COLON = :colon
SYM_SEMI_COLON = :semi_colon
SYM_DOMAIN_LITERAL = :domain_literal

Public Class methods

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

[Source]

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

Public Instance methods

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.

[Source]

# File lib/rmail/address.rb, line 296
      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

[Validate]