sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 2e85c498c0fef72c071f87c1cccb8f7aa8b0e2ea
parent bfe40c05dc6dc2656a4dde11948ff617f2fa00d6
Author: Bo Borgerson <gigabo@gmail.com>
Date:   Sun, 13 Sep 2009 10:38:35 -0400

add command for polling unusual sources

bin/sup: Add new global key binding, '{', to poll unusual sources
(requires confirmation).  This allows update of unusual sources
without having to leave sup to run a sync.

lib/sup/poll.rb: Add new method, poll_unusual.  Both the pre-existing
poll method and the new poll_unusual method are now wrappers around
new poll_with_sources method that contains the bulk of functionality
previously in poll.

lib/sup/source.rb: Add new accessor for unusual_sources

Diffstat:
M bin/sup | 5 +++++
M lib/sup/poll.rb | 23 +++++++++++++++++++----
M lib/sup/source.rb | 1 +
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/bin/sup b/bin/sup
@@ -76,6 +76,7 @@ global_keymap = Keymap.new do |k|
   k.add :search_unread, "Show all unread messages", 'U'
   k.add :list_labels, "List labels", 'L'
   k.add :poll, "Poll for new messages", 'P'
+  k.add :poll_unusual, "Poll for new messages from unusual sources", '{'
   k.add :compose, "Compose new message", 'm', 'c'
   k.add :nothing, "Do nothing", :ctrl_g
   k.add :recall_draft, "Edit most recent draft message", 'R'
@@ -283,6 +284,10 @@ begin
       ComposeMode.spawn_nicely
     when :poll
       reporting_thread("user-invoked poll") { PollManager.poll }
+    when :poll_unusual
+      if BufferManager.ask_yes_or_no "Really poll unusual sources?"
+        reporting_thread("user-invoked unusual poll") { PollManager.poll_unusual }
+      end
     when :recall_draft
       case Index.num_results_for :label => :draft
       when 0
diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
@@ -35,12 +35,11 @@ EOS
     @thread = nil
     @last_poll = nil
     @polling = false
+    @poll_sources = nil
     @mode = nil
   end
 
-  def poll
-    return if @polling
-    @polling = true
+  def poll_with_sources
     @mode ||= PollMode.new
     HookManager.run "before-poll"
 
@@ -54,6 +53,22 @@ EOS
 
     HookManager.run "after-poll", :num => num, :num_inbox => numi, :from_and_subj => from_and_subj, :from_and_subj_inbox => from_and_subj_inbox, :num_inbox_total_unread => lambda { Index.num_results_for :labels => [:inbox, :unread] }
 
+  end
+
+  def poll
+    return if @polling
+    @polling = true
+    @poll_sources = SourceManager.usual_sources
+    num, numi = poll_with_sources
+    @polling = false
+    [num, numi]
+  end
+
+  def poll_unusual
+    return if @polling
+    @polling = true
+    @poll_sources = SourceManager.unusual_sources
+    num, numi = poll_with_sources
     @polling = false
     [num, numi]
   end
@@ -78,7 +93,7 @@ EOS
     from_and_subj_inbox = []
 
     @mutex.synchronize do
-      SourceManager.usual_sources.each do |source|
+      @poll_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.respond_to?(:has_errors?) && source.has_errors?)
diff --git a/lib/sup/source.rb b/lib/sup/source.rb
@@ -207,6 +207,7 @@ class SourceManager
 
   def source_for uri; sources.find { |s| s.is_source_for? uri }; end
   def usual_sources; sources.find_all { |s| s.usual? }; end
+  def unusual_sources; sources.find_all { |s| !s.usual? }; end
 
   def load_sources fn=Redwood::SOURCE_FN
     source_array = (Redwood::load_yaml_obj(fn) || []).map { |o| Recoverable.new o }