sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit bf56b543cc664c40c3695e287ee8e7e924f2d0d1
parent 4eaef3e76dfddd2a0792a89ddb5bb2dae3af6b40
Author: Hamish Downer <dmishd@gmail.com>
Date:   Mon, 30 May 2011 18:21:07 +0100

Change account_selector so it works with alternate email addresses.

Diffstat:
M lib/sup/account.rb | 4 ++++
M lib/sup/modes/edit-message-mode.rb | 12 ++++++++----
M lib/sup/person.rb | 14 +++++++++-----
3 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/lib/sup/account.rb b/lib/sup/account.rb
@@ -80,6 +80,10 @@ class AccountManager
       @regexen.argfind { |re, a| re =~ email && a }
     end
   end
+  def full_address_for email
+    a = account_for email
+    Person.full_address a.name, email
+  end
 end
 
 end
diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
@@ -114,6 +114,7 @@ EOS
     @selectors = []
     @selector_label_width = 0
 
+    # only show account selector if there is more than one account
     if $config[:account_selector]
       ## Duplicate e-mail strings to prevent a "can't modify frozen
       ## object" crash triggered by the String::display_length()
@@ -122,10 +123,10 @@ EOS
       AccountManager.user_emails.each { |e| user_emails_copy.push e.dup }
 
       @account_selector =
-        HorizontalSelector.new "Account:", AccountManager.user_accounts + [nil], user_emails_copy + ["Customized"]
+        HorizontalSelector.new "Account:", AccountManager.user_emails + [nil], user_emails_copy + ["Customized"]
 
       if @header["From"] =~ /<?(\S+@(\S+?))>?$/
-        @account_selector.set_to AccountManager.account_for($1)
+        @account_selector.set_to $1
         @account_user = ""
       else
         @account_selector.set_to nil
@@ -294,8 +295,11 @@ protected
 
   def update
     if @account_selector
-      account = @account_selector.val
-      @header["From"] = account && account.full_address || @account_user
+      if @account_selector.val.nil?
+        @header["From"] = @account_user
+      else
+        @header["From"] = AccountManager.full_address_for @account_selector.val
+      end
     end
 
     regen_text
diff --git a/lib/sup/person.rb b/lib/sup/person.rb
@@ -43,18 +43,22 @@ class Person
 
   def mediumname; @name || @email; end
 
-  def full_address
-    if @name && @email
-      if @name =~ /[",@]/
-        "#{@name.inspect} <#{@email}>" # escape quotes
+  def Person.full_address name, email
+    if name && email
+      if name =~ /[",@]/
+        "#{name.inspect} <#{email}>" # escape quotes
       else
-        "#{@name} <#{@email}>"
+        "#{name} <#{email}>"
       end
     else
       email
     end
   end
 
+  def full_address
+    Person.full_address @name, @email
+  end
+
   ## when sorting addresses, sort by this
   def sort_by_me
     case @name