module RoundcubePlugin
Code that all Roundcube plugins ({RoundcubePrune}, {RoundcubeRm}, {RoundcubeMv}) share.
Public Class Methods
new(cfg)
click to toggle source
Initialize this Roundcube {Plugin} with values in cfg.
@param cfg [Configuration] the configuration for this plugin.
# File lib/common/roundcube_plugin.rb, line 17 def initialize(cfg) @db_hash = { :host => cfg.roundcube_dbhost, :port => cfg.roundcube_dbport, :options => cfg.roundcube_dbopts, :tty => cfg.roundcube_dbtty, :dbname => cfg.roundcube_dbname, :user => cfg.roundcube_dbuser, :password => cfg.roundcube_dbpass } end
Public Instance Methods
describe_user(user)
click to toggle source
Describe the given Roundcube user.
@param user [User] the user whose description we want.
@return [String] a string containing the Roundcube “User ID”
associated with *user*.
# File lib/common/roundcube_plugin.rb, line 36 def describe_user(user) user_id = self.get_user_id(user) return "User ID: #{user_id}" end
list_users()
click to toggle source
Return a list of Roundcube users.
@return [Array<User>] a list of users contained in the
Roundcube database.
# File lib/common/roundcube_plugin.rb, line 47 def list_users() usernames = [] connection = PG::Connection.new(@db_hash) sql_query = 'SELECT username FROM users;' begin connection.sync_exec(sql_query) do |result| usernames = result.field_values('username') end ensure # Make sure the connection gets closed even if the query explodes. connection.close() end return usernames.map{ |u| User.new(u) } end
Protected Instance Methods
get_user_id(user)
click to toggle source
Find the Roundcube “User ID” associated with the given user.
@param user [User] the user whose Roundcube “User ID” we want.
@return [Fixnum] the Roundcube “User ID” for user.
# File lib/common/roundcube_plugin.rb, line 75 def get_user_id(user) user_id = nil connection = PG::Connection.new(@db_hash) sql_query = 'SELECT user_id FROM users WHERE username = $1;' begin connection.sync_exec_params(sql_query, [user.to_s()]) do |result| if result.num_tuples > 0 user_id = result[0]['user_id'] end end ensure # Make sure the connection gets closed even if the query explodes. connection.close() end return user_id end