+
+ # Return a list of all domains managed by this plugin. This must be
+ # supplied by the individual plugins (who know how to find their
+ # domains). Many plugins will not have a separate concept of
+ # "domain", so the default implementation constructs a list of
+ # domains resulting from {#list_users}.
+ #
+ # For plugins that do know about domains, smarter implementations
+ # are surely possible.
+ #
+ # @return [Array<Domain>] a list of the domains that this plugin knows
+ # about.
+ #
+ def list_domains()
+ users = list_users()
+ domains = users.map{ |u| u.domain() }
+ return domains.uniq()
+ end
+
+
+ # Does the given *user* exist for this plugin? We use a naive
+ # implementation here based on {#list_users}. Plugins should override
+ # this with something faster.
+ #
+ # @param user [User] the user whose existence is in question.
+ #
+ # @return [Boolean] true if *user* exists for this plugin, and
+ # false otherwise.
+ #
+ def user_exists(user)
+ users = list_users()
+ return users.include?(user)
+ end
+
+
+ # Does the given *domain* exist for this plugin? We use a naive
+ # implementation here based on {#list_domains}. Plugins that know
+ # about domains should override this with something fast.
+ #
+ # @param domain [Domain] the domain whose existence is in question.
+ #
+ # @return [Boolean] true if *domain* exists for this plugin, and
+ # false otherwise.
+ #
+ def domain_exists(domain)
+ domains = list_domains()
+ return domains.include?(domain)
+ end
+
+
+ # List all users belonging to the given domains. We say that a user
+ # belongs to a domain "example.com" if the domain part of the user's
+ # email address is "example.com".
+ #
+ # This uses a naive loop, but relies only on the existence of
+ # {#list_users}. Plugins that know about domains should provide a
+ # more efficient implementation.
+ #
+ # @param domains [Array<Domain>] the domains whose users we want.
+ #
+ # @return [Array<User>] a list of {User} objects belonging to
+ # *domains* for this plugin.
+ #
+ def list_domains_users(domains)
+ domains_users = []
+
+ users = list_users();
+ domains.each do |d|
+ matches = users.select do |user|
+ user.domainpart() == d.to_s()
+ end
+
+ domains_users += matches
+ end
+
+ return domains_users
+ end
+