sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 924852255e80114d271204a7c3456df49bc6c96d
parent 26282c3bacb376f2cddcf282c73addd9c8017fb3
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date:   Sun,  9 Dec 2007 19:12:19 +0000

add tag by match to thread-index-mode

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

Diffstat:
M lib/sup/modes/thread-index-mode.rb | 15 +++++++++++++++
M lib/sup/tagger.rb | 2 ++
2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
@@ -31,6 +31,7 @@ EOS
     k.add :forward, "Forward latest message in a thread", 'f'
     k.add :toggle_tagged, "Tag/untag selected thread", 't'
     k.add :toggle_tagged_all, "Tag/untag all threads", 'T'
+    k.add :tag_matching, "Tag/untag all threads", 'g'
     k.add :apply_to_tagged, "Apply next command to all tagged threads", ';'
   end
 
@@ -351,6 +352,14 @@ EOS
     regen_text
   end
 
+  def tag_matching
+    query = BufferManager.ask :search, "tag threads matching: "
+    return if query.nil? || query.empty?
+    query = /#{query}/i
+    @mutex.synchronize { @threads.each { |t| @tags.tag t if thread_match?(t, query) } }
+    regen_text
+  end
+
   def apply_to_tagged; @tags.apply_to_tagged; end
 
   def edit_labels
@@ -465,6 +474,12 @@ EOS
 
 protected
 
+  ## used to tag threads by query. this can be made a lot more sophisticated,
+  ## but for right now we'll do the obvious this.
+  def thread_match? t, query
+    t.snippet =~ query || t.participants.any? { |x| x.longname =~ query }
+  end
+
   def size_widget_for_thread t
     HookManager.run("index-mode-size-widget", :thread => t) || default_size_widget_for(t)
   end
diff --git a/lib/sup/tagger.rb b/lib/sup/tagger.rb
@@ -8,6 +8,8 @@ class Tagger
 
   def tagged? o; @tagged[o]; end
   def toggle_tag_for o; @tagged[o] = !@tagged[o]; end
+  def tag o; @tagged[o] = true; end
+  def untag o; @tagged[o] = false; end
   def drop_all_tags; @tagged.clear; end
   def drop_tag_for o; @tagged.delete o; end