]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - src/postfixadmin_db.rb
Added the get_domains_from_db() function to the PostfixadminDb class.
[mailshears.git] / src / postfixadmin_db.rb
index e30c89c1bf982431043994602c0a2faa03dcd115..f4e6feb5c999119535afff82f16ec9d9b83b51cb 100644 (file)
@@ -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
@@ -30,16 +56,21 @@ class PostfixadminDb
                                   @db_name,
                                   @db_user,
                                   @db_pass)
-      
-      sql_query = 'SELECT address FROM alias;'
+
+      # If address = goto, then the alias basically says, "really
+      # deliver to that address; it's not an alias."
+      sql_query = 'SELECT username FROM mailbox;'
       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
-    
-    return result
+
+    # The database query returns an array of rows. Since we only asked
+    # for one column (address), we can flatten the result into an
+    # array of addresses.
+    return result.flatten
   end
-  
+
 end