]> git.cworth.org Git - sup/blobdiff - lib/sup/account.rb
Merge commit 'bwalton/bw/flexible_sent' into next
[sup] / lib / sup / account.rb
index 6fa63a7ded2b461885b250f27dcae0ee967c0759..6f86129ca5d8997b0572f38512ba84a691ee4a7c 100644 (file)
@@ -5,8 +5,8 @@ class Account < Person
 
   def initialize h
     raise ArgumentError, "no name for account" unless h[:name]
-    raise ArgumentError, "no name for email" unless h[:name]
-    super h[:name], h[:email], 0, true
+    raise ArgumentError, "no email for account" unless h[:email]
+    super h[:name], h[:email]
     @sendmail = h[:sendmail]
     @signature = h[:signature]
   end
@@ -20,6 +20,7 @@ class AccountManager
   def initialize accounts
     @email_map = {}
     @accounts = {}
+    @regexen = {}
     @default_account = nil
 
     add_account accounts[:default], true
@@ -41,7 +42,6 @@ class AccountManager
     hash[:alternates] ||= []
 
     a = Account.new hash
-    PersonManager.register a
     @accounts[a] = true
 
     if default
@@ -53,11 +53,21 @@ class AccountManager
       next if @email_map.member? email
       @email_map[email] = a
     end
+
+    hash[:regexen].each do |re|
+      @regexen[Regexp.new(re)] = a
+    end if hash[:regexen]
   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
+  def account_for email
+    if(a = @email_map[email])
+      a
+    else
+      @regexen.argfind { |re, a| re =~ email && a }
+    end
+  end
 end
 
 end