X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fcommon%2Fplugin.rb;h=b0b57505873665a856dcf7ade0eafc4b82cf266a;hp=0687989fe03169e3aa2e4d9c256f30bf9cbe8b67;hb=72696d3f6e95ef773af9727e9c3459b9038b0fc2;hpb=c6cab6b71770d14dad1115db90a00b990c44a58d diff --git a/lib/common/plugin.rb b/lib/common/plugin.rb index 0687989..b0b5750 100644 --- a/lib/common/plugin.rb +++ b/lib/common/plugin.rb @@ -21,11 +21,45 @@ module Plugin raise NotImplementedError end - def describe_account(account) - # Provide a "description" of the account. This is output along + def describe_user(user) + # Provide a "description" of the user. This is output along # with the domain name and can be anything of use to the system # administrator. raise NotImplementedError end + def list_users() + # Return a list of all users managed by this plugin. + raise NotImplementedError + end + + def user_exists(username) + # Does the given username exist for this plugin? We use a naive + # implementation here based on list_users() which is required to + # exist above. Plugins can override this with something fast. + users = list_users() + return users.include?(username) + end + + def list_domains_users(domains) + # Get all usernames belonging to the given domains. If a username + # ends in @example.com, it belongs to the domain example.com + # + # This uses a naive loop, but relies only on the existence of a + # list_users() method which is guaranteed above. More efficient + # implementations can usually be made within the plugin. + domains_users = [] + + usernames = list_users(); + domains.each do |d| + matches = usernames.select do |username| + username =~ /@#{d}$/ + end + + domains_users += matches + end + + return domains_users + end + end