X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fcommon%2Fpostfixadmin_db_plugin.rb;h=da40879ed07c03214cab62d2984d5a5da86b7cf6;hp=936672e27a331d60f1c05bead0fb14a96efb72e1;hb=483d14dc8228a81d12fb109d3ed6510e2d2b03c1;hpb=e7fa62fc599b7583102fe48fbaad3db4f911a6da;ds=sidebyside diff --git a/lib/common/postfixadmin_db_plugin.rb b/lib/common/postfixadmin_db_plugin.rb index 936672e..da40879 100644 --- a/lib/common/postfixadmin_db_plugin.rb +++ b/lib/common/postfixadmin_db_plugin.rb @@ -31,7 +31,7 @@ module PostfixadminDbPlugin end - def get_domains_from_db() + def list_domains() domains = [] # Just assume PostgreSQL for now. @@ -59,7 +59,7 @@ module PostfixadminDbPlugin end - def get_accounts_from_db() + def list_users() accounts = [] # Just assume PostgreSQL for now. @@ -88,4 +88,32 @@ module PostfixadminDbPlugin end + def list_domains_users(domains) + usernames = [] + + # Just assume PostgreSQL for now. + begin + connection = PGconn.connect(@db_host, + @db_port, + @db_opts, + @db_tty, + @db_name, + @db_user, + @db_pass) + + sql_query = 'SELECT username FROM mailbox WHERE domain IN $1;' + + connection.query(sql_query, [domains]) do |result| + usernames = result.field_values('username') + end + + connection.close() + rescue PGError => e + # Pretend like we're database-agnostic in case we ever are. + raise DatabaseError.new(e) + end + + return usernames + end + end