commit ef84454caff512230352ed901487ab020e715d19
parent 8f72f1c15baa9275d49c38fd328f4c8b40ca0907
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date: Mon, 11 Jun 2007 16:11:31 +0000
better address handling
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@444 5c8cc53c-5e98-4d25-b20a-d8db53a31250
Diffstat:
2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/lib/sup/account.rb b/lib/sup/account.rb
@@ -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 = a
+ @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
diff --git a/lib/sup/person.rb b/lib/sup/person.rb
@@ -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)