[rt-users] Queue-level Parsing of CC's

Ken Crocker kfcrocker at lbl.gov
Wed May 27 14:35:13 EDT 2009


To all (especially Ruslan & Stephen),

    Hallelujah! I finally got the code to parse CC addresses to a ticket 
for Queues only to work. Below is the code:

#----------------------------------------------------------------------------
# Custom condition:
#----------------------------------------------------------------------------
# condition set on email transaction to create

my $trans = $self->TransactionObj;
my $msgattr = $trans->Message->First;

return 0 unless $trans->Type eq "Create";
return 0 unless $msgattr;
return 1 if $msgattr->GetHeader('Received');
return 0;
#----------------------------------------------------------------------------
# Custom action preparation code:
#----------------------------------------------------------------------------
# Setup default QA Approver

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = "QA Approver";
my $cf_value = $trans->CreatorObj->Name;

$cf_obj->LoadByName( Name => $cf_name );
$RT::Logger->debug( "Loaded \$cf_obj->Name = ". $cf_obj->Name() ."\n" );
$ticket->AddCustomFieldValue( Field=>$cf_obj, Value=>$cf_value, 
RecordTransaction=>0 );

# Set up variables for parsing CC's

my $header;
my $addr;
my $ccid;
my $cc;

# Parse the email CC's into ticket "CC" Watchers

foreach $header ($trans->Attachments->First->GetHeader("Cc"))
    {
     foreach $cc ( split /\,/, $header )
         {      
          ($addr) = $cc =~ /([\w-]+?\@[\w-]+?\.[\w]+)/;
          $ccid = substr($addr, 0,length($addr)-8);
          my $user = RT::User->new($RT::SystemUser);
          $addr = $user->CanonicalizeEmailAddress($ccid);
          $ticket->AddWatcher( Type => 'Cc', Email => $ccid );
         }  
    }

return 1;
#----------------------------------------------------------------------------
# Custom action cleanup code:
#----------------------------------------------------------------------------
return 1;

    Now, I'm sure there are a couple of better ways to write this code, 
so Ruslan or Stephen, please advise. However, I am EXTREMELY tickled 
that I finally got this thing to work. OH, also thanks to Gene LeDuc.

Kenn
LBNL



More information about the rt-users mailing list