[rt-users] How to grab requestor's first and last name in email address ?

Landon Stewart lstewart at iweb.com
Wed Feb 5 14:49:44 EST 2014

On 5 February 2014 11:16, Ethier, Michael <methier at cgr.harvard.edu> wrote:

>  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 at 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 at iweb.com
Lead Specialist, Abuse and Security Management
Spécialiste principal, gestion des abus et sécurité
http://iweb.com :: +1 (888) 909-4932
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20140205/8ffaf675/attachment.htm>

More information about the rt-users mailing list