sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 856c0ebb8845f0658e056c889390f2c7086b35e2
parent 51789907cfcf80b5edb4d597c91a7c888ce5e003
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date:   Sun, 28 Mar 2010 17:01:20 -0700

plumb action up to caller of each_message_from

Diffstat:
M bin/sup-sync | 7 ++++++-
M lib/sup/draft.rb | 4 ++--
M lib/sup/poll.rb | 35 ++++++++++++++++++++++-------------
3 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/bin/sup-sync b/bin/sup-sync
@@ -114,7 +114,12 @@ begin
     num_added = num_updated = num_scanned = num_restored = 0
     last_info_time = start_time = Time.now
 
-    Redwood::PollManager.each_message_from source do |m|
+    Redwood::PollManager.each_message_from source do |action,m|
+      if action == :delete
+        puts "Deleting #{m.id}"
+        next
+      end
+
       num_scanned += 1
       seen[m.id] = true
       old_m = index.build_message m.id
diff --git a/lib/sup/draft.rb b/lib/sup/draft.rb
@@ -43,12 +43,12 @@ class DraftLoader < Source
   def to_s; DraftManager.source_name; end
   def uri; DraftManager.source_name; end
 
-  def each
+  def poll
     ids = get_ids
     ids.each do |id|
       if id >= cur_offset
         self.cur_offset = id + 1
-        yield [id, [:draft, :inbox]]
+        yield :add, id, [:draft, :inbox]
       end
     end
   end
diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
@@ -112,7 +112,12 @@ EOS
 
         num = 0
         numi = 0
-        each_message_from source do |m|
+        each_message_from source do |action,m|
+          if action == :delete
+            yield "Deleting #{m.id}"
+            next
+          end
+
           old_m = Index.build_message m.id
           if old_m
             if not old_m.locations.member? [source, m.source_info]
@@ -167,17 +172,20 @@ EOS
           return
         end
 
-        next if sym == :delete
-        fail unless sym == :add
-
-        m = Message.build_from_source source, args[:info]
-        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 }
-
-        HookManager.run "before-add-message", :message => m
-        yield m
+        case sym
+        when :add
+          m = Message.build_from_source source, args[:info]
+          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 }
+          HookManager.run "before-add-message", :message => m
+          yield :add, m
+        when :delete
+          Index.each_message :location => [source.id, args[:info]] do |m|
+            yield :delete, m
+          end
+        end
       end
     rescue SourceError => e
       warn "problem getting messages from #{source}: #{e.message}"
@@ -186,7 +194,8 @@ EOS
   end
 
   def add_new_messages source, add_labels, remove_labels
-    each_message_from(source) do |m|
+    each_message_from(source) do |action,m|
+      next unless action == :add
       remove_labels.each { |l| m.remove_label l }
       add_labels.each { |l| m.add_label l }
       add_new_message m