]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mv/plugins/dovecot_mailstore.rb
4ce1437f8fa474da5a9d77b798e6a8620a7d2fea
4 require 'common/filesystem'
5 require 'common/mailstore'
6 require 'common/plugin'
9 class DovecotMailstoreMv
< Mailstore
15 cfg
= Configuration
.new()
16 @domain_root = cfg
.mail_root
19 def describe_domain(domain
)
21 domain_path
= get_domain_path(domain
)
23 rescue NonexistentDomainError
=> e
24 return "Doesn't exist: #{e.to_s}"
28 def describe_account(account
)
30 account_path
= get_account_path(account
)
32 rescue NonexistentAccountError
=> e
33 return "Doesn't exist: #{e.to_s}"
37 def mv_domain(from
, to
)
38 from_path
= self.get_domain_path(from
)
39 to_path
= self.get_domain_path(to
)
40 FileUtils
.mv(from_path
, to_path
)
43 def mv_account(from
, to
)
44 from_path
= self.get_account_path(from
)
45 to_path
= self.get_account_path(to
)
46 FileUtils
.mv(from_path
, to_path
)
52 def get_domain_path(domain
)
53 # Return the filesystem path for the given domain.
54 # That is, the directory where its mail is stored.
55 # Only works if the domain directory exists!
56 domain_path
= File
.join(@domain_root, domain
)
58 if File
.directory
?(domain_path
)
61 raise NonexistentDomainError
.new(domain
)
66 def get_account_path(account
)
67 # Return the filesystem path of this account's mailbox.
68 # Only works if the account exists!
69 if not account
.include?('@')
70 msg
= "#{account}: Accounts must contain an '@' symbol."
71 raise InvalidAccountError
.new(msg
)
74 account_parts
= account
.split('@')
75 user_part
= account_parts
[0]
76 domain_part
= account_parts
[1]
79 domain_path
= get_domain_path(domain_part
)
80 rescue NonexistentDomainError
81 raise NonexistentAccountError
.new(account
)
84 account_path
= File
.join(domain_path
, user_part
)
86 if File
.directory
?(account_path
)
89 raise NonexistentAccountError(account
)