]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/dovecot_plugin.rb
4718483bec420e0e11731502597069300c816cb4
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
.mail_root
16 def describe_domain(domain
)
18 domain_path
= get_domain_path(domain
)
20 rescue NonexistentDomainError
=> e
21 return "Doesn't exist: #{e.to_s}"
25 def describe_user(user
)
27 user_path
= get_user_path(user
)
29 rescue NonexistentUserError
=> e
30 return "Doesn't exist: #{e.to_s}"
35 def domain_exists(domain
)
36 domains
= list_domains()
37 return domains
.include?(domain
)
43 def get_domain_path(domain
)
44 # Return the filesystem path for the given domain.
45 # That is, the directory where its mail is stored.
46 # Only works if the domain directory exists!
47 return File
.join(@domain_root, domain
.to_s())
51 def get_user_path(user
)
52 # Return the filesystem path of this user's mailbox.
53 domain_path
= get_domain_path(user
.domain())
54 return File
.join(domain_path
, user
.localpart())
59 return Filesystem
.get_subdirs(@domain_root).map
{ |d
| Domain
.new(d
) }
62 def list_domains_users(domains
)
65 domains
.each
do |domain
|
67 # Throws a NonexistentDomainError if the domain's path
68 # doesn't exist on the filesystem. In this case, we want
69 # to report zero users.
70 domain_path
= get_domain_path(domain
)
71 usernames
= Filesystem
.get_subdirs(domain_path
)
73 usernames
.each
do |username
|
74 users
<< User
.new("#{username}@#{domain}")
76 rescue NonexistentDomainError
86 domains
= list_domains()
87 users
= list_domains_users(domains
)