]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - lib/rm/rm_runner.rb
Way too many changes to mention. The 'rm' mode works now.
[mailshears.git] / lib / rm / rm_runner.rb
index 5fe2eaf933bf7d073a200f23381718ac60529b31..0392d1192acbac86218c0813218e37b5b5c56929 100644 (file)
@@ -1,3 +1,5 @@
+require 'common/runner'
+
 class RmRunner
   include Runner
 
@@ -8,25 +10,39 @@ class RmRunner
         begin
           account_description = plugin.describe_account(target)
           plugin.delete_account(target)
-          puts "Removed account: #{target} (#{account_description})"
+          report(plugin, "Removed account: #{target} (#{account_description})")
+
+        rescue NonexistentAccountError => e
+          report(plugin, "Account not found: #{e.to_s}")
         rescue StandardError => e
-          puts "There was an error removing the account: #{e.to_s}"
+          report(plugin, "There was an error removing the account: #{e.to_s}")
           Kernel.exit(ExitCodes::DATABASE_ERROR)
         end
       else
         begin
-          # TODO: Delete all accounts first.
+          # We must delete all accounts belonging to the domain first.
+          # This prevents us from leaving behind accounts. Not a
+          # problem with the mailstore, since we'll delete the domain
+          # directory anyway, but it is for the database plugins.
+          usernames = plugin.get_domain_usernames(target)
+          usernames.each { |u| run(plugin, u) }
+
           domain_description = plugin.describe_domain(target)
           plugin.delete_domain(target)
-          puts "Removed domain: #{target} (#{domain_description})"
+          report(plugin, "Removed domain: #{target} (#{domain_description})")
+
+        rescue NonexistentAccountError => e
+          # Can happen in the usernames.each... block.
+          report(plugin, "Account not found: #{e.to_s}")
+        rescue NonexistentDomainError => e
+          report(plugin, "Domain not found: #{e.to_s}")
         rescue StandardError => e
-          puts "There was an error removing the domain: #{e.to_s}"
+          report(plugin, "There was an error removing the domain: #{e.to_s}")
           Kernel.exit(ExitCodes::DATABASE_ERROR)
         end
       end
     end
 
-    # TODO: remove from postfixadmin as well.
   end
 
 end