X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=src%2Fpostfixadmin_db.rb;h=0249ea07949b384a5438f34c9c5f7c27e582d7e0;hp=e30c89c1bf982431043994602c0a2faa03dcd115;hb=8def8385214dc9095bd4dc5369b2f905d99b4b45;hpb=da71911046617ccffbb899b57162c5e6bdbb37ee diff --git a/src/postfixadmin_db.rb b/src/postfixadmin_db.rb index e30c89c..0249ea0 100644 --- a/src/postfixadmin_db.rb +++ b/src/postfixadmin_db.rb @@ -1,4 +1,4 @@ -require 'postgres' +require 'pg' class PostfixadminDb @@ -20,7 +20,37 @@ class PostfixadminDb end + def get_domains_from_db() + domains = [] + + # Just assume PostgreSQL for now. + begin + connection = PGconn.connect(@db_host, + @db_port, + @db_opts, + @db_tty, + @db_name, + @db_user, + @db_pass) + + # 'ALL' is a magic domain, and we don't want it. + sql_query = "SELECT domain FROM domain WHERE domain <> 'ALL';" + connection.query(sql_query) do |result| + domains = result.field_values('domain') + end + connection.close() + rescue PGError => e + # But pretend like we're database-agnostic in case we ever are. + raise DatabaseError.new(e) + end + + return domains + end + + def get_accounts_from_db() + accounts = [] + # Just assume PostgreSQL for now. begin connection = PGconn.connect(@db_host, @@ -30,16 +60,20 @@ class PostfixadminDb @db_name, @db_user, @db_pass) - - sql_query = 'SELECT address FROM alias;' - result = connection.query(sql_query) + + # If address = goto, then the alias basically says, "really + # deliver to that address; it's not an alias." + sql_query = 'SELECT username FROM mailbox;' + connection.query(sql_query) do |result| + accounts = result.field_values('username') + end connection.close() rescue PGError => e # But pretend like we're database-agnostic in case we ever are. raise DatabaseError.new(e) end - - return result + + return accounts end - + end