]>
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 :tty => cfg
.roundcube_dbtty
,
23 :dbname => cfg
.roundcube_dbname
,
24 :user => cfg
.roundcube_dbuser
,
25 :password => cfg
.roundcube_dbpass
}
29 # Describe the given Roundcube *user*.
31 # @param user [User] the user whose description we want.
33 # @return [String] a string containing the Roundcube "User ID"
34 # associated with *user*.
36 def describe_user(user
)
37 user_id
= self.get_user_id(user
)
38 return "User ID: #{user_id}"
42 # Return a list of Roundcube users.
44 # @return [Array<User>] a list of users contained in the
50 connection
= PG
::Connection.connect(@db_hash)
52 sql_query
= 'SELECT username FROM users;'
55 connection
.query(sql_query
) do |result
|
56 usernames
= result
.field_values('username')
59 # Make sure the connection gets closed even if the query explodes.
63 return usernames
.map
{ |u
| User
.new(u
) }
69 # Find the Roundcube "User ID" associated with the given *user*.
71 # @param user [User] the user whose Roundcube "User ID" we want.
73 # @return [Fixnum] the Roundcube "User ID" for *user*.
78 connection
= PG
::Connection.new(@db_hash)
79 sql_query
= 'SELECT user_id FROM users WHERE username = $1;'
82 connection
.query(sql_query
, [user
.to_s()]) do |result
|
83 if result
.num_tuples
> 0
84 user_id
= result
[0]['user_id']
88 # Make sure the connection gets closed even if the query explodes.