Way too many changes to mention. The 'rm' mode works now.
[mailshears.git] / lib / common / roundcube_db_plugin.rb
index 364b8199e23f992c2a4744ac3ec76239a98b7714..e4e9e7fb73471d4115cd6694527a43bb139cc293 100644 (file)
@@ -65,4 +65,33 @@ module RoundcubeDbPlugin
     return user_id
   end
 
+
+  # Uses in both prune/rm.
+  def get_roundcube_usernames()
+    usernames = []
+
+    # Just assume PostgreSQL for now.
+    begin
+      connection = PGconn.connect(@db_host,
+                                  @db_port,
+                                  @db_opts,
+                                  @db_tty,
+                                  @db_name,
+                                  @db_user,
+                                  @db_pass)
+
+      sql_query = "SELECT username FROM users;"
+      connection.query(sql_query) do |result|
+        usernames = result.field_values('username')
+      end
+
+      connection.close()
+    rescue PGError => e
+      # Pretend like we're database-agnostic in case we ever are.
+      raise DatabaseError.new(e)
+    end
+
+    return usernames
+  end
+
 end