Sha256: b8a7b4fa346020c7ebdda8576e21cc1c6da321b85dea705804f379c860a2087e

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module Redwood

module CanSpawnComposeMode
  def spawn_compose_mode 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 = ComposeMode.new :to => to, :cc => cc, :bcc => bcc
    BufferManager.spawn "New Message", mode
    mode.edit_message
  end
end

class ComposeMode < EditMessageMode
  def initialize opts={}
    header = {
      "From" => AccountManager.default_account.full_address,
    }

    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 edit_message
    edited = super
    BufferManager.kill_buffer self.buffer unless edited
    edited
  end
end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sup-0.2 lib/sup/modes/compose-mode.rb