X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fcommon%2Fdovecot_plugin.rb;h=dfd87494c797642d68614ad3ca8e0a0f5a6169ad;hp=ab5a40930400af057229ded188d40516cc88b866;hb=861e51dd6a409cb41fa6fdac3f49195acccc6541;hpb=365d681f1ef45bd3f5f2c9dded07108bdd75a1ff diff --git a/lib/common/dovecot_plugin.rb b/lib/common/dovecot_plugin.rb index ab5a409..dfd8749 100644 --- a/lib/common/dovecot_plugin.rb +++ b/lib/common/dovecot_plugin.rb @@ -19,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 @@ -45,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 @@ -78,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