From: Tero Tilus <tero@tilus.net>
To: Sup developers <sup-devel@rubyforge.org>
Subject: [sup-devel] Patch: Always try to canonize person name using ContactManager
Date: Tue, 25 Jan 2011 01:33:23 +0200 [thread overview]
Message-ID: <1295911516-sup-1253@tilus.net> (raw)
[-- 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
next reply other threads:[~2011-01-24 23:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-24 23:33 Tero Tilus [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1295911516-sup-1253@tilus.net \
--to=tero@tilus.net \
--cc=sup-devel@rubyforge.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox