sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit af10b0fcdd1a192f7bec9c116f677a1bd93bb760
parent b776b3b1f60aaef49ad8b36c47a7a47ca2e67474
Author: Jason Petsod <jason@petsod.org>
Date:   Fri,  4 Jun 2010 19:57:46 -0700

add a thread request to sup-server

Diffstat:
M lib/sup/client.rb | 16 ++++++++++++++++
M lib/sup/server.rb | 15 +++++++++++++++
2 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/lib/sup/client.rb b/lib/sup/client.rb
@@ -65,6 +65,22 @@ class Redwood::Client < EM::P::RedwoodClient
                  'labels' => labels
   end
 
+  def thread msg_id, raw, &b
+    tag = mktag do |type,tag,args|
+      if type == 'message'
+        b.call args
+      else
+        fail unless type == 'done'
+        b.call nil
+        rmtag tag
+      end
+    end
+
+    send_message 'thread', tag,
+                 'message_id' => msg_id,
+                 'raw' => raw
+  end
+
   def receive_message type, tag, args
     cb = @cbs[tag] or fail "invalid tag #{tag.inspect}"
     cb[type, tag, args]
diff --git a/lib/sup/server.rb b/lib/sup/server.rb
@@ -34,6 +34,13 @@ class Redwood::Server < EM::P::RedwoodServer
     send_message 'done', tag
   end
 
+  def request_thread tag, a
+    thread a['message_id'], a['raw'] do |r|
+      send_message 'message', tag, r
+    end
+    send_message 'done', tag
+  end
+
 private
 
   def result_from_message m, raw
@@ -92,4 +99,12 @@ private
     Index.update_message_state m2
     nil
   end
+
+  def thread msg_id, raw
+    msg = Index.build_message msg_id
+    Index.each_message_in_thread_for msg do |id, builder|
+      m = builder.call
+      yield result_from_message(m, raw)
+    end
+  end
 end