]>
gitweb.michael.orlitzky.com - mailshears.git/blob - common/postfixadmin_plugin.rb
1 require 'common/plugin'
4 module PostfixadminPlugin
5 # Code that all Postfixadmin plugins (Prune, Rm, Mv...) will
6 # share. That is, we implement the Plugin interface.
10 @db_host = cfg
.postfixadmin_dbhost
11 @db_port = cfg
.postfixadmin_dbport
12 @db_opts = cfg
.postfixadmin_dbopts
13 @db_tty = cfg
.postfixadmin_dbtty
14 @db_name = cfg
.postfixadmin_dbname
15 @db_user = cfg
.postfixadmin_dbuser
16 @db_pass = cfg
.postfixadmin_dbpass
20 def describe_user(user
)
21 # There's no other unique identifier in PostfixAdmin
26 def describe_domain(domain
)
27 # There's no other unique identifier in PostfixAdmin
35 # Just assume PostgreSQL for now.
37 connection
= PGconn
.connect(@db_host,
45 # 'ALL' is a magic domain, and we don't want it.
46 sql_query
= "SELECT domain FROM domain WHERE domain <> 'ALL';"
47 connection
.query(sql_query
) do |result
|
48 domains
= result
.field_values('domain')
52 # But pretend like we're database-agnostic in case we ever are.
53 raise DatabaseError
.new(e
)
63 # Just assume PostgreSQL for now.
65 connection
= PGconn
.connect(@db_host,
73 # If address = goto, then the alias basically says, "really
74 # deliver to that address; it's not an alias."
75 sql_query
= 'SELECT username FROM mailbox;'
76 connection
.query(sql_query
) do |result
|
77 users
= result
.field_values('username')
81 # But pretend like we're database-agnostic in case we ever are.
82 raise DatabaseError
.new(e
)
89 def list_domains_users(domains
)
92 # Just assume PostgreSQL for now.
94 connection
= PGconn
.connect(@db_host,
102 sql_query
= 'SELECT username FROM mailbox WHERE domain IN $1;'
104 connection
.query(sql_query
, [domains
]) do |result
|
105 usernames
= result
.field_values('username')
110 # Pretend like we're database-agnostic in case we ever are.
111 raise DatabaseError
.new(e
)