I dunno. This helps with the "From problem", but at the expense of being
too specific than the mbox spec really demands. I don't think there's a
really right solution, in general (due to the mbox format being a
fundamentally broken one), but I'm hoping this will work with all modern
mbox files.
##
## TODO: move functionality to somewhere better, like message.rb
module MBox
- BREAK_RE = /^From \S+/
+ BREAK_RE = /^From \S+@\S+ /
HEADER_RE = /\s*(.*?)\s*/
def read_header f
@mutex.synchronize do
@f.seek offset
begin
- RMail::Mailbox::MBoxReader.new(@f).each_message do |input|
- m = RMail::Parser.read(input)
- if m.body && m.body.is_a?(String)
- m.body.gsub!(/^>From /, "From ")
- end
- return m
- end
+ ## don't use RMail::Mailbox::MBoxReader because it doesn't properly ignore
+ ## "From" at the start of a message body line.
+ string = ""
+ l = @f.gets
+ string << l until @f.eof? || (l = @f.gets) =~ BREAK_RE
+ RMail::Parser.read string
rescue RMail::Parser::Error => e
raise FatalSourceError, "error parsing mbox file: #{e.message}"
end