]> git.cworth.org Git - sup/blobdiff - lib/sup/modes/thread-view-mode.rb
added chronic support thanks to Marcus Williams
[sup] / lib / sup / modes / thread-view-mode.rb
index f00e19c670737331a89ab36d204e38e194cb2ab7..88c512529f148bb9a2b9e5c4e3635cc587b997e1 100644 (file)
@@ -1,6 +1,9 @@
 module Redwood
 
 class ThreadViewMode < LineCursorMode
+  include CanSpawnComposeMode
+  include CanSpawnForwardMode
+
   ## this holds all info we need to lay out a message
   class MessageLayout
     attr_accessor :top, :bot, :prev, :next, :depth, :width, :state, :color, :star_color, :orig_new
@@ -35,6 +38,8 @@ class ThreadViewMode < LineCursorMode
     k.add :compose, "Compose message to person", 'm'
     k.add :archive_and_kill, "Archive thread and kill buffer", 'a'
     k.add :delete_and_kill, "Delete thread and kill buffer", 'd'
+    k.add :subscribe_to_list, "Subscribe to/unsubscribe from mailing list", "("
+    k.add :unsubscribe_from_list, "Subscribe to/unsubscribe from mailing list", ")"
   end
 
   ## there are a couple important instance variables we hold to format
@@ -105,11 +110,27 @@ class ThreadViewMode < LineCursorMode
     BufferManager.spawn "Reply to #{m.subj}", mode
   end
 
+  def subscribe_to_list
+    m = @message_lines[curpos] or return
+    if m.list_subscribe && m.list_subscribe =~ /<mailto:(.*?)\?(subject=(.*?))>/
+      spawn_compose_mode :from => AccountManager.account_for(m.recipient_email), :to => [PersonManager.person_for($1)], :subj => $3
+    else
+      BufferManager.flash "Can't find List-Subscribe header for this message."
+    end
+  end
+
+  def unsubscribe_from_list
+    m = @message_lines[curpos] or return
+    if m.list_unsubscribe && m.list_unsubscribe =~ /<mailto:(.*?)\?(subject=(.*?))>/
+      spawn_compose_mode :from => AccountManager.account_for(m.recipient_email), :to => [PersonManager.person_for($1)], :subj => $3
+    else
+      BufferManager.flash "Can't find List-Unsubscribe header for this message."
+    end
+  end
+
   def forward
     m = @message_lines[curpos] or return
-    mode = ForwardMode.new m
-    BufferManager.spawn "Forward of #{m.subj}", mode
-    mode.edit_message
+    spawn_forward_mode m
   end
 
   include CanAliasContacts
@@ -128,14 +149,11 @@ class ThreadViewMode < LineCursorMode
 
   def compose
     p = @person_lines[curpos]
-    mode =
-      if p
-        ComposeMode.new :to => [p]
-      else
-        ComposeMode.new
-      end
-    BufferManager.spawn "Compose message", mode
-    mode.edit_message
+    if p
+      spawn_compose_mode :to => [p]
+    else
+      spawn_compose_mode
+    end
   end    
 
   def edit_labels
@@ -146,7 +164,7 @@ class ThreadViewMode < LineCursorMode
     @thread.labels = (reserved_labels + new_labels).uniq
     new_labels.each { |l| LabelManager << l }
     update
-    UpdateManager.relay self, :label, m
+    UpdateManager.relay self, :label_thread, @thread
   end
 
   def toggle_starred
@@ -237,6 +255,7 @@ class ThreadViewMode < LineCursorMode
   end
 
   def jump_to_next_open
+    return continue_search_in_buffer if in_search? # hack: allow 'n' to apply to both operations
     m = @message_lines[curpos] or return
     while nextm = @layout[m].next
       break if @layout[nextm].state != :closed