Pass a Configuration object to each plugin's initialize().
[mailshears.git] / lib / prune / prune_runner.rb
1 require 'common/runner'
2
3 # This is always needed, regardless of which plugin is running.
4 require 'prune/plugins/postfixadmin'
5
6 class PruneRunner
7 include Runner
8
9 def run(plugin)
10 # We don't want to check the PostfixAdmin database against itself.
11 return if plugin.class == PostfixadminPrune
12
13 cfg = Configuration.new()
14 pfa = PostfixadminPrune.new(cfg)
15
16 db_users = pfa.list_users()
17 db_domains = pfa.list_domains()
18
19 leftover_users = plugin.get_leftover_accounts(db_users)
20 leftover_domains = plugin.get_leftover_domains(db_domains)
21
22 leftover_users.each do |user|
23 user_description = plugin.describe_account(user)
24 plugin.delete_account(user)
25 report(plugin, "Removed user: #{user} (#{user_description})")
26 end
27
28 leftover_domains.each do |domain|
29 domain_description = plugin.describe_domain(domain)
30 plugin.delete_domain(domain)
31 report(plugin, "Removed domain: #{domain} (#{domain_description})")
32 end
33
34 end
35
36 end