sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit feeee41cf0d4dae0a2e01fe117cbef9bcff63560
parent 153bfef0c47686dd8d01093cc12a1c65cc799182
Author: Gaudenz Steinlin <gaudenz@soziologie.ch>
Date:   Thu,  7 Oct 2010 05:05:30 -0400

prefer To and Cc adresses of accounts on reply

Resending this on Rich's request.

If a message was sent (To or Cc header) to an address which corresponds
to an account prefer this account over the account corresponding to the
address in recipient_email.

This solves the problem that the wrong reply from address is chosen on
mails which are sent to an account which is forwarded to another account.

Diffstat:
M lib/sup/modes/reply-mode.rb | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/lib/sup/modes/reply-mode.rb b/lib/sup/modes/reply-mode.rb
@@ -65,18 +65,15 @@ EOS
     ## 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