sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit d41d3ab44903e4e894ecb9bed2740846e05fa53b
parent 660ce358d0e03e77205ea93a7341bcf58f458a06
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date:   Wed,  7 Nov 2007 20:54:24 +0000

improve forwarding, having it prompt for addresses and respect related configuration options, etc

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

Diffstat:
M lib/sup/modes/forward-mode.rb | 27 +++++++++++++++++++++++----
M lib/sup/modes/thread-index-mode.rb | 6 +++---
M lib/sup/modes/thread-view-mode.rb | 5 ++---
3 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/lib/sup/modes/forward-mode.rb b/lib/sup/modes/forward-mode.rb
@@ -1,12 +1,31 @@
 module Redwood
 
+module CanSpawnForwardMode
+  def spawn_forward_mode m, opts={}
+    to = opts[:to] || BufferManager.ask_for_contacts(:people, "To: ") or return
+    cc = opts[:cc] || BufferManager.ask_for_contacts(:people, "Cc: ") or return if $config[:ask_for_cc]
+    bcc = opts[:bcc] || BufferManager.ask_for_contacts(:people, "Bcc: ") or return if $config[:ask_for_bcc]
+    
+    mode = ForwardMode.new m, :to => to, :cc => cc, :bcc => bcc
+    BufferManager.spawn "Forwarding #{m.subj}", mode
+    mode.edit_message
+  end
+end
+
 class ForwardMode < EditMessageMode
-  def initialize m
-    super :header => {
+
+  ## todo: share some of this with reply-mode
+  def initialize m, opts={}
+    header = {
       "From" => AccountManager.default_account.full_address,
       "Subject" => "Fwd: #{m.subj}",
-    },
-         :body => forward_body_lines(m)
+    }
+
+    header["To"] = opts[:to].map { |p| p.full_address }.join(", ") if opts[:to]
+    header["Cc"] = opts[:cc].map { |p| p.full_address }.join(", ") if opts[:cc]
+    header["Bcc"] = opts[:bcc].map { |p| p.full_address }.join(", ") if opts[:bcc]
+
+    super :header => header, :body => forward_body_lines(m)
   end
 
 protected
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
@@ -4,6 +4,8 @@ module Redwood
 ## - is_relevant?
 
 class ThreadIndexMode < LineCursorMode
+  include CanSpawnForwardMode
+
   DATE_WIDTH = Time::TO_NICE_S_MAX_LEN
   MIN_FROM_WIDTH = 15
   LOAD_MORE_THREAD_NUM = 20
@@ -379,9 +381,7 @@ EOS
     m = t.latest_message
     return if m.nil? # probably won't happen
     m.load_from_source!
-    mode = ForwardMode.new m
-    BufferManager.spawn "Forward of #{m.subj}", mode
-    mode.edit_message
+    spawn_forward_mode m
   end
 
   def load_n_threads_background n=LOAD_MORE_THREAD_NUM, opts={}
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
@@ -2,6 +2,7 @@ module Redwood
 
 class ThreadViewMode < LineCursorMode
   include CanSpawnComposeMode
+  include CanSpawnForwardMode
 
   ## this holds all info we need to lay out a message
   class MessageLayout
@@ -109,9 +110,7 @@ class ThreadViewMode < LineCursorMode
 
   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