]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - lib/common/dovecot_plugin.rb
Get the MvRunner working, at least for Postfixadmin.
[mailshears.git] / lib / common / dovecot_plugin.rb
index 2496bae2eade64be5889c4a5057b8ac00e4b5228..dfd87494c797642d68614ad3ca8e0a0f5a6169ad 100644 (file)
@@ -6,8 +6,7 @@ module DovecotPlugin
   # share.  That is, we implement the Plugin interface.
   include Plugin
 
-  def initialize
-    cfg = Configuration.new()
+  def initialize(cfg)
     @domain_root = cfg.mail_root
   end
 
@@ -20,11 +19,11 @@ module DovecotPlugin
     end
   end
 
-  def describe_account(account)
+  def describe_user(user)
     begin
-      account_path = get_account_path(account)
-      return account_path
-    rescue NonexistentAccountError => e
+      user_path = get_user_path(user)
+      return user_path
+    rescue NonexistentUserError => e
       return "Doesn't exist: #{e.to_s}"
     end
   end
@@ -46,30 +45,33 @@ module DovecotPlugin
   end
 
 
-  def get_account_path(account)
-    # Return the filesystem path of this account's mailbox.
-    # Only works if the account exists!
-    if not account.include?('@')
-      msg = "#{account}: Accounts must contain an '@' symbol."
-      raise InvalidAccountError.new(msg)
+  def get_user_path(user, existence_check = true)
+    # Return the filesystem path of this user's mailbox. With
+    # existence_check = true, it only works if the user exists!
+    # We always require that the domain exists.
+    if not user.include?('@')
+      msg = "#{user}: Users must contain an '@' symbol."
+      raise InvalidUserError.new(msg)
     end
 
-    account_parts = account.split('@')
-    user_part = account_parts[0]
-    domain_part = account_parts[1]
+    user_parts = user.split('@')
+    local_part = user_parts[0]
+    domain_part = user_parts[1]
 
     begin
       domain_path = get_domain_path(domain_part)
     rescue NonexistentDomainError
-      raise NonexistentAccountError.new(account)
+      raise NonexistentUserError.new(user)
     end
 
-    account_path = File.join(domain_path, user_part)
+    user_path = File.join(domain_path, local_part)
 
-    if File.directory?(account_path)
-      return account_path
+    return user_path if not existence_check
+
+    if File.directory?(user_path)
+      return user_path
     else
-      raise NonexistentAccountError.new(account)
+      raise NonexistentUserError.new(user)
     end
   end
 
@@ -79,25 +81,25 @@ module DovecotPlugin
   end
 
   def list_domains_users(domains)
-    accounts = []
+    users = []
 
     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.
+        # to report zero users.
         domain_path = get_domain_path(domain)
         usernames = Filesystem.get_subdirs(domain_path)
 
         usernames.each do |username|
-          accounts << "#{username}@#{domain}"
+          users << "#{username}@#{domain}"
         end
       rescue NonexistentDomainError
         # Party hard.
       end
     end
 
-    return accounts
+    return users
   end