* [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
* [sup-devel] Person.from_address and Contacts (or John.Smith@example.com) @ 2010-02-10 21:04 ` Gregor Hoffleit 2011-01-25 12:55 ` [sup-devel] Patch: Always try to canonize person name using ContactManager Gregor Hoffleit 0 siblings, 1 reply; 7+ messages in thread From: Gregor Hoffleit @ 2010-02-10 21:04 UTC (permalink / raw) To: sup-devel I have quite a few contacts that send their mails without a display name, i.e. something like "From: John.Smith@example.com". Sup does some magic (in Person.from_address) to derive something like a display name from the local-part of the e-mail address. That's fine so far. But, if the person is in my list of contacts, I want Sup to show the display name definied in the contacts entry. In the above case, that might be "John Smith" or "John E. Smith" or whatever. Instead, Sup sticks to the display name derived from the local part, "john.smith". It's especially odd in the detailed header view of the thread-view-mode, where Sup resolves and shows the alias, but still sticks to the derived display name: From: john.smith <john.smith@example.com> (Johnny Boy) The obvious place to start a fix would be Person.from_address, where the (display) name, if missing, is derived from the email address. I wanted to modify Person.from_address in order to use, in the case of an empty display name, the ContactManager, to look up any alias in the contact list, but somehow I didn't succeed integrating ContactManager in person.rb. Any better idea? Should I file a bug about this? Regards, Gregor Hoffleit _______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [sup-devel] Patch: Always try to canonize person name using ContactManager 2010-02-10 21:04 ` [sup-devel] Person.from_address and Contacts (or John.Smith@example.com) Gregor Hoffleit @ 2011-01-25 12:55 ` Gregor Hoffleit 2011-01-25 21:26 ` Tero Tilus 0 siblings, 1 reply; 7+ messages in thread From: Gregor Hoffleit @ 2011-01-25 12:55 UTC (permalink / raw) To: sup-devel * Tero Tilus <tero@tilus.net> [Di Jan 25 00:33:23 +0100 2011] > 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). I guess you saw my report in <1265828498-sup-6054@sam.mediasupervision.de>: * Gregor Hoffleit <gregor@hoffleit.de> [Mi Feb 10 22:04:57 +0100 2010] > I have quite a few contacts that send their mails without a display > name, i.e. something like "From: John.Smith@example.com". > > Sup does some magic (in Person.from_address) to derive something like a > display name from the local-part of the e-mail address. That's fine so > far. > > But, if the person is in my list of contacts, I want Sup to show the > display name definied in the contacts entry. In the above case, that > might be "John Smith" or "John E. Smith" or whatever. Instead, Sup > sticks to the display name derived from the local part, "john.smith". > > It's especially odd in the detailed header view of the thread-view-mode, > where Sup resolves and shows the alias, but still sticks to the derived > display name: > > From: john.smith <john.smith@example.com> (Johnny Boy) > > > The obvious place to start a fix would be Person.from_address, where > the (display) name, if missing, is derived from the email address. > > I wanted to modify Person.from_address in order to use, in the case of > an empty display name, the ContactManager, to look up any alias in the > contact list, but somehow I didn't succeed integrating ContactManager > in person.rb. > > Any better idea? Should I file a bug about this? Regards, Gregor Hoffleit _______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [sup-devel] Patch: Always try to canonize person name using ContactManager 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 0 siblings, 0 replies; 7+ messages in thread From: Tero Tilus @ 2011-01-25 21:26 UTC (permalink / raw) To: Sup developers Gregor Hoffleit, 2011-01-25 14:55: > I guess you saw my report in <1265828498-sup-6054@sam.mediasupervision.de> See! I wasn't dreaming. ;) -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ _______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [sup-devel] Patch: Always try to canonize person name using ContactManager 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 18:29 ` Alvaro Herrera 2011-01-25 21:25 ` Tero Tilus 2011-06-20 22:43 ` Hamish Downer 2 siblings, 1 reply; 7+ messages in thread From: Alvaro Herrera @ 2011-01-25 18:29 UTC (permalink / raw) To: sup-devel Excerpts from Tero Tilus's message of lun ene 24 20:33:23 -0300 2011: > 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). I tried this patch -- works great, thanks. One minor nit, probably material for another patch: the list of names that's built in the thread index mode doesn't seem to use this facility, and so when you have a thread that includes several emails from the same account but inconsistent names, that person is listed more than once in the "participants" column, with the different names. (For example I have a thread from Fabian, Fabián, and fabian.martinez that all come from the same fabian.martinez@example.com account). -- Álvaro Herrera -- Se vende casa en Ñuñoa: www.portalinmobiliario.com/993147 _______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [sup-devel] Patch: Always try to canonize person name using ContactManager 2011-01-25 18:29 ` Alvaro Herrera @ 2011-01-25 21:25 ` Tero Tilus 0 siblings, 0 replies; 7+ messages in thread From: Tero Tilus @ 2011-01-25 21:25 UTC (permalink / raw) To: Sup developers [-- Attachment #1: Type: text/plain, Size: 997 bytes --] Alvaro Herrera, 2011-01-25 20:29: > One minor nit, probably material for another patch: the list of > names that's built in the thread index mode doesn't seem to use this > facility When message was built from index it bypassed person canonization. Amended patch attached. > and so when you have a thread that includes several emails from the > same account but inconsistent names, that person is listed more than > once in the "participants" column, with the different names. > > (For example I have a thread from Fabian, Fabián, and > fabian.martinez that all come from the same > fabian.martinez@example.com account). Actually, this was completely independent of the person canonization feature. Thread index mode, when constructing the from-list, identified authors by name, not by email. The people not in contacts.txt and appearing in from fields with varying names were listed several times. Attached patch also fixes this. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ [-- Attachment #2: 0002-Always-try-to-canonize-person-using-ContactManager.patch --] [-- Type: application/octet-stream, Size: 4177 bytes --] From b6afc55cd0539a38ef16b62c206181ef297c98df 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 using ContactManager Signed-off-by: Tero Tilus <tero@tilus.net> --- lib/sup/contact.rb | 13 +++++++++---- lib/sup/index.rb | 6 ++++-- lib/sup/modes/thread-index-mode.rb | 4 ++-- lib/sup/person.rb | 8 +++++++- 4 files changed, 22 insertions(+), 9 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/index.rb b/lib/sup/index.rb index bcc449b..95f104a 100644 --- a/lib/sup/index.rb +++ b/lib/sup/index.rb @@ -210,7 +210,9 @@ EOS :labels => entry[:labels], :snippet => entry[:snippet] - mk_person = lambda { |x| Person.new(*x.reverse!) } + # Try to find person from contacts before falling back to + # generating it from the address. + mk_person = lambda { |x| Person.from_name_and_email(*x.reverse!) } entry[:from] = mk_person[entry[:from]] entry[:to].map!(&mk_person) entry[:cc].map!(&mk_person) @@ -235,7 +237,7 @@ EOS m = b.call ([m.from]+m.to+m.cc+m.bcc).compact.each { |p| contacts << [p.name, p.email] } end - contacts.to_a.compact.map { |n,e| Person.new n, e }[0...num] + contacts.to_a.compact[0...num].map { |n,e| Person.from_name_and_email n, e } end ## Yield each message-id matching query diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb index 11548c7..040dfa5 100644 --- a/lib/sup/modes/thread-index-mode.rb +++ b/lib/sup/modes/thread-index-mode.rb @@ -792,8 +792,8 @@ protected authors = t.map do |m, *o| next unless m && m.from new[m.from] ||= m.has_label?(:unread) - next if seen[m.from.mediumname] - seen[m.from.mediumname] = true + next if seen[m.from] + seen[m.from] = true m.from end.compact diff --git a/lib/sup/person.rb b/lib/sup/person.rb index 28887b3..41a9a90 100644 --- a/lib/sup/person.rb +++ b/lib/sup/person.rb @@ -71,6 +71,12 @@ class Person end.downcase end + ## return "canonical" person using contact manager or create one if + ## not found or contact manager not available + def self.from_name_and_email name, email + ContactManager.instantiated? && ContactManager.person_for(email) || Person.new(name, email) + end + def self.from_address s return nil if s.nil? @@ -100,7 +106,7 @@ class Person [nil, s] end - Person.new name, email + from_name_and_email 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
* Re: [sup-devel] Patch: Always try to canonize person name using ContactManager 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 18:29 ` Alvaro Herrera @ 2011-06-20 22:43 ` Hamish Downer 2 siblings, 0 replies; 7+ messages in thread From: Hamish Downer @ 2011-06-20 22:43 UTC (permalink / raw) To: sup-devel Excerpts from Tero Tilus's message of Mon Jan 24 23:33:23 +0000 2011: > 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). In my search for old patches that have never been applied I came across this one. Now applied to next. Hamish -- Hamish Downer <hamish@foobacca.co.uk> Web: http://www.foobacca.co.uk/ GPG: B7C48416 _______________________________________________ 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