Replace 'account' with 'user' everywhere.
[mailshears.git] / lib / prune / prune_runner.rb
index 0f1dfeb3832a70c7baf77b59d3b8d0bfbd493e07..7ea61919ca46981c4284c4744854355756f9e3be 100644 (file)
@@ -1,8 +1,36 @@
+require 'common/runner'
+
+# This is always needed, regardless of which plugin is running.
+require 'prune/plugins/postfixadmin'
+
 class PruneRunner
   include Runner
 
   def run(plugin)
-    puts "Not implemented"
+    # We don't want to check the PostfixAdmin database against itself.
+    return if plugin.class == PostfixadminPrune
+
+    cfg = Configuration.new()
+    pfa = PostfixadminPrune.new(cfg)
+
+    db_users = pfa.list_users()
+    db_domains = pfa.list_domains()
+
+    leftover_users = plugin.get_leftover_users(db_users)
+    leftover_domains = plugin.get_leftover_domains(db_domains)
+
+    leftover_users.each do |user|
+      user_description = plugin.describe_users(user)
+      plugin.delete_user(user)
+      report(plugin, "Removed user: #{user} (#{user_description})")
+    end
+
+    leftover_domains.each do |domain|
+      domain_description = plugin.describe_domain(domain)
+      plugin.delete_domain(domain)
+      report(plugin, "Removed domain: #{domain} (#{domain_description})")
+    end
+
   end
 
 end