OnToOrCC: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
m (2 revisions imported)
 
mNo edit summary
 
Line 9: Line 9:
'''Custom Condition:'''
'''Custom Condition:'''


  <nowiki># Parse out if the email was sent to Clarity and exclude
  <pre>
# Parse out if the email was sent to Clarity and exclude
  my $ContentObj = $self-&gt;TransactionObj-&gt;Attachments-&gt;First();
  my $ContentObj = $self-&gt;TransactionObj-&gt;Attachments-&gt;First();
  my $Headers = $ContentObj-&gt;{values}{headers};
  my $Headers = $ContentObj-&gt;{values}{headers};
Line 20: Line 21:
   
   
  return 1;
  return 1;
  </pre>
</nowiki>


'''Code Explanation:''' This condition grabs the first attachment and gets the header block. It then searches through the headers looking for a line that starts with "To:" or "CC:" and then for a particular ACCOUNT.
'''Code Explanation:''' This condition grabs the first attachment and gets the header block. It then searches through the headers looking for a line that starts with "To:" or "CC:" and then for a particular ACCOUNT.


The /im on the regex makes it case-insensitive and treats each line in the multi-line block as and individual line. If you don't have the /m then the ^ anchor will only go on the very first line.
The /im on the regex makes it case-insensitive and treats each line in the multi-line block as and individual line. If you don't have the /m then the ^ anchor will only go on the very first line.

Latest revision as of 16:11, 17 August 2016

Purpose: We have multiple mailboxes to accept requests to a single RT system. There are certain scripts that I want to execute for some mailboxes but not others. For example we have a paging scrip for off hours but don't want to page for a certain mailbox.

This condition scrip searches the headers for a particular email account in the TO or CC line of the email. If it finds a match it exits out and does not execute. Of course you can flip the result bit so it does do something.

Author: macnlos AT comcast DOT net - I'm on the RT Users List

Condition: User Defined

Custom Condition:

 # Parse out if the email was sent to Clarity and exclude
 my $ContentObj = $self->TransactionObj->Attachments->First();
 my $Headers = $ContentObj->{values}{headers};
 if ($Headers =~ /^To: .*ACCOUNT.*/im) {
    return 0;
 }
 if ($Headers =~ /^CC: .*ACCOUNT.*/im) {
    return 0;
 }
 
 return 1;
  

Code Explanation: This condition grabs the first attachment and gets the header block. It then searches through the headers looking for a line that starts with "To:" or "CC:" and then for a particular ACCOUNT.

The /im on the regex makes it case-insensitive and treats each line in the multi-line block as and individual line. If you don't have the /m then the ^ anchor will only go on the very first line.