]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/roundcube_plugin.rb
1 require 'common/plugin'
4 # Code that all Roundcube plugins ({RoundcubePrune}, {RoundcubeRm},
5 # {RoundcubeMv}) share.
9 # We implement the Plugin "interface."
13 # Initialize this Roundcube {Plugin} with values in *cfg*.
15 # @param cfg [Configuration] the configuration for this plugin.
19 :host => cfg
.roundcube_dbhost
,
20 :port => cfg
.roundcube_dbport
,
21 :options => cfg
.roundcube_dbopts
,
22 :dbname => cfg
.roundcube_dbname
,
23 :user => cfg
.roundcube_dbuser
,
24 :password => cfg
.roundcube_dbpass
}
28 # Describe the given Roundcube *user*.
30 # @param user [User] the user whose description we want.
32 # @return [String] a string containing the Roundcube "User ID"
33 # associated with *user*.
35 def describe_user(user
)
36 user_id
= self.get_user_id(user
)
37 return "User ID: #{user_id}"
41 # Return a list of Roundcube users.
43 # @return [Array<User>] a list of users contained in the
49 connection
= PG
::Connection.new(@db_hash)
51 sql_query
= 'SELECT username FROM users;'
54 connection
.sync_exec(sql_query
) do |result
|
55 usernames
= result
.field_values('username')
58 # Make sure the connection gets closed even if the query explodes.
62 return usernames
.map
{ |u
| User
.new(u
) }
68 # Find the Roundcube "User ID" associated with the given *user*.
70 # @param user [User] the user whose Roundcube "User ID" we want.
72 # @return [Fixnum] the Roundcube "User ID" for *user*.
77 connection
= PG
::Connection.new(@db_hash)
78 sql_query
= 'SELECT user_id FROM users WHERE username = $1;'
81 connection
.sync_exec_params(sql_query
, [user
.to_s()]) do |result
|
82 if result
.num_tuples
> 0
83 user_id
= result
[0]['user_id']
87 # Make sure the connection gets closed even if the query explodes.