]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - lib/common/postfixadmin_plugin.rb
Get the MvRunner working, at least for Postfixadmin.
[mailshears.git] / lib / common / postfixadmin_plugin.rb
index 7a1985202cc343af0301518dc9a9e94abf03c799..97d59f267214060a7b9824d47338727e29b58b24 100644 (file)
@@ -17,9 +17,9 @@ module PostfixadminPlugin
   end
 
 
-  def describe_account(account)
+  def describe_user(user)
     # There's no other unique identifier in PostfixAdmin
-    return account
+    return user
   end
 
 
@@ -57,8 +57,17 @@ module PostfixadminPlugin
   end
 
 
+  def domain_exists(domain)
+    # Does the given domain exist in Postfixadmin? We use a naive
+    # implementation here based on list_domains(). This isn't in our
+    # superclass because not all plugins have a concept of domains.
+    domains = list_domains()
+    return domains.include?(domain)
+  end
+
+
   def list_users()
-    accounts = []
+    users = []
 
     # Just assume PostgreSQL for now.
     begin
@@ -70,11 +79,9 @@ module PostfixadminPlugin
                                   @db_user,
                                   @db_pass)
 
-      # 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')
+        users = result.field_values('username')
       end
       connection.close()
     rescue PGError => e
@@ -82,7 +89,7 @@ module PostfixadminPlugin
       raise DatabaseError.new(e)
     end
 
-    return accounts
+    return users
   end
 
 
@@ -114,4 +121,35 @@ module PostfixadminPlugin
     return usernames
   end
 
+
+  def list_aliases()
+    #
+    # Get a list of all aliases, useful for testing.
+    #
+    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)
+    end
+
+    return aliases
+  end
+
 end