X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fcommon%2Fdovecot_mailstore_plugin.rb;h=90aa02c8fde2b582c93afda07902a36ea17c5722;hp=d0f8dd11f7f76c10b8a53e7e83fa87989fe0b7b2;hb=483d14dc8228a81d12fb109d3ed6510e2d2b03c1;hpb=e7fa62fc599b7583102fe48fbaad3db4f911a6da diff --git a/lib/common/dovecot_mailstore_plugin.rb b/lib/common/dovecot_mailstore_plugin.rb index d0f8dd1..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('@') @@ -71,4 +73,38 @@ module DovecotMailstorePlugin 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