]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/roundcube_plugin.rb
1 require 'common/plugin'
5 # Code that all Roundcube plugins (Prune, Rm, Mv...) will share.
6 # That is, we implement the Plugin interface.
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_user(user
)
21 user_id
= self.get_user_id(user
)
22 return "User ID: #{user_id}"
27 # Produce a list of Roundcube users. This is used in prune/rm, and
28 # is public because it is useful in testing.
31 connection
= PGconn
.connect(@db_host, @db_port, @db_opts, @db_tty,
32 @db_name, @db_user, @db_pass)
34 sql_query
= 'SELECT username FROM users;'
35 connection
.query(sql_query
) do |result
|
36 usernames
= result
.field_values('username')
41 return usernames
.map
{ |u
| User
.new(u
) }
49 connection
= PGconn
.connect(@db_host, @db_port, @db_opts, @db_tty,
50 @db_name, @db_user, @db_pass)
52 sql_query
= 'SELECT user_id FROM users WHERE username = $1;'
54 connection
.query(sql_query
, [user
.to_s()]) do |result
|
55 if result
.num_tuples
> 0
56 user_id
= result
[0]['user_id']