Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [sup-devel] Patch: Always try to canonize person name using ContactManager
@ 2011-01-24 23:33 Tero Tilus
  2010-02-10 21:04 ` [sup-devel] Person.from_address and Contacts (or John.Smith@example.com) Gregor Hoffleit
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Tero Tilus @ 2011-01-24 23:33 UTC (permalink / raw)
  To: Sup developers

[-- Attachment #1: Type: text/plain, Size: 406 bytes --]

Sup has mostly not been using the names defined in contacts.txt when
displaying messages.  I vaguely remember seeing an issue reported on
something similar to this.  I became annoyed enough and fixed it.

Now Person.from_address first tries to find the person using
ContactManager (if it is instantiated) and falls back to
Person.new(name, email).

-- 
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/

[-- Attachment #2: 0002-Always-try-to-canonize-person-name-using-ContactMana.patch --]
[-- Type: application/octet-stream, Size: 2418 bytes --]

From 188f4d21dc2d3a769ef9383204a041ee942271af Mon Sep 17 00:00:00 2001
From: Tero Tilus <tero@tilus.net>
Date: Tue, 25 Jan 2011 01:12:30 +0200
Subject: [PATCH] Always try to canonize person name using ContactManager

Signed-off-by: Tero Tilus <tero@tilus.net>
---
 lib/sup/contact.rb |   13 +++++++++----
 lib/sup/person.rb  |    4 +++-
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/lib/sup/contact.rb b/lib/sup/contact.rb
index c489aaf..382896d 100644
--- a/lib/sup/contact.rb
+++ b/lib/sup/contact.rb
@@ -12,14 +12,13 @@ class ContactManager
 
     @p2a = {} # person to alias
     @a2p = {} # alias to person
+    @e2p = {} # email to person
 
     if File.exists? fn
       IO.foreach(fn) do |l|
         l =~ /^([^:]*): (.*)$/ or raise "can't parse #{fn} line #{l.inspect}"
         aalias, addr = $1, $2
-        p = Person.from_address addr
-        @p2a[p] = aalias
-        @a2p[aalias] = p unless aalias.nil? || aalias.empty?
+        update_alias Person.from_address(addr), aalias
       end
     end
   end
@@ -30,9 +29,13 @@ class ContactManager
   def update_alias person, aalias=nil
     if(old_aalias = @p2a[person]) # remove old alias
       @a2p.delete old_aalias
+      @e2p.delete old_aalias.email
     end
     @p2a[person] = aalias
-    @a2p[aalias] = person unless aalias.nil? || aalias.empty?
+    unless aalias.nil? || aalias.empty?
+      @a2p[aalias] = person
+      @e2p[person.email] = person
+    end
   end
 
   ## this may not actually be called anywhere, since we still keep contacts
@@ -40,11 +43,13 @@ class ContactManager
   def drop_contact person
     aalias = @p2a[person]
     @p2a.delete person
+    @e2p.delete person.email
     @a2p.delete aalias if aalias
   end
 
   def contact_for aalias; @a2p[aalias] end
   def alias_for person; @p2a[person] end
+  def person_for email; @e2p[email] end
   def is_aliased_contact? person; !@p2a[person].nil? end
 
   def save
diff --git a/lib/sup/person.rb b/lib/sup/person.rb
index 28887b3..ad75906 100644
--- a/lib/sup/person.rb
+++ b/lib/sup/person.rb
@@ -100,7 +100,9 @@ class Person
         [nil, s]
       end
 
-    Person.new name, email
+    ## return "canonical" person using contact manager or self if not
+    ## found or contact manager not available
+    ContactManager.instantiated? && ContactManager.person_for(email) || Person.new(name, email)
   end
 
   def self.from_address_list ss
-- 
1.5.6.5


[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-06-20 22:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-24 23:33 [sup-devel] Patch: Always try to canonize person name using ContactManager Tero Tilus
2010-02-10 21:04 ` [sup-devel] Person.from_address and Contacts (or John.Smith@example.com) Gregor Hoffleit
2011-01-25 12:55   ` [sup-devel] Patch: Always try to canonize person name using ContactManager Gregor Hoffleit
2011-01-25 21:26     ` Tero Tilus
2011-01-25 18:29 ` Alvaro Herrera
2011-01-25 21:25   ` Tero Tilus
2011-06-20 22:43 ` Hamish Downer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox