]>
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.
18 @db_host = cfg
.roundcube_dbhost
19 @db_port = cfg
.roundcube_dbport
20 @db_opts = cfg
.roundcube_dbopts
21 @db_tty = cfg
.roundcube_dbtty
22 @db_name = cfg
.roundcube_dbname
23 @db_user = cfg
.roundcube_dbuser
24 @db_pass = 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
= PGconn
.connect(@db_host, @db_port, @db_opts, @db_tty,
50 @db_name, @db_user, @db_pass)
52 sql_query
= 'SELECT username FROM users;'
53 connection
.query(sql_query
) do |result
|
54 usernames
= result
.field_values('username')
59 return usernames
.map
{ |u
| User
.new(u
) }
65 # Find the Roundcube "User ID" associated with the given *user*.
67 # @param user [User] the user whose Roundcube "User ID" we want.
69 # @return [Fixnum] the Roundcube "User ID" for *user*.
74 connection
= PGconn
.connect(@db_host, @db_port, @db_opts, @db_tty,
75 @db_name, @db_user, @db_pass)
77 sql_query
= 'SELECT user_id FROM users WHERE username = $1;'
79 connection
.query(sql_query
, [user
.to_s()]) do |result
|
80 if result
.num_tuples
> 0
81 user_id
= result
[0]['user_id']