Create a prep action based on custom header

I have a webform that submits an email into RT. I have a scrip that I want
to run ONLY if the email came from the webform. I currently have the scrip
set up, and all is working - but it works on EVERY email that comes in. I
would like to add a check so that if the email came from somewhere other
then the web form, then the rest scrip can be by-passed. With my webform, I
have added an X-header – “X-Webform: yes”

From reviewing the archives, It appears as though I can place this check
into the prep code. From what I found on the list, I have put the following
prep code together. But since my Perl skills are zero to null I wanted to
run it by the list:

Prep Code:

my $Trans = $self->TransactionObj;
my $submitted = $Trans->Attachments->First->GetHeader(‘X-Webform’) =~
/^yes\b/ ;

if the X-webform is yes then do magic

if ( $submitted = yes )
{
return 1;
} else {
return 0;
}

So, for the scrip edit page I currently have this:
Condition: On Create
Action: User Defined
Template: Global template:Blank
Stage: TransactionCreate

Custom condition: BLANK
Custom action prep. code: currently it has “return 1;” but I would like
to add the check
Custom action cleanup code: “My Magic”

So my questions are:

  1. Is my logic right - by adding a “return 1 if or return 0” type statement
    to the prep condition will I by-pass the cleanup code?
  2. Is my prep code noted above “good” or is my lack of Perl showing through?

http://gentgeen.homelinux.org

Associate yourself with men of good quality if you esteem
your own reputation; for 'tis better to be alone then in bad
company. - George Washington, Rules of Civility

Hi Kevin,

Answers: 1) logic is good but; 2) syntax is not

The “my $submitted” line is going to return a true or false depending on
whether the header is there and has “yes” as it’s argument. Since it’s a
true/false value, you can use
if ( $submitted )
instead of what you have.

And in fact, since you already have a boolean value, you could replace your
entire “if” block (6 lines after the comment) with:
return $submitted;

If your X-Webform header exists and has “yes” as it’s value, the prep code
will return TRUE and let the cleanup code execute, otherwise it will return
FALSE and that will be the end of it.

Regards,
Gene

At 08:12 AM 2/6/2008, Kevin Squire wrote:

I have a webform that submits an email into RT. I have a scrip that I
want to run ONLY if the email came from the webform. I currently have the
scrip set up, and all is working - but it works on EVERY email that comes
in. I would like to add a check so that if the email came from somewhere
other then the web form, then the rest scrip can be by-passed. With my
webform, I have added an X-header – “X-Webform: yes”

From reviewing the archives, It appears as though I can place this check
into the prep code. From what I found on the list, I have put the
following prep code together. But since my Perl skills are zero to null
I wanted to run it by the list:

Prep Code:

my $Trans = $self->TransactionObj;
my $submitted = $Trans->Attachments->First->GetHeader(‘X-Webform’) =~
/^yes\b/ ;

if the X-webform is yes then do magic

if ( $submitted = yes )
{
return 1;
} else {
return 0;
}

So, for the scrip edit page I currently have this:
Condition: On Create
Action: User Defined
Template: Global template:Blank
Stage: TransactionCreate

Custom condition: BLANK
Custom action prep. code: currently it has “return 1;” but I would
like to add the check
Custom action cleanup code: “My Magic”

So my questions are:

  1. Is my logic right - by adding a “return 1 if or return 0” type
    statement to the prep condition will I by-pass the cleanup code?
  2. Is my prep code noted above “good” or is my lack of Perl showing through?

Gene LeDuc, GSEC
Security Analyst
San Diego State University