From ef84454caff512230352ed901487ab020e715d19 Mon Sep 17 00:00:00 2001 From: wmorgan Date: Mon, 11 Jun 2007 16:11:31 +0000 Subject: [PATCH] better address handling git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@444 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- lib/sup/account.rb | 30 +++++++++++++++--------------- lib/sup/person.rb | 4 ++++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/sup/account.rb b/lib/sup/account.rb index de54e5b..344572e 100644 --- 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 index 9c2d687..36f51fa 100644 --- 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) -- 2.45.2