[rt-users] Multiple email addresses for a single login name

Kyle Balling kballing at sci.utah.edu
Tue Sep 6 18:45:12 EDT 2005


OK, after hours and hours of pouring over the code in 
/opt/rt3/lib/RT/Interface/Email.pm I have a solution.

Now if there is a user, for example Joe, who has two or three or 10 
email addresses, RT will make it work. For example if Joe uses, 
joe at domain1.com and joe at domain2.com he will be able to create tickets by 
email and RT will not create two users or give an error. So here is what 
I changed.

(From Email.pm  with changes commented ) ---------------

# {{{ Create User

sub CreateUser {
    my ($Username, $Address, $Name, $ErrorsTo, $entity) = @_;
    my $NewUser = RT::User->new($RT::SystemUser);

     
 ##### I inserted this part to give me normal user names instead of the 
entire email address as the username
        my ($name, $domain) = split(/@/, $Address);
#####


       my ($Val, $Message) =
      $NewUser->Create(Name => $name,     ##### used to be ($Username || 
$Address),
                       EmailAddress => $Address,
                       RealName => $Name,
                       Password => undef,
                       Privileged => 0,
                       Comments => 'Autocreated on ticket submission'
                      );

     unless ($Val) {

        # Deal with the race condition of two account creations at once
        #
 
##### the function LoadByName doesn't work for some reason.
#        if ($Username) {
#            $NewUser->LoadByName($Username);
#        }
#####
#This seems to work and updates the user's email address to the most 
recently used one
                if ($name){
                        $NewUser->Load($name);
                        $NewUser->SetEmailAddress($Address)
                        }
#####

        unless ($NewUser->Id) {
            $NewUser->LoadByEmail($Address);
        }

      unless ($NewUser->Id) {
            MailError( To => $ErrorsTo,
                       Subject => "User could not be created",
                       Explanation => "User creation failed in 
mailgateway: $Mes
sage",
                       MIMEObj => $entity,
                       LogLevel => 'crit'
                     );
        }
    }


    my $CurrentUser = RT::CurrentUser->new();

        $CurrentUser->LoadByEmail($Address);

    unless ($CurrentUser->id) {
            $RT::Logger->warning("Couldn't load user '$Address'.".  
"giving up")
;
                MailError( To => $ErrorsTo,
                           Subject => "User could not be loaded",
                           Explanation => "User  '$Address' could not be 
loaded
in the mail gateway",
                           MIMEObj => $entity,
                           LogLevel => 'crit'
                     );
    }

    return $CurrentUser;
}
# }}}


That seems to work and is a good work around if a single username has to 
be mantained for multiple emails.
Please tell me if there are any errors.



Kyle Balling wrote:

> Hello RT world,
>
>    I am in a jam. This is the situation:  I have configured RT to 
> authenticate users on our NIS server. So,  when email is submitted, a  
> valid username is created by chopping the email address in two (i.e. 
> joe at domain.com becomes user 'joe' with email joe at domain.com). This 
> lets new users login correctly to rt with their NIS password. So it is 
> important to create users like that.
>
>   Here is the problem: Joe also has another email acount, 
> joe at blah.org, and when he sends mail to RT from this e-mail address he 
> gets a error message back and no ticket is created. RT recognizes 
> joe at blah.org as a new address and tries to create a user. When it gets 
> a username from his email, 'joe', and tries to create a new user, it 
> cannot because a user 'joe' already exists. I need to fix this problem.
>
>   How can I make RT realize that if a new email address has the same 
> username as an existing one, then it should assume it belongs to that 
> user? Then it can add that new address to the existing user or 
> overwrite the existing users old email. Of course we will assume that 
> there are no users with conflicting email adresses (i.e. user1 has 
> email bob at domain.com and user2 has email bob at otherdomain.com). It is 
> safe to say that all email addresses with the same username belong to 
> the same user
>
> Which also brings up the topic of assigning multiple email addresses 
> to one user, but it is not neccesary. I only need this to happen when 
> a user is created on email submission and skip new user creation if 
> the username already exists.
>
> Thanks in advance,
> Kyle Balling
> SCI Institute,
> Universtiy of Utah
>
>
>
>
> _______________________________________________
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>
> Be sure to check out the RT Wiki at http://wiki.bestpractical.com
>
> Buy your copy of our new book, RT Essentials, today!
> Download a free sample chapter from http://rtbook.bestpractical.com



More information about the rt-users mailing list