How to grab requestor's first and last name in email address?

Hello,

I need to obtain the first and last name that would be part of the requestor’s email address.
For example, requestor email address comes in as:

In this example I want parse out the “Joe” and “Smith” keywords and assign them to 2 variables
which I will use for comparison later.

I am writing a RT Scrip. Is this possible to do ?

Thanks,
Mike

Hello,

I need to obtain the first and last name that would be part of the
requestor’s email address.

For example, requestor email address comes in as:

From: “Smith, Joe” jsmith@mail.com

In this example I want parse out the “Joe” and “Smith” keywords and assign
them to 2 variables

which I will use for comparison later.

I am writing a RT Scrip. Is this possible to do ?

The “name” of the requestor is stored within the UsersObj in the Requestors
group object for the $Ticket. You want the first UsersObj. There’s no way
to know if it’s the name is written “Last, First” or “First Last” so you’ll
have to figure that out somehow. Usually a comma in a name field means
“Last, First” though so the following is a decent bet. I haven’t tested
this code but this ought to get you close anyway.

my $realname = $self->TicketObj->Requestors->UsersObj->First->RealName;

Switch things around if there’s a comma in the field.

$realname =~ s/(.),\s(.*)/$2 $1/ if $realname =~ /,/;

If they have “First Last, Company” it’ll come out as “ACME Inc., Jim Smith”
though which might not be terrible.
Worse would be “Last, First - Position” coming out as “Jim - Manager Smith”
which might sound a little too familiar for business.

In my opinion you’d want to just leave it as-is so if it’s Last, First and
they get an email addressed to them with “Dear Smith, Jim:” they’ll know
it’s because they have it that way in their mail client.

Landon Stewart :: lstewart@iweb.com
Lead Specialist, Abuse and Security Management
Spécialiste principal, gestion des abus et sécurité
http://iweb.com :: +1 (888) 909-4932

Hi,

I tried your suggestion and it doesn’t work, RT complains:

[3270] [Thu Feb 6 12:50:36 2014] [error]: Scrip 25 IsApplicable failed: Can’t locate object method “First” via package “No object mapping for field” (perhaps you forgot to load “No object mapping for field”?) at (eval 792) line 20.

When I try this code, it runs but it’s not outputting what I need:
my $trueuser = $TicketObj->Requestors->UserMembersObj->First->RealName;
$RT::Logger->debug("trueuser is: ".$trueuser);

Resulting output looks to be whatever is before the “@” in the email address, not the RealName:

[3263] [Thu Feb 6 12:55:07 2014] [debug]: trueuser is: ethier ((eval 625):28)

Any other ideas ?

Thanks,
MikeFrom: Landon Stewart [mailto:lstewart@iweb.com]
Sent: Wednesday, February 05, 2014 2:50 PM
To: Ethier, Michael
Cc: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] How to grab requestor’s first and last name in email address ?

Hello,

I need to obtain the first and last name that would be part of the requestor’s email address.
For example, requestor email address comes in as:

From: “Smith, Joe” <jsmith@mail.commailto:jsmith@mail.com>

In this example I want parse out the “Joe” and “Smith” keywords and assign them to 2 variables
which I will use for comparison later.

I am writing a RT Scrip. Is this possible to do ?

The “name” of the requestor is stored within the UsersObj in the Requestors group object for the $Ticket. You want the first UsersObj. There’s no way to know if it’s the name is written “Last, First” or “First Last” so you’ll have to figure that out somehow. Usually a comma in a name field means “Last, First” though so the following is a decent bet. I haven’t tested this code but this ought to get you close anyway.

my $realname = $self->TicketObj->Requestors->UsersObj->First->RealName;

Switch things around if there’s a comma in the field.

$realname =~ s/(.),\s(.*)/$2 $1/ if $realname =~ /,/;

If they have “First Last, Company” it’ll come out as “ACME Inc., Jim Smith” though which might not be terrible.
Worse would be “Last, First - Position” coming out as “Jim - Manager Smith” which might sound a little too familiar for business.

In my opinion you’d want to just leave it as-is so if it’s Last, First and they get an email addressed to them with “Dear Smith, Jim:” they’ll know it’s because they have it that way in their mail client.

Landon Stewart :: lstewart@iweb.commailto:lstewart@iweb.com
Lead Specialist, Abuse and Security Management
Spécialiste principal, gestion des abus et sécurité
http://iweb.com :: +1 (888) 909-4932

When I try this code, it runs but it’s not outputting what I need:
my $trueuser = $TicketObj->Requestors->UserMembersObj->First->RealName;
$RT::Logger->debug("trueuser is: ".$trueuser);

Resulting output looks to be whatever is before the “@” in the email address, not the
RealName:

[3263] [Thu Feb 6 12:55:07 2014] [debug]: trueuser is: ethier ((eval 625):28)

RealName is set to the Email Address’ ‘phrase’ which is the “Smith,
Joe” you mention. I suspect your test email isn’t sending what you
expect. Or, the user already exists in your system with that bogus
RealName (you can confirm this by searching for the user in the admin
UI and reading the History tab).

You may want to try
$self->TransactionObj->ContentObj->GetHeader(‘From’) and parse it
manually if you can’t trust your Users table (which is what Requestors
is searching).

-kevin