Class: RMail::Parser
- Inherits:
-
Object
- Object
- RMail::Parser
- Defined in:
- lib/rmail/parser.rb,
lib/rmail/parser/multipart.rb,
lib/rmail/parser/pushbackreader.rb
Overview
The RMail::Parser class creates RMail::Message objects from Ruby IO objects or strings.
To parse from a string:
= RMail::Parser.read(the_string)
To parse from an IO object:
= File.open('my-message') { |f|
RMail::Parser.read(f)
}
You can also parse from STDIN, etc.
= RMail::Parser.read(STDIN)
In all cases, the parser consumes all input.
Defined Under Namespace
Classes: Error, Handler, MultipartReader, PushbackReader
Instance Attribute Summary collapse
-
#chunk_size ⇒ Object
Change the chunk size used to read the message.
Class Method Summary collapse
-
.read(input) ⇒ Object
Parse a message from the IO object
io
and return a new message.
Instance Method Summary collapse
-
#initialize ⇒ Parser
constructor
Creates a new parser.
-
#parse(input) ⇒ Object
Parse a message from the IO object
io
and return a new message.
Constructor Details
#initialize ⇒ Parser
Creates a new parser. Messages of message_class
will be created by the parser. By default, the parser will create RMail::Message objects.
321 322 323 |
# File 'lib/rmail/parser.rb', line 321 def initialize() @chunk_size = nil end |
Instance Attribute Details
#chunk_size ⇒ Object
Change the chunk size used to read the message. This is useful mostly for testing.
337 338 339 |
# File 'lib/rmail/parser.rb', line 337 def chunk_size @chunk_size end |
Class Method Details
Instance Method Details
#parse(input) ⇒ Object
Parse a message from the IO object io
and return a new message. The io
object can also be a string.
327 328 329 330 331 332 333 |
# File 'lib/rmail/parser.rb', line 327 def parse(input) handler = RMail::Parser::Handler.new parser = RMail::StreamParser.new(input, handler) parser.chunk_size = @chunk_size if @chunk_size parser.parse return handler. end |