]>
gitweb.michael.orlitzky.com - mailshears.git/blob - src/plugins/dovecot_mailstore.rb
d253c3250bb693c486e8891506983c137a606222
2 require 'src/filesystem'
3 require 'src/mailstore'
6 class DovecotMailstore
< Mailstore
11 @domain_root = Configuration
::MAIL_ROOT
14 def describe_domain(domain
)
15 return get_domain_path(domain
)
18 def describe_account(account
)
20 account_path
= get_account_path(account
)
22 rescue NonexistentAccountError
=> e
27 def delete_domain(domain
)
28 domain_path
= self.get_domain_path(domain
)
29 FileUtils
.rm_rf(domain_path
)
32 def delete_account(account
)
33 account_path
= self.get_account_path(account
)
34 FileUtils
.rm_rf(account_path
)
37 def get_leftover_domains(db_domains
)
38 # Get the list of domains according to the filesystem.
39 fs_domains
= self.get_domains_from_filesystem()
41 # Return the list of domains on the filesystem that aren't in the DB.
42 return (fs_domains
- db_domains
)
45 def get_leftover_accounts(db_accounts
)
46 # Get the list of accounts according to the filesystem.
47 fs_domains
= self.get_domains_from_filesystem()
48 fs_accounts
= self.get_accounts_from_filesystem(fs_domains
)
50 # And return the accounts on the filesystem that aren't in the DB.
51 return (fs_accounts
- db_accounts
)
56 def get_domains_from_filesystem()
57 return Filesystem
.get_subdirs(@domain_root)
60 def get_accounts_from_filesystem(domains
)
63 domains
.each
do |domain
|
65 # Throws a NonexistentDomainError if the domain's path
66 # doesn't exist on the filesystem. In this case, we want
67 # to report zero accounts.
68 domain_path
= get_domain_path(domain
)
69 usernames
= Filesystem
.get_subdirs(domain_path
)
71 usernames
.each
do |username
|
72 accounts
<< "#{username}@#{domain}"
74 rescue NonexistentDomainError
=> e
83 def get_domain_path(domain
)
84 # Return the filesystem path for the given domain.
85 # That is, the directory where its mail is stored.
86 # Only works if the domain directory exists!
87 domain_path
= File
.join(@domain_root, domain
)
89 if File
.directory
?(domain_path
)
92 raise NonexistentDomainError
.new(domain_path
)
97 def get_account_path(account
)
98 # Return the filesystem path of this account's mailbox.
99 # Only works if the account exists!
100 if not account
.include?('@')
101 raise InvalidAccountError
.new("#{account}: Accounts must contain an '@' symbol.")
104 account_parts
= account
.split('@')
105 user_part
= account_parts
[0]
106 domain_part
= account_parts
[1]
108 domain_path
= get_domain_path(domain_part
)
109 account_path
= File
.join(domain_path
, user_part
)
111 if File
.directory
?(account_path
)
114 raise NonexistentAccountError
.new(account_path
)