[rt-users] Regex match on requester's domain?

Todd Chapman todd at chaka.net
Thu Dec 15 14:26:06 EST 2005


Attached is a perl script I run periodically from cron that
inspects all users and adds them to a certain group if
their e-mail address matches a pattern.

-Todd

On Thu, Dec 15, 2005 at 12:20:28AM -0800, Mike Ely wrote:
> (First off, sorry for two posts, but the topics are different enough 
> that I thought it better to split into two threads.)
> 
> I'm wondering if it is possible to create a group that is essentially 
> (in my case) *@rogueriver.blahblah so that any user with that domain can 
> email in and be accepted as a requestor.  I can certainly use 
> AutoCreateFromExternalUserInfo if all else fails, but it seems like a 
> user/group wildcard like the above would be a more-elegant solution.
> 
> Cheers again,
> Mike Ely
> _______________________________________________
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
> 
> Be sure to check out the RT Wiki at http://wiki.bestpractical.com
> 
> Download a free sample chapter of RT Essentials from O'Reilly Media at 
> http://rtbook.bestpractical.com
> 
> WE'RE COMING TO YOUR TOWN SOON - RT Training in Amsterdam, Boston and
> San Francisco - Find out more at 
> http://bestpractical.com/services/training.html
-------------- next part --------------
#!/usr/bin/perl

use strict;
use warnings;
use lib qw(/opt/rt3/local/lib /opt/rt3/lib);

use RT;
RT::LoadConfig();
RT::Init();
use RT::Group;
use RT::Users;

my $g = RT::Group->new($RT::SystemUser);
$g->LoadUserDefinedGroup("my_group");
my $users = $g->UserMembersObj();

while (my $user = $users->Next) {

    $g->DeleteMember( $user->PrincipalObj->Id ) unless 
                    $user->EmailAddress =~ /\@my_company\.com(\.mx)?$/i
                or !$user->Privileged
                or  $user->Disabled;

}

$users = RT::Users->new($RT::SystemUser);
$users->LimitToEnabled();
$users->LimitToPrivileged;
$users->Limit(FIELD => 'EmailAddress', OPERATOR => 'LIKE', VALUE => '@my_company.com');

while (my $user = $users->Next) {

    next if $g->HasMember( $user->PrincipalObj );
    $g->AddMember( $user->PrincipalObj->Id );

}


More information about the rt-users mailing list