]> git.cworth.org Git - sup/commitdiff
fix mbox splitting regexp
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Tue, 28 Apr 2009 13:34:27 +0000 (09:34 -0400)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 29 Apr 2009 17:47:02 +0000 (13:47 -0400)
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.

lib/sup/mbox.rb
lib/sup/mbox/loader.rb

index 8497a37f11a6f6a00bce35953e4a43d5c96103e7..33a8adb069226d435d277afe7707d42c45be29ae 100644 (file)
@@ -10,7 +10,7 @@ module Redwood
 ##
 ## 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
index 7fe912900e16d477fc7d690873d92e9c623f48c2..086510ddf83b7841bbf331994a8d0b8770cd4de7 100644 (file)
@@ -68,13 +68,12 @@ class Loader < Source
     @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