<HTML>
<HEAD>
<TITLE>Re: [rt-users] Scrip to add watchers from mail body SOLVED</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Since noone replyid I figured it out myself ;)<BR>
There might be an easier way to do it but this works for me. Basically I create an array of the content splitted by space (or newline) and then go through each line in array to set watchers.<BR>
<BR>
<BR>
This is my code:<BR>
<BR>
my $attachs = $self->TransactionObj->Attachments;<BR>
my $AttachObj;<BR>
<BR>
while( my $a = $attachs->Next ) <BR>
{<BR>
  if( $a->ContentType eq 'text/plain' ) <BR>
  { <BR>
    $AttachObj = $a; <BR>
    last <BR>
  } <BR>
} <BR>
unless ($AttachObj)<BR>
{<BR>
  unless ( $AttachObj = $self->TransactionObj->Attachments->First )<BR>
  {<BR>
    return 1;<BR>
  }<BR>
  unless( $AttachObj->ContentType =~ /^text/ ) {<BR>
    return 1;<BR>
  }<BR>
}<BR>
<BR>
my $content = $AttachObj->Content;<BR>
my @arrayBody = split(' ', $content);<BR>
foreach my $line (@arrayBody) {<BR>
 if( $line =~ m/^\QSet-CC:\E\s*(\S+)\s*$/m ) {<BR>
      $self->TicketObj->AddWatcher( Type => "Cc", Email => $1);<BR>
      $RT::Logger->info( "User ". $1 . " added as watcher to Ticket #" . $self->TicketObj->Id);<BR>
 }<BR>
}<BR>
<BR>
# strip special commands from email content<BR>
$content =~ s/^\QSet-CC:\E\s*(\S+)\s*$//gm;<BR>
<BR>
# silently overwrite attachment content<BR>
$AttachObj->__Set( Field => 'Content', Value => $content );<BR>
1;<BR>
<BR>
<BR>
On 5/12/08 10:11 AM, "Johan Baarman" <<a href="johan.baarman@citec.fi">johan.baarman@citec.fi</a>> wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Hi list,<BR>
<BR>
I’m trying to create a scip that will add several watchers from a mail body on ticket creation. It works alright for the first line but can’t get it to add several watchers. I’ve followed <a href="http://wiki.bestpractical.com/view/SetTicketPropertiesViaMail">http://wiki.bestpractical.com/view/SetTicketPropertiesViaMail</a> but I’m not too confident with perl to get it work.<BR>
<BR>
<BR>
My message body looks like this:<BR>
<BR>
Set-CC:<a href="john.doe@mycompany.com">john.doe@mycompany.com</a><BR>
Set-CC:<a href="marcus.whatever@mycompany.com">marcus.whatever@mycompany.com</a><BR>
Set-CC:<a href="brian.surname@mycompany.com">brian.surname@mycompany.com</a><BR>
<BR>
<BR>
And my scrip looks like:<BR>
<BR>
my $AttachObj = $self->TransactionObj->Attachments->First;<BR>
# go out if content is not text!<BR>
unless( $AttachObj->ContentType =~ /^text/ ) {<BR>
     return 1;<BR>
}<BR>
<BR>
my $content = $AttachObj->Content;<BR>
if( $content =~ m/^\QSet-CC:\E\s*(\S+)\s*$/m ) {<BR>
      $self->TicketObj->AddWatcher( Type => "Cc", Email => $1);<BR>
}<BR>
<BR>
# strip special commands from email content<BR>
$content =~ s/^\QSet-CC:\E\s*(\S+)\s*$//gm;<BR>
<BR>
# silently overwrite attachment content<BR>
$AttachObj->__Set( Field => 'Content', Value => $content );<BR>
1;<BR>
<BR>
I guess I should make the scrip go through each line but don’t know how?<BR>
<BR>
Thank in advance<BR>
Johan ###########################################<BR>
<BR>
This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.<BR>
For more information, connect to <a href="http://www.f-secure.com/">http://www.f-secure.com/</a><BR>
<HR ALIGN=CENTER SIZE="3" WIDTH="95%"></SPAN></FONT><FONT SIZE="2"><FONT FACE="Consolas, Courier New, Courier"><SPAN STYLE='font-size:10pt'>_______________________________________________<BR>
<a href="http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users">http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users</a><BR>
<BR>
Community help: <a href="http://wiki.bestpractical.com">http://wiki.bestpractical.com</a><BR>
Commercial support: <a href="sales@bestpractical.com">sales@bestpractical.com</a><BR>
<BR>
<BR>
Discover RT's hidden secrets with RT Essentials from O'Reilly Media. <BR>
Buy a copy at <a href="http://rtbook.bestpractical.com">http://rtbook.bestpractical.com</a><BR>
</SPAN></FONT></FONT></BLOCKQUOTE>
###########################################<br><br>This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.<br>For more information, connect to http://www.f-secure.com/</BODY>
</HTML>