]>
gitweb.michael.orlitzky.com - mailshears.git/blob - dovecot_plugin.rb
fa61d5367b593d959c1839de143f1f0c767490db
1 require 'common/domain'
2 require 'common/filesystem'
3 require 'common/plugin'
8 # Code that all Dovecot plugins (Prune, Rm, Mv...) will
9 # share. That is, we implement the Plugin interface.
13 @domain_root = cfg
.dovecot_mail_root
16 def describe_domain(domain
)
17 return get_domain_path(domain
)
20 def describe_user(user
)
21 return get_user_path(user
)
27 def get_domain_path(domain
)
28 # Return the filesystem path for the given domain.
29 # That is, the directory where its mail is stored.
30 # Only works if the domain directory exists!
31 return File
.join(@domain_root, domain
.to_s())
35 def get_user_path(user
)
36 # Return the filesystem path of this user's mailbox.
37 domain_path
= get_domain_path(user
.domain())
38 return File
.join(domain_path
, user
.localpart())
43 return Filesystem
.get_subdirs(@domain_root).map
{ |d
| Domain
.new(d
) }
46 def list_domains_users(domains
)
49 domains
.each
do |domain
|
51 # Throws a NonexistentDomainError if the domain's path
52 # doesn't exist on the filesystem. In this case, we want
53 # to report zero users.
54 domain_path
= get_domain_path(domain
)
55 usernames
= Filesystem
.get_subdirs(domain_path
)
57 usernames
.each
do |username
|
58 users
<< User
.new("#{username}@#{domain}")
60 rescue NonexistentDomainError
70 domains
= list_domains()
71 users
= list_domains_users(domains
)