]> git.cworth.org Git - sup/blobdiff - lib/sup/person.rb
add --search option to sup (thanks to Marcus Williams)
[sup] / lib / sup / person.rb
index 9c2d687eebceb7216a732b997ac18def45a6d928..ba2720562e459a39b9cae7c0586b3fafe67e5c5f 100644 (file)
@@ -20,6 +20,8 @@ class PersonManager
   def save
     File.open(@fn, "w") do |f|
       @@people.each do |email, p|
+        next if p.email == p.name
+        next if p.email =~ /=/ # drop rfc2047-encoded, and lots of other useless emails. definitely a heuristic.
         f.puts "#{p.email}: #{p.timestamp} #{p.name}"
       end
     end
@@ -33,6 +35,10 @@ class PersonManager
   def self.person_for s, opts={}
     p = Person.from_address(s) or return nil
     p.definitive = true if opts[:definitive]
+    register p
+  end
+  
+  def self.register p
     oldp = @@people[p.email]
 
     if oldp.nil? || p.better_than?(oldp)
@@ -110,7 +116,7 @@ class Person
 
   def full_address
     if @name && @email
-      if @name =~ /"/
+      if @name =~ /[",@]/
         "#{@name.inspect} <#@email>" # escape quotes
       else
         "#@name <#@email>"
@@ -155,6 +161,9 @@ class Person
 
     Person.new name, email
   end
+
+  def eql? o; email.eql? o.email end
+  def hash; email.hash end
 end
 
 end