]> git.notmuchmail.org Git - sup/commitdiff
add a :regexen section of an account in config.yaml for email regexes
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Sun, 6 Jan 2008 19:25:03 +0000 (11:25 -0800)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Sun, 6 Jan 2008 19:25:03 +0000 (11:25 -0800)
lib/sup/account.rb

index 6fa63a7ded2b461885b250f27dcae0ee967c0759..f8ac0fcaf672ace7e2b72e4e666e2b56d7c6fc19 100644 (file)
@@ -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