"DTD/xhtml1-strict.dtd">
Class RMail::Mailbox::MBoxReader
In: lib/rmail/mailbox/mboxreader.rb
Parent: RMail::Parser::PushbackReader

Class that can parse Unix mbox style mailboxes. These mailboxes separate individual messages with a line beginning with the string "From ".

Typical usage:

 File.open("file.mbox") { |file|
   RMail::Mailbox::MBoxReader.new(file).each_message { |input|
     message = RMail::Parser.read(input)
     # do something with the message
   end
 }

Or see RMail::Mailbox.parse_mbox for a more convenient interface.

Methods
each_message    eof    new    next    read_chunk   
Public Class methods
new(input, line_separator = $/)

Creates a new MBoxReader that reads from `input' with lines that end with `line_separator'.

`input' can either be an IO source (an object that responds to the "read" method in the same way as a standard IO object) or a String.

`line_separator' defaults to $/, and useful values are probably limited to "\n" (Unix) and "\r\n" (DOS/Windows).

Public Instance methods
read_chunk(size)

Reads some data from the current message and returns it. The `size' argument is just a suggestion, and the returned string can be larger or smaller. When `size' is nil, then the entire message is returned.

Once all data from the current message has been read, #read returns nil and #next must be called to begin reading from the next message. You can use #eof to tell if there is any more data to be read from the input source.

next()

Advances to the next message to be read. Call this after #read returns nil.

Note: Once #read returns nil, you can call #eof before or after calling #next to tell if there actually is a next message to read.

eof()

Returns true if the next call to read_chunk will return nil.

each_message() {|self| ...}

Yield self until eof, calling next after each yield.

This method makes it simple to read messages successively out of the mailbox. See the class description for a code example.