sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 51789907cfcf80b5edb4d597c91a7c888ce5e003
parent c09945efe3d4599c904883a455318e4b7b5d3298
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date:   Fri, 26 Mar 2010 09:06:04 -0700

remove uses of each_message_from

Diffstat:
M lib/sup/connection.rb | 8 +-------
M lib/sup/draft.rb | 17 +++++------------
M lib/sup/poll.rb | 11 ++++++++++-
M lib/sup/sent.rb | 8 ++------
M lib/sup/source.rb | 2 ++
5 files changed, 20 insertions(+), 26 deletions(-)
diff --git a/lib/sup/connection.rb b/lib/sup/connection.rb
@@ -49,13 +49,7 @@ class Connection
     SentManager.source.store_message Time.now, "test@example.com" do |io|
       io.write raw
     end
-    m2 = nil
-    PollManager.each_message_from(SentManager.source) do |m|
-      PollManager.add_new_message m
-      m2 = m
-    end
-    m2.labels = Set.new(labels.map(&:to_sym))
-    Index.update_message_state m2
+    PollManager.add_new_messages SentManager.source, labels, []
     nil
   end
 end
diff --git a/lib/sup/draft.rb b/lib/sup/draft.rb
@@ -17,14 +17,7 @@ class DraftManager
     offset = @source.gen_offset
     fn = @source.fn_for_offset offset
     File.open(fn, "w") { |f| yield f }
-
-    my_message = nil
-    PollManager.each_message_from(@source) do |m|
-      PollManager.add_new_message m
-      my_message = m
-    end
-
-    my_message
+    PollManager.add_new_messages @source
   end
 
   def discard m
@@ -37,12 +30,12 @@ end
 
 class DraftLoader < Source
   attr_accessor :dir
-  yaml_properties :cur_offset
+  yaml_properties
 
-  def initialize cur_offset=0
+  def initialize
     dir = Redwood::DRAFT_DIR
     Dir.mkdir dir unless File.exists? dir
-    super DraftManager.source_name, cur_offset, true, false
+    super DraftManager.source_name, true, false
     @dir = dir
   end
 
@@ -61,7 +54,7 @@ class DraftLoader < Source
   end
 
   def gen_offset
-    i = cur_offset
+    i = 0
     while File.exists? fn_for_offset(i)
       i += 1
     end
diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
@@ -171,7 +171,8 @@ EOS
         fail unless sym == :add
 
         m = Message.build_from_source source, args[:info]
-        m.labels += args[:labels] + (source.archived? ? [] : [:inbox])
+        m.labels += args[:labels]
+        m.labels.delete :unread if source.read?
         m.labels.delete :unread if m.source_marked_read? # preserve read status if possible
         m.labels.each { |l| LabelManager << l }
 
@@ -184,6 +185,14 @@ EOS
     end
   end
 
+  def add_new_messages source, add_labels, remove_labels
+    each_message_from(source) do |m|
+      remove_labels.each { |l| m.remove_label l }
+      add_labels.each { |l| m.add_label l }
+      add_new_message m
+    end
+  end
+
   ## TODO: see if we can do this within PollMode rather than by calling this
   ## method.
   ##
diff --git a/lib/sup/sent.rb b/lib/sup/sent.rb
@@ -26,12 +26,7 @@ class SentManager
 
   def write_sent_message date, from_email, &block
     @source.store_message date, from_email, &block
-
-    PollManager.each_message_from(@source) do |m|
-      m.remove_label :unread
-      m.add_label :sent
-      PollManager.add_new_message m
-    end
+    PollManager.add_new_messages @sources, [:sent], [:unread]
   end
 end
 
@@ -51,6 +46,7 @@ class SentLoader < MBox
 
   def id; 9998; end
   def labels; [:inbox, :sent]; end
+  def read?; true; end
 end
 
 end
diff --git a/lib/sup/source.rb b/lib/sup/source.rb
@@ -79,6 +79,8 @@ class Source
   def == o; o.uri == uri; end
   def is_source_for? uri; uri == @uri; end
 
+  def read?; false; end
+
   ## Yields values of the form [Symbol, Hash]
   ## add: info, labels, progress
   ## delete: info, progress