Move domain removal into the plugins.
[mailshears.git] / lib / common / plugin.rb
1 # All plugins should include this module. It defines the basic
2 # operations that all plugins are supposed to support.
3 module Plugin
4
5 def Plugin.included(c)
6 # Callback, called whenever another class or module includes this
7 # one. The parameter given is the name of the class or module
8 # that included us.
9 @includers ||= []
10 @includers << c
11 end
12
13 def Plugin.includers
14 return @includers
15 end
16
17 def describe_domain(domain)
18 # Provide a "description" of the domain. This is output along
19 # with the domain name and can be anything of use to the system
20 # administrator.
21 raise NotImplementedError
22 end
23
24 def describe_account(account)
25 # Provide a "description" of the account. This is output along
26 # with the domain name and can be anything of use to the system
27 # administrator.
28 raise NotImplementedError
29 end
30
31 def list_users()
32 # Return a list of all users managed by this plugin.
33 raise NotImplementedError
34 end
35
36 def list_domains_users(domains)
37 # Get all usernames belonging to the given domains. If a username
38 # ends in @example.com, it belongs to the domain example.com
39 #
40 # This uses a naive loop, but relies only on the existence of a
41 # list_users() method which is guaranteed above. More efficient
42 # implementations can usually be made within the plugin.
43 domains_users = []
44
45 usernames = list_users();
46 domains.each do |d|
47 matches = usernames.select do |username|
48 username =~ /@#{d}$/
49 end
50
51 domains_users += matches
52 end
53
54 return domains_users
55 end
56
57 end