X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=src%2Fpostfixadmin_db.rb;h=f4e6feb5c999119535afff82f16ec9d9b83b51cb;hp=7998bfe677681638766b26a54275419b0a18d20f;hb=1fe2e9e56eaa02ce4301545d9998c7f36dd64d2e;hpb=7643bd3ebfe3d4aa8a56679c16e313ea9250f47e diff --git a/src/postfixadmin_db.rb b/src/postfixadmin_db.rb index 7998bfe..f4e6feb 100644 --- a/src/postfixadmin_db.rb +++ b/src/postfixadmin_db.rb @@ -20,6 +20,32 @@ class PostfixadminDb end + def get_domains_from_db() + # 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 domain FROM domain;' + result = connection.query(sql_query) + connection.close() + rescue PGError => e + # But pretend like we're database-agnostic in case we ever are. + raise DatabaseError.new(e) + end + + # The database query returns an array of rows. Since we only asked + # for one column (domain), we can flatten the result into an + # array of domains. + return result.flatten + end + + def get_accounts_from_db() # Just assume PostgreSQL for now. begin @@ -33,7 +59,7 @@ class PostfixadminDb # If address = goto, then the alias basically says, "really # deliver to that address; it's not an alias." - sql_query = 'SELECT address FROM alias WHERE address = goto;' + sql_query = 'SELECT username FROM mailbox;' result = connection.query(sql_query) connection.close() rescue PGError => e @@ -46,5 +72,5 @@ class PostfixadminDb # array of addresses. return result.flatten end - + end