]> git.cworth.org Git - sup/blobdiff - lib/sup/modes/compose-mode.rb
added ThreadIndexMode#launch_next_thread_after to support dispatch-then-kill
[sup] / lib / sup / modes / compose-mode.rb
index 3dce01ee8e2a07035ea4ec238c396c3aa9795140..3c92fd286f544f9c9e0347fdc42a40a822cace0d 100644 (file)
@@ -1,32 +1,33 @@
 module Redwood
 
 class ComposeMode < EditMessageMode
-  attr_reader :body, :header
-
-  def initialize h={}
-    super()
-    @header = {
-      "From" => AccountManager.default_account.full_address,
-      "Message-Id" => gen_message_id,
-    }
-
-    @header["To"] = [h[:to]].flatten.compact.map { |p| p.full_address }
-    @body = sig_lines
-    regen_text
+  def initialize opts={}
+    header = {}
+    header["From"] = (opts[:from] || AccountManager.default_account).full_address
+    header["To"] = opts[:to].map { |p| p.full_address }.join(", ") if opts[:to]
+    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]
+    header["Subject"] = opts[:subj] if opts[:subj]
+
+    super :header => header, :body => (opts[:body] || [])
   end
 
-  def lines; @text.length; end
-  def [] i; @text[i]; end
-
-protected
-
-  def handle_new_text new_header, new_body
-    @header = new_header
-    @body = new_body
+  def edit_message
+    edited = super
+    BufferManager.kill_buffer self.buffer unless edited
+    edited
   end
 
-  def regen_text
-    @text = header_lines(@header - EditMessageMode::NON_EDITABLE_HEADERS) + [""] + @body
+  def self.spawn_nicely 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]
+    subj = opts[:subj] || BufferManager.ask(:subject, "Subject: ") or return if $config[:ask_for_subject]
+    
+    mode = ComposeMode.new :from => opts[:from], :to => to, :cc => cc, :bcc => bcc, :subj => subj
+    BufferManager.spawn "New Message", mode
+    mode.edit_message
   end
 end