]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - lib/common/dovecot_mailstore_plugin.rb
Move domain removal into the plugins.
[mailshears.git] / lib / common / dovecot_mailstore_plugin.rb
index d0f8dd11f7f76c10b8a53e7e83fa87989fe0b7b2..90aa02c8fde2b582c93afda07902a36ea17c5722 100644 (file)
@@ -1,4 +1,5 @@
 require 'common/plugin'
 require 'common/plugin'
+require 'common/filesystem'
 
 module DovecotMailstorePlugin
   # Code that all DovecotMailstore plugins (Prune, Rm, Mv...) will
 
 module DovecotMailstorePlugin
   # Code that all DovecotMailstore plugins (Prune, Rm, Mv...) will
@@ -49,7 +50,8 @@ module DovecotMailstorePlugin
     # Return the filesystem path of this account's mailbox.
     # Only works if the account exists!
     if not account.include?('@')
     # Return the filesystem path of this account's mailbox.
     # Only works if the account exists!
     if not account.include?('@')
-      raise InvalidAccountError.new("#{account}: Accounts must contain an '@' symbol.")
+      msg = "#{account}: Accounts must contain an '@' symbol."
+      raise InvalidAccountError.new(msg)
     end
 
     account_parts = account.split('@')
     end
 
     account_parts = account.split('@')
@@ -71,4 +73,38 @@ module DovecotMailstorePlugin
     end
   end
 
     end
   end
 
+
+  def list_domains()
+    return Filesystem.get_subdirs(@domain_root)
+  end
+
+  def list_domains_users(domains)
+    accounts = []
+
+    domains.each do |domain|
+      begin
+        # Throws a NonexistentDomainError if the domain's path
+        # doesn't exist on the filesystem. In this case, we want
+        # to report zero accounts.
+        domain_path = get_domain_path(domain)
+        usernames = Filesystem.get_subdirs(domain_path)
+
+        usernames.each do |username|
+          accounts << "#{username}@#{domain}"
+        end
+      rescue NonexistentDomainError
+        # Party hard.
+      end
+    end
+
+    return accounts
+  end
+
+
+  def list_users()
+    domains = list_domains()
+    users = list_domains_users(domains)
+    return users
+  end
+
 end
 end