lib/sup/modes/reply-mode.rb in sup-0.11 vs lib/sup/modes/reply-mode.rb in sup-0.12

- old
+ new

@@ -40,10 +40,11 @@ The reply mode you desire, or nil to use the default behavior. EOS def initialize message, type_arg=nil @m = message + @edited = false ## 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 @@ -62,22 +63,19 @@ ## determine the from address of a reply. ## if we have a value from a hook, use it. from = if hook_reply_from hook_reply_from - ## otherwise, if the original email had an envelope-to header, try and use - ## it, and look up the corresponding name form the list of accounts. - ## + ## otherwise, try and find an account somewhere in the list of to's + ## and cc's and look up the corresponding name form the list of accounts. + ## if this does not succeed use the recipient_email (=envelope-to) instead. ## this is for the case where mail is received from a mailing lists (so the ## To: is the list id itself). if the user subscribes via a particular ## alias, we want to use that alias in the reply. - elsif @m.recipient_email && (a = AccountManager.account_for(@m.recipient_email)) - Person.new a.name, @m.recipient_email - ## otherwise, try and find an account somewhere in the list of to's - ## and cc's. - elsif(b = (@m.to + @m.cc).find { |p| AccountManager.is_account? p }) - b + elsif(b = (@m.to.collect {|t| t.email} + @m.cc.collect {|c| c.email} + [@m.recipient_email] ).find { |p| AccountManager.is_account_email? p }) + a = AccountManager.account_for(b) + Person.new a.name, b ## if all else fails, use the default else AccountManager.default_account end @@ -148,32 +146,36 @@ :sender else :recipient end) + @bodies = {} @headers.each do |k, v| - HookManager.run "before-edit", :header => v, :body => body + @bodies[k] = body + HookManager.run "before-edit", :header => v, :body => @bodies[k] end - super :header => @headers[@type_selector.val], :body => body, :twiddles => false + super :header => @headers[@type_selector.val], :body => @bodies[@type_selector.val], :twiddles => false add_selector @type_selector end protected def move_cursor_right super if @headers[@type_selector.val] != self.header self.header = @headers[@type_selector.val] + self.body = @bodies[@type_selector.val] unless @edited update end end def move_cursor_left super if @headers[@type_selector.val] != self.header self.header = @headers[@type_selector.val] + self.body = @bodies[@type_selector.val] unless @edited update end end def reply_body_lines m @@ -186,9 +188,13 @@ def default_attribution m "Excerpts from #{@m.from.name}'s message of #{@m.date}:" end def handle_new_text new_header, new_body + if new_body != @bodies[@type_selector.val] + @bodies[@type_selector.val] = new_body + @edited = true + end old_header = @headers[@type_selector.val] if new_header.size != old_header.size || old_header.any? { |k, v| new_header[k] != v } @type_selector.set_to :user self.header = @headers[:user] = new_header update