Class: RMail::Address::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/rmail/address.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Parser

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



279
280
281
# File 'lib/rmail/address.rb', line 279

def initialize(string)
  @string = string
end

Instance Method Details

#parseObject

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.



295
296
297
298
299
300
301
302
303
304
305
306
307
# 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