[Rt-devel] Who should call
RT::EmailParser::LookupExternalUserInfo()?
Petter Reinholdtsen
pere at hungry.com
Wed Aug 25 12:31:48 EDT 2004
I'm working integrating RT into our LDAP infrastructure, and ran into
a question. The function RT::EmailParser::LookupExternalUserInfo()
seem to be intended for one of the features we need. I want to map
mail address to local username when a new user is to be created when a
new mail is recieved. But this function do not seem to be used.
Which part of the code is supposed to call this function? I suspect
Email/Auth/MailFrom.pm is the best place to insert the call. Is this
patch on the right track?
--- lib/RT/Interface/Email/Auth/MailFrom.pm 2004-03-28 06:04:08.000000000 +0200
+++ local/lib/RT/Interface/Email/Auth/MailFromPere.pm 2004-08-25 18:29:03.000000000 +0200
@@ -36,11 +36,27 @@
@_ );
- # We don't need to do any external lookups
+ my $Username = undef;
my ( $Address, $Name ) = ParseSenderAddressFromHead( $args{'Message'}->head );
+
+ my ($UserFoundInExternalDatabase, %ExternalUserInfo) =
+ RT::EmailParser::LookupExternalUserInfo( undef, $Address, $Name );
+ if ($UserFoundInExternalDatabase) {
+ $Username = $ExternalUserInfo{'Name'} if $ExternalUserInfo{'Name'};
+ $Address = $ExternalUserInfo{'EmailAddress'}
+ if ($ExternalUserInfo{'EmailAddress'});
+ $RealName = $ExternalUserInfo{'RealName'}
+ if ($ExternalUserInfo{'RealName'});
+ }
+
my $CurrentUser = RT::CurrentUser->new();
- $CurrentUser->LoadByEmail($Address);
+ # Try username first
+ $CurrentUser->LoadByName($Username) if $Username;
+
+ unless ( $CurrentUser->Id ) {
+ $CurrentUser->LoadByEmail($Address);
+ }
unless ( $CurrentUser->Id ) {
$CurrentUser->LoadByName($Address);
}
@@ -117,7 +133,7 @@
}
- $CurrentUser = CreateUser( undef, $Address, $Name, $Address, $args{'Message'} );
+ $CurrentUser = CreateUser( $Username, $Address, $Name, $Address, $args{'Message'} );
return ( $CurrentUser, 1 );
}
With this modification, I'm able to use a replacement
RT::EmailParser::LookupExternalUserInfo() function (in my local
EmailParser_Local.pm) to look up the username in LDAP and get RT to
behave as I want. If this change is correct, please include it in the
next version of RT.
More information about the Rt-devel
mailing list