]>
gitweb.michael.orlitzky.com - mailshears.git/blob - roundcube_db_plugin.rb
df5413fdb0cc7a797dc2fd1f7070f3809b7f2abc
1 require 'common/plugin'
3 module RoundcubeDbPlugin
4 # Code that all RoundcubeDb plugins (Prune, Rm, Mv...) will share.
5 # That is, we implement the Plugin interface.
9 cfg
= Configuration
.new()
10 @db_host = cfg
.roundcube_dbhost
11 @db_port = cfg
.roundcube_dbport
12 @db_opts = cfg
.roundcube_dbopts
13 @db_tty = cfg
.roundcube_dbtty
14 @db_name = cfg
.roundcube_dbname
15 @db_user = cfg
.roundcube_dbuser
16 @db_pass = cfg
.roundcube_dbpass
20 def describe_domain(domain
)
21 # Roundcube doesn't have a concept of domains.
25 def describe_account(account
)
26 user_id
= self.get_user_id(account
)
29 return 'User not found'
31 return "User ID: #{user_id}"
38 def get_user_id(account
)
42 connection
= PGconn
.connect(@db_host,
50 sql_query
= "SELECT user_id FROM users WHERE username = $1;"
52 connection
.query(sql_query
, [account
]) do |result
|
53 if result
.num_tuples
> 0
54 user_id
= result
[0]['user_id']
61 # Pretend like we're database-agnostic in case we ever are.
62 raise DatabaseError
.new(e
)
69 # Used in both prune/rm.
73 # Just assume PostgreSQL for now.
75 connection
= PGconn
.connect(@db_host,
83 sql_query
= "SELECT username FROM users;"
84 connection
.query(sql_query
) do |result
|
85 usernames
= result
.field_values('username')
90 # Pretend like we're database-agnostic in case we ever are.
91 raise DatabaseError
.new(e
)