X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fcommon%2Fplugin.rb;h=633c8fd26d0c2f4bd467ff3d33aa3a48cc1a93fc;hp=0687989fe03169e3aa2e4d9c256f30bf9cbe8b67;hb=483d14dc8228a81d12fb109d3ed6510e2d2b03c1;hpb=e7fa62fc599b7583102fe48fbaad3db4f911a6da diff --git a/lib/common/plugin.rb b/lib/common/plugin.rb index 0687989..633c8fd 100644 --- a/lib/common/plugin.rb +++ b/lib/common/plugin.rb @@ -28,4 +28,30 @@ module Plugin raise NotImplementedError end + def list_users() + # Return a list of all users managed by this plugin. + raise NotImplementedError + 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