X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fcommon%2Fdovecot_mailstore_plugin.rb;h=90aa02c8fde2b582c93afda07902a36ea17c5722;hp=ff901ee43417e8e7d66562763792aeb75e13eb14;hb=bd2dabf89ab277fbe315b05e6dfa839afb5ce5ef;hpb=e3826d8926e11763837a591986d453e9ef5d9dec diff --git a/lib/common/dovecot_mailstore_plugin.rb b/lib/common/dovecot_mailstore_plugin.rb index ff901ee..90aa02c 100644 --- a/lib/common/dovecot_mailstore_plugin.rb +++ b/lib/common/dovecot_mailstore_plugin.rb @@ -1,4 +1,5 @@ require 'common/plugin' +require 'common/filesystem' 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?('@') - 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('@') @@ -67,8 +69,42 @@ module DovecotMailstorePlugin if File.directory?(account_path) return account_path else - raise NonexistentAccountError(account) + raise NonexistentAccountError.new(account) 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