]> git.cworth.org Git - sup/commitdiff
better address handling
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Mon, 11 Jun 2007 16:11:31 +0000 (16:11 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Mon, 11 Jun 2007 16:11:31 +0000 (16:11 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@444 5c8cc53c-5e98-4d25-b20a-d8db53a31250

lib/sup/account.rb
lib/sup/person.rb

index de54e5bd451d77f5d435da4ad2c12ab5ddc02477..344572e9c0eef86759f57c10a0b953fefe168799 100644 (file)
@@ -3,8 +3,8 @@ module Redwood
 class Account < Person
   attr_accessor :sendmail, :sig_file
 
-  def initialize h
-    super h[:name], h[:email]
+  def initialize email, h
+    super h[:name], email, 0, true
     @sendmail = h[:sendmail]
     @sig_file = h[:signature]
   end
@@ -17,7 +17,6 @@ class AccountManager
 
   def initialize accounts
     @email_map = {}
-    @alternate_map = {}
     @accounts = {}
     @default_account = nil
 
@@ -30,24 +29,25 @@ class AccountManager
   def user_emails; (@email_map.keys + @alternate_map.keys).uniq.select { |e| String === e }; end
 
   def add_account hash, default=false
-    email = hash[:email]
+    main_email = hash[:email]
+
+    ([hash[:email]] + (hash[:alternates] || [])).each do |email|
+      next if @email_map.member? email
+      a = Account.new email, hash
+      PersonManager.register a
+      @accounts[a] = true
+      @email_map[email] = a
+    end
 
-    next if @email_map.member? email
-    a = Account.new hash
-    @accounts[a] = true
-    @email_map[email] = a
-    hash[:alternates].each { |aa| @alternate_map[aa] = a } if hash[:alternates]
     if default
       raise ArgumentError, "multiple default accounts" if @default_account
-      @default_account = 
+      @default_account = @email_map[main_email]
     end
   end
 
-  def is_account? p; @email_map.member?(p.email); end
-  def account_for email
-    @email_map[email] || @alternate_map[email] || @alternate_map.argfind { |k, v| k === email && v }
-  end
-  def is_account_email? email; !account_for(email).nil?; end
+  def is_account? p; is_account_email? p.email end
+  def account_for email; @email_map[email] end
+  def is_account_email? email; !account_for(email).nil? end
 end
 
 end
index 9c2d687eebceb7216a732b997ac18def45a6d928..36f51faf9269e07fe1ee60d42dc3fd4a26d23d84 100644 (file)
@@ -33,6 +33,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)