]>
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_domain(domain
)
21 # Roundcube doesn't have a concept of domains.
25 def describe_user(user
)
26 user_id
= self.get_user_id(user
)
29 return 'User not found'
31 return "User ID: #{user_id}"
37 # Produce a list of Roundcube users. This is used in prune/rm, and
38 # is public because it is useful in testing.
41 # Just assume PostgreSQL for now.
43 connection
= PGconn
.connect(@db_host,
51 sql_query
= "SELECT username FROM users;"
52 connection
.query(sql_query
) do |result
|
53 usernames
= result
.field_values('username')
58 # Pretend like we're database-agnostic in case we ever are.
59 raise DatabaseError
.new(e
)
62 return usernames
.map
{ |u
| User
.new(u
) }
71 connection
= PGconn
.connect(@db_host,
79 sql_query
= "SELECT user_id FROM users WHERE username = $1;"
81 connection
.query(sql_query
, [user
.to_s()]) do |result
|
82 if result
.num_tuples
> 0
83 user_id
= result
[0]['user_id']
90 # Pretend like we're database-agnostic in case we ever are.
91 raise DatabaseError
.new(e
)