lib/sup/modes/reply-mode.rb in sup-0.0.6 vs lib/sup/modes/reply-mode.rb in sup-0.0.7
- old
+ new
@@ -1,11 +1,12 @@
module Redwood
class ReplyMode < EditMessageMode
- REPLY_TYPES = [:sender, :list, :all, :user]
+ 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"
}
@@ -28,23 +29,29 @@
AccountManager.account_for(@m.recipient_email)
else
(@m.to + @m.cc).find { |p| AccountManager.is_account? p }
end || AccountManager.default_account
- from_email = @m.recipient_email || from.email
+ #from_email = @m.recipient_email || from.email
+ from_email = from.email
## ignore reply-to for list messages because it's typically set to
## the list address anyways
to = @m.is_list_message? ? @m.from : (@m.replyto || @m.from)
cc = (@m.to + @m.cc - [from, to]).uniq
@headers = {}
@headers[:sender] = {
"From" => "#{from.name} <#{from_email}>",
"To" => [to.full_address],
- }
+ } unless AccountManager.is_account? to
+ @headers[:recipient] = {
+ "From" => "#{from.name} <#{from_email}>",
+ "To" => cc.map { |p| p.full_address },
+ } unless cc.empty? || @m.is_list_message?
+
@headers[:user] = {
"From" => "#{from.name} <#{from_email}>",
}
@headers[:all] = {
@@ -71,11 +78,18 @@
"References" => refs,
}.merge v
end
@type_labels = REPLY_TYPES.select { |t| @headers.member?(t) }
- @selected_type = @m.is_list_message? ? :list : :sender
+ @selected_type =
+ if @m.is_list_message?
+ :list
+ elsif @headers.member? :sender
+ :sender
+ else
+ :recipient
+ end
@body += sig_lines
regen_text
end
@@ -112,17 +126,16 @@
def handle_new_text new_header, new_body
@body = new_body
if new_header.size != header.size ||
header.any? { |k, v| new_header[k] != v }
- #raise "nhs: #{new_header.size} hs: #{header.size} new: #{new_header.inspect} old: #{header.inspect}"
@selected_type = :user
@headers[:user] = new_header
end
end
def regen_text
- @text = header_lines(@headers[@selected_type] - NON_EDITABLE_HEADERS) + [""] + @body
+ @text = header_lines(header - NON_EDITABLE_HEADERS) + [""] + body
end
def gen_references
(@m.refs + [@m.id]).map { |x| "<#{x}>" }.join(" ")
end