sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 4e23e13e705c02f9a341a04338b5b46994c01d24
parent ad657e383d6914c053b7cceff082c05c096d0245
Author: Dan Callaghan <djc@djc.id.au>
Date:   Sat, 11 Apr 2026 19:55:05 +1000

fix handling of contacts with no alias

This avoids showing empty parentheses (displaying an alias which is
empty string) after contacts' email addresses in ThreadViewMode.

Diffstat:
M lib/sup/contact.rb | 7 +++----
M test/fixtures/contacts.txt | 4 ++--
M test/unit/test_contact.rb | 18 +++++++++++++++---
3 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/lib/sup/contact.rb b/lib/sup/contact.rb
@@ -20,6 +20,7 @@ class ContactManager
       IO.foreach(fn) do |l|
         l =~ /^([^:]*): (.*)$/ or raise "can't parse #{fn} line #{l.inspect}"
         aalias, addr = $1, $2
+        aalias = nil if aalias.empty?
         update_alias Person.from_address(addr), aalias
       end
     end
@@ -37,10 +38,8 @@ class ContactManager
     end
     ## Update with new data
     @p2a[person] = aalias
-    unless aalias.nil? || aalias.empty?
-      @a2p[aalias] = person
-      @e2p[person.email] = person
-    end
+    @a2p[aalias] = person unless aalias.nil?
+    @e2p[person.email] = person
   end
 
   ## this may not actually be called anywhere, since we still keep contacts
diff --git a/test/fixtures/contacts.txt b/test/fixtures/contacts.txt
@@ -1 +1,2 @@
-RC: Random Contact <random_dude@gmail.com>
-\ No newline at end of file
+RC: Random Contact <random_dude@gmail.com>
+: Unaliased Contact <unaliased@example.invalid>
diff --git a/test/unit/test_contact.rb b/test/unit/test_contact.rb
@@ -1,4 +1,5 @@
 require 'test_helper'
+require 'sup'
 require 'sup/contact'
 
 module Redwood
@@ -16,9 +17,20 @@ class TestContact < Minitest::Test
 
   def test_contact_manager
     assert @contact
-    ## 1 contact is imported from the fixture file.
-    assert_equal 1, @contact.contacts.count
-    assert_equal @contact.contact_for("RC").name, "Random Contact"
+
+    ## 2 contacts are imported from the fixture file.
+    assert_equal 2, @contact.contacts.count
+
+    rc = @contact.contact_for "RC"
+    assert_equal "Random Contact", rc.name
+    assert @contact.is_aliased_contact? rc
+    assert_equal "RC", @contact.alias_for(rc)
+
+    uc = @contact.person_for "unaliased@example.invalid"
+    refute @contact.is_aliased_contact? uc
+    assert_nil @contact.alias_for uc
+    assert_equal [rc, uc], @contact.contacts
+    assert_equal [rc], @contact.contacts_with_aliases
 
     assert_nil @contact.contact_for "TN"
     @contact.update_alias @person, "TN"