Regex matching in scrips to match email requestor RT 3.8.7 - reference material anywhere?

Hi all,

I’m trying to get a scrip setup that will send conditionally based
upon the senders email address. Basically I don’t want to send an
email to addresses that look like:

root@
administrator@
mailer-daemon@

and so forth. I’ve looked at the doco both online and in the RT book
but neither cover these specific cases I’m trying to do - for example
the object model isn’t completely documented and I can’t find a page
that tells me what operators I can use with text or other fields.

So… I’ve actually got three questions here (sorry!):

  1. How to regex these strings
  2. What the object reference is to retrieve the first requestor email
    address inside a scrip
  3. Can I build an array of results so that I can keep adding more and
    more cases easily

I’ve got a script that is correctly working that handles conditional
stuff OK for values of CF fields and ticket status, but I’m not sure
how to handle this one because I’m doing a fuzzy match… if it was
SQL it would be easy "where email like ‘root@%’ or similar depending
on your DBMS. I know I can use “eq” or “ne” but is there a "like"
comparator available that I can use in a scrip… and if so, how do I
pass it a wildcard?

Question 1.
I’ve found some examples of scrips in wikia that skirt around what I’m
trying to do… (sorry to the OP I don’t have the original link
available but I think it was the customcondition page):

my $subject = $Transaction->Attachments->First->GetHeader(‘Subject’);
if ($subject =~ /** RECOVERY (\w+) - (.*) OK **/) {

but… how do I interpret this? I’m guessing that the syntax means
"RECOVERYOK*" (i.e. *== wildcard). But what’s the (\w+) and why the
**/ construction? I’ve seen some other examples out there with other
syntax too but don’t have them at hand. Is there a page somewhere that
describes what’s available for this and how to use the syntax?

Question 2.
I think that the object I need is: $self->TicketObj->IsWatcher(Type
=> ‘Requestor’, Email => ‘foo@bar.com’);
based upon another page on wikia (apologies again)!
but… it seems a little bit odd that I can’t reference it by
$self->TicketObj->Requestor->Email?
Also, if I do reference it as above, then what happens if there is > 1
Requestor? I would be happy if it only returns the email of the first
requestor, but would it does this or return the ARRAY error you see in
the CLI when trying to pull requestor email?

Question 3.
Apologies I haven’t actually looked into this yet as I got stuck on 1
& 2, but if there’s an easy way to model a growing list of things to
match please point me at an example. Another use case for this would
be auto-deleting spam emails, and auto-resolving system generated
tickets that have no error content (for example “Backup successful”).

Thanks,

Chris

I’m trying to get a scrip setup that will send conditionally based
upon the senders email address. Basically I don’t want to send an
email to addresses that look like:

root@
administrator@
mailer-daemon@

and so forth. I’ve looked at the doco both online and in the RT book
but neither cover these specific cases I’m trying to do - for example
the object model isn’t completely documented and I can’t find a page
that tells me what operators I can use with text or other fields.

So… I’ve actually got three questions here (sorry!):

  1. How to regex these strings
  2. What the object reference is to retrieve the first requestor email
    address inside a scrip
  3. Can I build an array of results so that I can keep adding more and
    more cases easily

I’ve got a script that is correctly working that handles conditional
stuff OK for values of CF fields and ticket status, but I’m not sure
how to handle this one because I’m doing a fuzzy match… if it was
SQL it would be easy "where email like ‘root@%’ or similar depending
on your DBMS. I know I can use “eq” or “ne” but is there a "like"
comparator available that I can use in a scrip… and if so, how do I
pass it a wildcard?

You want to read about perl regular expressions, which are the things
you’re talking about in question 1. The =~ operator is perl’s Like
operator, but they’re very powerful.

Question 1.
I’ve found some examples of scrips in wikia that skirt around what I’m
trying to do… (sorry to the OP I don’t have the original link
available but I think it was the customcondition page):

my $subject = $Transaction->Attachments->First->GetHeader(‘Subject’);
if ($subject =~ /** RECOVERY (\w+) - (.*) OK **/) {

but… how do I interpret this? I’m guessing that the syntax means
"RECOVERYOK*" (i.e. *== wildcard). But what’s the (\w+) and why the
**/ construction? I’ve seen some other examples out there with other
syntax too but don’t have them at hand. Is there a page somewhere that
describes what’s available for this and how to use the syntax?

Question 2.
I think that the object I need is: $self->TicketObj->IsWatcher(Type
=> ‘Requestor’, Email => ‘foo@bar.com’);
based upon another page on wikia (apologies again)!
but… it seems a little bit odd that I can’t reference it by
$self->TicketObj->Requestor->Email?
Also, if I do reference it as above, then what happens if there is > 1
Requestor? I would be happy if it only returns the email of the first
requestor, but would it does this or return the ARRAY error you see in
the CLI when trying to pull requestor email?

If you perldoc lib/RT/Ticket.pm on RT4 you’ll see a relevant method to
get all the email addresses of the requestors.

Question 3.
Apologies I haven’t actually looked into this yet as I got stuck on 1
& 2, but if there’s an easy way to model a growing list of things to
match please point me at an example. Another use case for this would
be auto-deleting spam emails, and auto-resolving system generated
tickets that have no error content (for example “Backup successful”).

I usually turn them into Config options you set in RT_SiteConfig.pm
that way the perl code never changes.

-kevin