sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 59cb2add14f75a2b4977d7c59738ba0baeb2b517
parent 4c8091314b3ad6005bc33d89793f8ebda145756b
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date:   Sat,  2 Dec 2006 00:34:19 +0000

improved polling behavior


git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@59 5c8cc53c-5e98-4d25-b20a-d8db53a31250

Diffstat:
M bin/sup | 35 ++++++++++++++---------------------
M lib/sup/buffer.rb | 2 +-
M lib/sup/modes/poll-mode.rb | 4 ++--
M lib/sup/poll.rb | 24 +++++++++++++++++++-----
4 files changed, 36 insertions(+), 29 deletions(-)
diff --git a/bin/sup b/bin/sup
@@ -99,15 +99,6 @@ begin
   log "initializing buffer manager"
   bm = BufferManager.new
 
-  if Index.usual_sources.any? { |s| !s.done? }
-    log "polling for new mail"
-    pmode = PollMode.new
-    pbuf = bm.spawn "load new messages", pmode
-    pmode.poll
-#    sleep 1
-#    bm.kill_buffer pbuf
-  end
-
   log "initializing mail index buffer"
   imode = InboxMode.new
   ibuf = bm.spawn "inbox", imode
@@ -118,6 +109,8 @@ begin
   bm.draw_screen
   imode.load_more_threads ibuf.content_height
 
+  ::Thread.new { sleep 5; PollManager.poll }
+
   until $exception
     bm.draw_screen
     c = Ncurses.nonblocking_getch
@@ -168,10 +161,8 @@ begin
           bm.spawn "new message", mode
           mode.edit
         when :poll
-          b = BufferManager.spawn_unless_exists("load new messages") do
-            PollMode.new
-          end
-          b.mode.poll
+          BufferManager.raise_to_front PollManager.buffer
+          PollManager.poll
         when :nothing
         when :redraw
           bm.completely_redraw_screen
@@ -193,21 +184,23 @@ end
 Index.save unless $exception # TODO: think about this
 
 if $exception 
-  if $exception.is_a? IndexError
+  case $exception
+  when IndexError
     $stderr.puts <<EOS
-An error occurred while loading a message from source "#{$exception.source}".
+An error occurred while parsing a message from source "#{$exception.source}".
 Typically, this means that the source has been modified in some
-way which has rendered the messages invalid.
+way which has rendered the messages invalid. For example, if it's an mbox
+file, you may have read or deleted messages using another client.
 
 You must rebuild the index for this source. Please run:
   sup-import --rebuild #{$exception.source}
 to correct this error.
 EOS
-  raise $exception                             
+#' stupid ruby-mode
   else
     $stderr.puts <<EOS
------------------------------------------------------------------
-I'm very sorry, but it seems that an error occurred in Redwood. 
+----------------------------------------------------------------
+I'm very sorry, but it seems that an error occurred in Sup. 
 Please accept my sincere apologies. If you don't mind, please
 send the backtrace below and a brief report of the circumstances
 to user wmorgan-sup at site masanjin dot net so that I might
@@ -215,13 +208,13 @@ address this problem. Thank you!
 
 Sincerely,
 William
------------------------------------------------------------------
+----------------------------------------------------------------
 
 The problem was: #{$exception.message} (error type #{$exception.class.name})
 A backtrace follows:
 EOS
-    raise $exception
   end
+  raise $exception
 end
 
 
diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
@@ -216,7 +216,7 @@ class BufferManager
   def spawn_unless_exists title, opts={}
     if @name_map.member? title
       Redwood::log "buffer '#{title}' already exists, raising to front"
-      raise_to_front @name_map[title]
+      raise_to_front @name_map[title] unless opts[:hidden]
     else
       mode = yield
       spawn title, mode, opts
diff --git a/lib/sup/modes/poll-mode.rb b/lib/sup/modes/poll-mode.rb
@@ -16,8 +16,8 @@ class PollMode < LogMode
   def poll
     puts unless @new
     @new = false
-    puts "poll started at #{Time.now}"
-    PollManager.poll { |s| puts s }
+    puts "Poll started at #{Time.now}"
+    PollManager.do_poll { |s| puts s }
   end
 end
 
diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
@@ -17,16 +17,30 @@ class PollManager
       while true
         sleep DELAY / 2
         if @last_poll.nil? || (Time.now - @last_poll) >= DELAY
-          mbid = BufferManager.say "Polling for new messages..."
-          num, numi = poll { |s| BufferManager.say s, mbid }
-          BufferManager.clear mbid
-          BufferManager.flash "Loaded #{num} new messages, #{numi} to inbox." if num > 0
+          poll
         end
       end
     end
   end
 
+  def buffer
+    BufferManager.spawn_unless_exists("<poll for new messages>", :hidden => true) do
+      PollMode.new
+    end
+  end
+
   def poll
+    BufferManager.flash "Polling for new messages..."
+    num, numi = buffer.mode.poll
+    if num > 0
+      BufferManager.flash "Loaded #{num} new messages, #{numi} to inbox." 
+    else
+      BufferManager.flash "No new messages."
+    end
+    [num, numi]
+  end
+
+  def do_poll
     return [0, 0] if @polling
     @polling = true
     found = {}
@@ -41,7 +55,7 @@ class PollManager
       num_inbox = 0
       source.each do |offset, labels|
         start_offset ||= offset
-
+        yield " Found message at #{offset} with labels #{labels * ', '}"
         begin
           m = Redwood::Message.new source, offset, labels
           if found[m.id]