Class: Redwood::ForwardMode

Inherits:
EditMessageMode show all
Defined in:
lib/sup/modes/forward-mode.rb

Constant Summary

Constant Summary

Constants inherited from EditMessageMode

EditMessageMode::DECORATION_LINES, EditMessageMode::FORCE_HEADERS, EditMessageMode::MULTI_HEADERS, EditMessageMode::NON_EDITABLE_HEADERS

Constants inherited from ScrollMode

ScrollMode::COL_JUMP

Instance Attribute Summary

Attributes inherited from EditMessageMode

#body, #header, #status

Attributes inherited from LineCursorMode

#curpos

Attributes inherited from ScrollMode

#botline, #leftcol, #status, #topline

Attributes inherited from Mode

#buffer

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from EditMessageMode

#[], #attach_file, #delete_attachment, #edit_cc, #edit_message, #edit_message_or_field, #edit_subject, #edit_to, #handle_new_text, #killable?, #lines

Methods inherited from LineCursorMode

#draw

Methods inherited from ScrollMode

#at_bottom?, #at_top?, #cancel_search!, #col_left, #col_right, #continue_search_in_buffer, #draw, #ensure_mode_validity, #half_page_down, #half_page_up, #in_search?, #jump_to_col, #jump_to_end, #jump_to_left, #jump_to_line, #jump_to_start, #line_down, #line_up, #page_down, #page_up, #resize, #rightcol, #search_goto_line, #search_goto_pos, #search_in_buffer, #search_start_line

Methods inherited from Mode

#blur, #cancel_search!, #cleanup, #draw, #focus, #handle_input, #help_text, #in_search?, #killable?, load_all_modes, make_name, #name, #pipe_to_process, register_keymap, #resize, #resolve_input, #save_to_file, #status

Constructor Details

- (ForwardMode) initialize(opts = {})

TODO: share some of this with reply-mode



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sup/modes/forward-mode.rb', line 5

def initialize opts={}
  header = {
    "From" => AccountManager..full_address,
  }

  header["Subject"] = 
    if opts[:message]
      "Fwd: " + opts[:message].subj
    elsif opts[:attachments]
      "Fwd: " + opts[:attachments].keys.join(", ")
    end

  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]

  body =
    if opts[:message]
      forward_body_lines(opts[:message]) 
    elsif opts[:attachments]
      ["Note: #{opts[:attachments].size.pluralize 'attachment'}."]
    end

  super :header => header, :body => body, :attachments => opts[:attachments]
end

Class Method Details

+ (Object) spawn_nicely(opts = {})



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sup/modes/forward-mode.rb', line 31

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]
  
  attachment_hash = {}
  attachments = opts[:attachments] || []

  if(m = opts[:message])
    m.load_from_source! # read the full message in. you know, maybe i should just make Message#chunks do this....
    attachments += m.chunks.select { |c| c.is_a?(Chunk::Attachment) && !c.quotable? }
  end

  attachments.each do |c|
    mime_type = MIME::Types[c.content_type].first || MIME::Types["application/octet-stream"].first
    attachment_hash[c.filename] = RMail::Message.make_attachment c.raw_content, mime_type.content_type, mime_type.encoding, c.filename
  end

  mode = ForwardMode.new :message => opts[:message], :to => to, :cc => cc, :bcc => bcc, :attachments => attachment_hash

  title = "Forwarding " +
    if opts[:message]
      opts[:message].subj
    elsif attachments
      attachment_hash.keys.join(", ")
    else
      "something"
    end

  BufferManager.spawn title, mode
  mode.edit_message
end