Class: Redwood::ReplyMode

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

Constant Summary collapse

REPLY_TYPES =
[:sender, :recipient, :list, :all, :user]
TYPE_DESCRIPTIONS =
{
  :sender => "Reply to sender",
  :recipient => "Reply to recipient",
  :all => "Reply to all",
  :list => "Reply to mailing list",
  :user => "Customized reply"
}

Constants inherited from EditMessageMode

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

Instance Method Summary collapse

Methods inherited from EditMessageMode

#attach_file, #delete_attachment, #edit_cc, #edit_message, #edit_message_or_field, #edit_subject, #edit_to, #killable?

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, #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_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, register_keymap, #resize, #resolve_input, #save_to_file, #status

Constructor Details

#initialize(message) ⇒ ReplyMode

Returns a new instance of ReplyMode.



18
19
20
21
22
23
24
25
26
27
28
29
30
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/sup/modes/reply-mode.rb', line 18

def initialize message
  @m = message

  ## it's important to put this early because it forces a read of
  ## the full headers (most importantly the list-post header, if
  ## any)
  body = reply_body_lines message

  from =
    if @m.recipient_email && (a = AccountManager.(@m.recipient_email))
      a
    elsif(b = (@m.to + @m.cc).find { |p| AccountManager.is_account? p })
      b
    else
      AccountManager.
    end

  ## ignore reply-to for list messages because it's typically set to
  ## the list address, which we explicitly treat with :list
  to = @m.is_list_message? ? @m.from : (@m.replyto || @m.from)
  cc = (@m.to + @m.cc - [from, to]).uniq

  @headers = {}

  ## if there's no cc, then the sender is the person you want to reply
  ## to. if it's a list message, then the list address is. otherwise,
  ## the cc contains a recipient.
  useful_recipient = !(cc.empty? || @m.is_list_message?)
  
  @headers[:recipient] = {
    "To" => cc.map { |p| p.full_address },
  } if useful_recipient

  ## typically we don't want to have a reply-to-sender option if the sender
  ## is a user account. however, if the cc is empty, it's a message to
  ## ourselves, so for the lack of any other options, we'll add it.
  @headers[:sender] = { "To" => [to.full_address], } if !AccountManager.is_account?(to) || !useful_recipient

  @headers[:user] = {}

  @headers[:all] = {
    "To" => [to.full_address],
    "Cc" => cc.select { |p| !AccountManager.is_account?(p) }.map { |p| p.full_address },
  } unless cc.empty?

  @headers[:list] = {
    "To" => [@m.list_address.full_address],
  } if @m.is_list_message?

  refs = gen_references

  @headers.each do |k, v|
    @headers[k] = {
             "From" => "#{from.name} <#{from.email}>",
             "To" => [],
             "Cc" => [],
             "Bcc" => [],
             "In-Reply-To" => "<#{@m.id}>",
             "Subject" => Message.reify_subj(@m.subj),
             "References" => refs,
           }.merge v
  end

  @type_labels = REPLY_TYPES.select { |t| @headers.member?(t) }
  @selected_type = 
    if @m.is_list_message?
      :list
    elsif @headers.member? :sender
      :sender
    else
      :recipient
    end

  super :header => @headers[@selected_type], :body => body,
        :skip_top_rows => 2, :twiddles => false
end

Instance Method Details

#[](i) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/sup/modes/reply-mode.rb', line 96

def [] i
  case i
  when 0
    @type_labels.inject([]) do |array, t|
      array + [[(t == @selected_type ? :none_highlight : :none), 
        "#{TYPE_DESCRIPTIONS[t]}"], [:none, "  "]]
    end + [[:none, ""]]
  when 1
    ""
  else
    super(i - 2)
  end
end

#linesObject



95
# File 'lib/sup/modes/reply-mode.rb', line 95

def lines; super + 2; end