sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 45dc40dc11d986b846df7cda0f72deb2d511eaa4
parent e08c09f7310a5e5ca565708c80aef523019165ab
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Wed, 29 Apr 2009 13:53:19 -0400

Merge branch 'various-mbox-fixes' into next

Conflicts:

	lib/sup/mbox.rb

Diffstat:
M lib/sup/mbox.rb | 2 +-
M lib/sup/mbox/loader.rb | 13 ++++++-------
M lib/sup/message.rb | 3 ++-
M lib/sup/poll.rb | 2 +-
M test/dummy_source.rb | 7 -------
5 files changed, 10 insertions(+), 17 deletions(-)
diff --git a/lib/sup/mbox.rb b/lib/sup/mbox.rb
@@ -6,6 +6,6 @@ require "sup/rfc2047"
 module Redwood
 
 module MBox
-  BREAK_RE = /^From \S+/ ######### TODO REMOVE ME
+  BREAK_RE = /^From \S+@\S+ /
 end
 end
diff --git a/lib/sup/mbox/loader.rb b/lib/sup/mbox/loader.rb
@@ -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
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
@@ -190,7 +190,7 @@ class Message
   ## this is called when the message body needs to actually be loaded.
   def load_from_source!
     @chunks ||=
-      if @source.has_errors?
+      if @source.respond_to?(:has_errors?) && @source.has_errors?
         [Chunk::Text.new(error_message(@source.error.message).split("\n"))]
       else
         begin
@@ -364,6 +364,7 @@ private
     [notice, sig, children].flatten.compact
   end
 
+  ## takes a RMail::Message, breaks it into Chunk:: classes.
   def message_to_chunks m, encrypted=false, sibling_types=[]
     if m.multipart?
       chunks =
diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
@@ -86,7 +86,7 @@ EOS
       Index.usual_sources.each do |source|
 #        yield "source #{source} is done? #{source.done?} (cur_offset #{source.cur_offset} >= #{source.end_offset})"
         begin
-          yield "Loading from #{source}... " unless source.done? || source.has_errors?
+          yield "Loading from #{source}... " unless source.done? || (source.respond_to?(:has_errors?) && source.has_errors?)
         rescue SourceError => e
           Redwood::log "problem getting messages from #{source}: #{e.message}"
           Redwood::report_broken_sources :force_to_top => true
diff --git a/test/dummy_source.rb b/test/dummy_source.rb
@@ -53,13 +53,6 @@ class DummySource < Source
       yield f.gets
     end
   end
-
-  # FIXME: this one was not mentioned in the source documentation, but
-  # it's still required
-  def has_errors?
-
-  end
-
 end
 
 end