]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - lib/rm/rm_runner.rb
Overhaul everything to get consistent error reports.
[mailshears.git] / lib / rm / rm_runner.rb
index 0392d1192acbac86218c0813218e37b5b5c56929..2df8410c5ea9d6d3d65d2565ec9cc00552d7b1f0 100644 (file)
@@ -1,3 +1,4 @@
+require 'common/errors'
 require 'common/runner'
 
 class RmRunner
 require 'common/runner'
 
 class RmRunner
@@ -5,44 +6,32 @@ class RmRunner
 
   def run(plugin, *targets)
     targets.each do |target|
 
   def run(plugin, *targets)
     targets.each do |target|
-      # Why think too hard? An account has an @, a domain doesn't.
-      if target.include?('@') then
-        begin
-          account_description = plugin.describe_account(target)
-          plugin.delete_account(target)
-          report(plugin, "Removed account: #{target} (#{account_description})")
+      remove_target(plugin, target)
+    end
+  end
+
+  private;
 
 
-        rescue NonexistentAccountError => e
-          report(plugin, "Account not found: #{e.to_s}")
-        rescue StandardError => e
-          report(plugin, "There was an error removing the account: #{e.to_s}")
-          Kernel.exit(ExitCodes::DATABASE_ERROR)
-        end
-      else
-        begin
-          # 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) }
+  def remove_target(plugin, target)
+    # Wrap the "remove this thing" operation so that it can be reused
+    # in the prine plugin.
+    target_description = plugin.describe(target)
 
 
-          domain_description = plugin.describe_domain(target)
-          plugin.delete_domain(target)
-          report(plugin, "Removed domain: #{target} (#{domain_description})")
+    begin
+      plugin.delete(target)
+      msg =  "Removed #{target.class.to_s().downcase()} #{target}"
 
 
-        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
-          report(plugin, "There was an error removing the domain: #{e.to_s}")
-          Kernel.exit(ExitCodes::DATABASE_ERROR)
-        end
+      # Only append the extra description if it's useful.
+      if not target_description.nil? and
+         not target_description.empty? and
+         not target_description == target.to_s() then
+        msg += " (#{target_description})"
       end
       end
-    end
+      msg += '.'
 
 
+      report(plugin, msg)
+    rescue NonexistentDomainError, NonexistentUserError => e
+      report(plugin, "#{target.class.to_s()} #{e.to_s} not found.")
+    end
   end
   end
-
 end
 end