]> git.cworth.org Git - sup/blobdiff - lib/sup/mbox/loader.rb
keybindings: ; -> buffer-list-mode, b, B, +
[sup] / lib / sup / mbox / loader.rb
index 48ddfba41a91b00622fccece63064f8ccd0fd85b..7fe912900e16d477fc7d690873d92e9c623f48c2 100644 (file)
@@ -6,6 +6,7 @@ module MBox
 
 class Loader < Source
   yaml_properties :uri, :cur_offset, :usual, :archived, :id, :labels
+  attr_accessor :labels
 
   ## uri_or_fp is horrific. need to refactor.
   def initialize uri_or_fp, start_offset=nil, usual=true, archived=false, id=nil, labels=[]
@@ -37,7 +38,7 @@ class Loader < Source
     if File.dirname(path) =~ /\b(var|usr|spool)\b/
       []
     else
-      [File.basename(path).intern]
+      [File.basename(path).downcase.intern]
     end
   end
 
@@ -68,7 +69,11 @@ class Loader < Source
       @f.seek offset
       begin
         RMail::Mailbox::MBoxReader.new(@f).each_message do |input|
-          return RMail::Parser.read(input)
+          m = RMail::Parser.read(input)
+          if m.body && m.body.is_a?(String)
+            m.body.gsub!(/^>From /, "From ")
+          end
+          return m
         end
       rescue RMail::Parser::Error => e
         raise FatalSourceError, "error parsing mbox file: #{e.message}"
@@ -80,7 +85,7 @@ class Loader < Source
     ret = ""
     @mutex.synchronize do
       @f.seek offset
-      until @f.eof? || (l = @f.gets) =~ /^$/
+      until @f.eof? || (l = @f.gets) =~ /^\r*$/
         ret += l
       end
     end
@@ -143,7 +148,7 @@ class Loader < Source
     end
 
     self.cur_offset = next_offset
-    [returned_offset, (@labels + [:unread]).uniq]
+    [returned_offset, (self.labels + [:unread]).uniq]
   end
 end