]>
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 # Just assume PostgreSQL for now.
33 connection
= PGconn
.connect(@db_host,
41 sql_query
= "SELECT username FROM users;"
42 connection
.query(sql_query
) do |result
|
43 usernames
= result
.field_values('username')
48 # Pretend like we're database-agnostic in case we ever are.
49 raise DatabaseError
.new(e
)
52 return usernames
.map
{ |u
| User
.new(u
) }
61 connection
= PGconn
.connect(@db_host,
69 sql_query
= "SELECT user_id FROM users WHERE username = $1;"
71 connection
.query(sql_query
, [user
.to_s()]) do |result
|
72 if result
.num_tuples
> 0
73 user_id
= result
[0]['user_id']
80 # Pretend like we're database-agnostic in case we ever are.
81 raise DatabaseError
.new(e
)