]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/roundcube_plugin.rb
1f9805a3e9d079243da75859f6992d7688e6f266
1 require 'common/plugin'
4 # Code that all Roundcube plugins (Prune, Rm, Mv...) will share.
5 # That is, we implement the Plugin interface.
9 @db_host = cfg
.roundcube_dbhost
10 @db_port = cfg
.roundcube_dbport
11 @db_opts = cfg
.roundcube_dbopts
12 @db_tty = cfg
.roundcube_dbtty
13 @db_name = cfg
.roundcube_dbname
14 @db_user = cfg
.roundcube_dbuser
15 @db_pass = cfg
.roundcube_dbpass
19 def describe_domain(domain
)
20 # Roundcube doesn't have a concept of domains.
24 def describe_user(user
)
25 user_id
= self.get_user_id(user
)
28 return 'User not found'
30 return "User ID: #{user_id}"
36 # Produce a list of Roundcube users. This is used in prune/rm, and
37 # is public because it is useful in testing.
40 # Just assume PostgreSQL for now.
42 connection
= PGconn
.connect(@db_host,
50 sql_query
= "SELECT username FROM users;"
51 connection
.query(sql_query
) do |result
|
52 usernames
= result
.field_values('username')
57 # Pretend like we're database-agnostic in case we ever are.
58 raise DatabaseError
.new(e
)
70 connection
= PGconn
.connect(@db_host,
78 sql_query
= "SELECT user_id FROM users WHERE username = $1;"
80 connection
.query(sql_query
, [user
]) do |result
|
81 if result
.num_tuples
> 0
82 user_id
= result
[0]['user_id']
89 # Pretend like we're database-agnostic in case we ever are.
90 raise DatabaseError
.new(e
)