]>
gitweb.michael.orlitzky.com - mailshears.git/blob - src/dovecot_mailstore.rb
d675efc9be45b883c02fdcb15233fea57d71e270
2 require 'src/filesystem'
3 require 'src/mailstore'
5 class DovecotMailstore
< Mailstore
7 def get_domains_from_filesystem()
8 return Filesystem
.get_subdirs(@domain_root)
12 def get_accounts_from_filesystem(domains
)
15 domains
.each
do |domain
|
17 # Throws a NonexistentDomainError if the domain's path
18 # doesn't exist on the filesystem. In this case, we want
19 # to report zero accounts.
20 domain_path
= get_domain_path(domain
)
21 usernames
= Filesystem
.get_subdirs(domain_path
)
23 usernames
.each
do |username
|
24 accounts
<< "#{username}@#{domain}"
26 rescue NonexistentDomainError
=> e
35 def get_domain_path(domain
)
36 # Return the filesystem path for the given domain.
37 # That is, the directory where its mail is stored.
38 # Only works if the domain directory exists!
39 domain_path
= File
.join(@domain_root, domain
)
41 if File
.directory
?(domain_path
)
44 raise NonexistentDomainError
.new(domain_path
)
49 def get_account_path(account
)
50 # Return the filesystem path of this account's mailbox.
51 # Only works if the account exists!
52 if not account
.include?('@')
53 raise InvalidAccountError
.new("#{account}: Accounts must contain an '@' symbol.")
56 account_parts
= account
.split('@')
57 user_part
= account_parts
[0]
58 domain_part
= account_parts
[1]
60 domain_path
= get_domain_path(domain_part
)
61 account_path
= File
.join(domain_path
, user_part
)
63 if File
.directory
?(account_path
)
66 raise NonexistentAccountError
.new(account_path
)