Class: RMail::StreamParser

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

Overview

The RMail::StreamParser is a low level message parsing API. It is useful when you are interested in serially examining all message content but are not interested in a full object representation of the object. See StreamParser.parse.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, handler) ⇒ StreamParser

:nodoc:


174
175
176
177
178
# File 'lib/rmail/parser.rb', line 174

def initialize(input, handler) # :nodoc:
  @input = input
  @handler = handler
  @chunk_size = nil
end

Instance Attribute Details

#chunk_sizeObject

Change the chunk size used to read the message. This is useful mostly for testing, so we don't document it.


189
190
191
# File 'lib/rmail/parser.rb', line 189

def chunk_size
  @chunk_size
end

Class Method Details

.parse(input, handler) ⇒ Object

Parse a message from an input source. This method returns nothing. Instead, the supplied handler is expected to implement the same methods as RMail::StreamHandler. The message structure can be inferred from the methods called on the handler. The input can be any Ruby IO source or a String.

This is a low level parsing API. For a message parser that returns an RMail::Message object, see the RMail::Parser class. RMail::Parser is implemented using RMail::StreamParser.


169
170
171
# File 'lib/rmail/parser.rb', line 169

def parse(input, handler)
  RMail::StreamParser.new(input, handler).parse
end

Instance Method Details

#parseObject

:nodoc:


180
181
182
183
184
185
# File 'lib/rmail/parser.rb', line 180

def parse                   # :nodoc:
  input = RMail::Parser::PushbackReader.new(@input)
  input.chunk_size = @chunk_size if @chunk_size
  parse_low(input, 0)
  return nil
end