]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - lib/rm/plugins/dovecot.rb
Wrap all close() calls in "ensure" blocks and simplify DB connection-making.
[mailshears.git] / lib / rm / plugins / dovecot.rb
index 4283e9c2267f9b0088febcd4d5b45ea423ddb660..7babfbeb40d353f212459f0a040da3c9d0d6f8bb 100644 (file)
@@ -1,25 +1,48 @@
-# Needed for rm_r.
 require 'fileutils'
 
 require 'common/dovecot_plugin'
 require 'rm/rm_plugin'
 
+
+# Handle the removal of users and domains from the Dovecot mailstore
+# (the filesystem).
+#
 class DovecotRm
 
   include DovecotPlugin
   include RmPlugin
 
 
-  def delete_domain(domain)
-    # Will raise an exception if the path doesn't exist.
+  # Remove *domain* from the Dovecot mailstore. This just runs "rm -r"
+  # on the domain directory if it exists.
+  #
+  # @param domain [Domain] the domain to remove.
+  #
+  def remove_domain(domain)
     domain_path = self.get_domain_path(domain)
+
+    if not File.directory?(domain_path)
+      raise NonexistentDomainError.new(domain.to_s())
+    end
+
     FileUtils.rm_r(domain_path)
   end
 
-  def delete_account(account)
-    # Will raise an exception if the path doesn't exist.
-    account_path = self.get_account_path(account)
-    FileUtils.rm_r(account_path)
+
+  # Remove *user* from the Dovecot mailstore. This just runs "rm -r"
+  # on the *user*'s mailbox directory, if it exists.
+  #
+  # @param user [User] the user whose mailbox directory we want to
+  #   remove.
+  #
+  def remove_user(user)
+    user_path = self.get_user_path(user)
+
+    if not File.directory?(user_path)
+      raise NonexistentUserError.new(user.to_s())
+    end
+
+    FileUtils.rm_r(user_path)
   end
 
 end