X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fcommon%2Fpostfixadmin_plugin.rb;h=97d59f267214060a7b9824d47338727e29b58b24;hp=5556d5a7c23a15866a0a7fb17e6cbb77f2a21f1d;hb=a7905056b29b9e7b99bfb35b4b89bf0e56275597;hpb=72696d3f6e95ef773af9727e9c3459b9038b0fc2 diff --git a/lib/common/postfixadmin_plugin.rb b/lib/common/postfixadmin_plugin.rb index 5556d5a..97d59f2 100644 --- a/lib/common/postfixadmin_plugin.rb +++ b/lib/common/postfixadmin_plugin.rb @@ -57,6 +57,15 @@ 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() users = [] @@ -70,8 +79,6 @@ 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| users = result.field_values('username') @@ -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