Stop pretending that we'll ever work with another DBMS.
[mailshears.git] / lib / common / postfixadmin_plugin.rb
index b984f6cf66a5b2e5d66155124577f8c6a2c6eaef..3a5494bced822593e7a63f7a65c4422a02f3fb75 100644 (file)
@@ -22,27 +22,17 @@ module PostfixadminPlugin
   def list_domains()
     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)
+    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()
+
     return domains.map{ |d| Domain.new(d) }
   end
 
@@ -51,26 +41,16 @@ module PostfixadminPlugin
   def list_users()
     users = []
 
-    # 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;'
-      connection.query(sql_query) do |result|
-        users = 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)
+    connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
+                                @db_name, @db_user, @db_pass)
+
+    sql_query = 'SELECT username FROM mailbox;'
+    connection.query(sql_query) do |result|
+      users = result.field_values('username')
     end
 
+    connection.close()
+
     return users.map{ |u| User.new(u) }
   end
 
@@ -78,28 +58,17 @@ module PostfixadminPlugin
   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.map{|d| d.to_s()}) 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)
+    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.map{|d| d.to_s()}) do |result|
+      usernames = result.field_values('username')
     end
 
+    connection.close()
+
     return usernames.map{ |u| User.new(u) }
   end
 
@@ -110,27 +79,17 @@ module PostfixadminPlugin
     #
     aliases = []
 
-    # 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 address,goto FROM alias;'
-      results = connection.query(sql_query)
-      results.each do |row|
-        aliases << row # row should be a hash
-      end
-      connection.close()
-    rescue PGError => e
-      # But pretend like we're database-agnostic in case we ever are.
-      raise DatabaseError.new(e)
+    connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
+                                @db_name, @db_user, @db_pass)
+
+    sql_query = 'SELECT address,goto FROM alias;'
+    results = connection.query(sql_query)
+    results.each do |row|
+      aliases << row # row should be a hash
     end
 
+    connection.close()
+
     return aliases
   end