]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/dovecot_mailstore_plugin.rb
1 require 'common/plugin'
3 module DovecotMailstorePlugin
4 # Code that all DovecotMailstore plugins (Prune, Rm, Mv...) will
5 # share. That is, we implement the Plugin interface.
9 cfg
= Configuration
.new()
10 @domain_root = cfg
.mail_root
13 def describe_domain(domain
)
15 domain_path
= get_domain_path(domain
)
17 rescue NonexistentDomainError
=> e
18 return "Doesn't exist: #{e.to_s}"
22 def describe_account(account
)
24 account_path
= get_account_path(account
)
26 rescue NonexistentAccountError
=> e
27 return "Doesn't exist: #{e.to_s}"
34 def get_domain_path(domain
)
35 # Return the filesystem path for the given domain.
36 # That is, the directory where its mail is stored.
37 # Only works if the domain directory exists!
38 domain_path
= File
.join(@domain_root, domain
)
40 if File
.directory
?(domain_path
)
43 raise NonexistentDomainError
.new(domain
)
48 def get_account_path(account
)
49 # Return the filesystem path of this account's mailbox.
50 # Only works if the account exists!
51 if not account
.include?('@')
52 raise InvalidAccountError
.new("#{account}: Accounts must contain an '@' symbol.")
55 account_parts
= account
.split('@')
56 user_part
= account_parts
[0]
57 domain_part
= account_parts
[1]
60 domain_path
= get_domain_path(domain_part
)
61 rescue NonexistentDomainError
62 raise NonexistentAccountError
.new(account
)
65 account_path
= File
.join(domain_path
, user_part
)
67 if File
.directory
?(account_path
)
70 raise NonexistentAccountError(account
)