Move domain removal into the plugins.
[mailshears.git] / lib / common / postfixadmin_db_plugin.rb
index 936672e27a331d60f1c05bead0fb14a96efb72e1..da40879ed07c03214cab62d2984d5a5da86b7cf6 100644 (file)
@@ -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