# class RMail::Parser

The `RMail::Parser` class creates `RMail::Message` objects from Ruby IO objects or strings.

To parse from a string:

    message = RMail::Parser.read(the_string)

To parse from an IO object:

    message = File.open('my-message') { |f|
      RMail::Parser.read(f)
    }

You can also parse from STDIN, etc.

    message = RMail::Parser.read(STDIN)

In all cases, the parser consumes all input.

### Attributes

chunk_size[RW]

Change the chunk size used to read the message. This is useful mostly for testing.

### Public Class Methods

new() click to toggle source

Creates a new parser. Messages of `message_class` will be created by the parser. By default, the parser will create `RMail::Message` objects.

    # File lib/rmail/parser.rb, line 322
    def initialize()
      @chunk_size = nil
    end

read(input) click to toggle source

Parse a message from the IO object `io` and return a new message. The `io` object can also be a string. This is just shorthand for:

    RMail::Parser.new.parse(io)

    # File lib/rmail/parser.rb, line 345
    def Parser.read(input)
      Parser.new.parse(input)
    end

### Public Instance Methods

parse(input) click to toggle source

Parse a message from the IO object `io` and return a new message. The `io` object can also be a string.

    # File lib/rmail/parser.rb, line 328
    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.message
    end