From: William Morgan Date: Sun, 6 Jan 2008 19:25:03 +0000 (-0800) Subject: add a :regexen section of an account in config.yaml for email regexes X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=5e241b83742edc33af69157a38f6326d0305df18;p=sup add a :regexen section of an account in config.yaml for email regexes --- diff --git a/lib/sup/account.rb b/lib/sup/account.rb index 6fa63a7..f8ac0fc 100644 --- a/lib/sup/account.rb +++ b/lib/sup/account.rb @@ -20,6 +20,7 @@ class AccountManager def initialize accounts @email_map = {} @accounts = {} + @regexen = {} @default_account = nil add_account accounts[:default], true @@ -53,11 +54,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