[rt-users] Scrip to add watchers from mail body SOLVED

Johan Baarman johan.baarman at citec.fi
Thu May 15 03:58:59 EDT 2008


Since noone replyid I figured it out myself ;)
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.


This is my code:

my $attachs = $self->TransactionObj->Attachments;
my $AttachObj;

while( my $a = $attachs->Next )
{
  if( $a->ContentType eq 'text/plain' )
  { 
    $AttachObj = $a;
    last 
  } 
} 
unless ($AttachObj)
{
  unless ( $AttachObj = $self->TransactionObj->Attachments->First )
  {
    return 1;
  }
  unless( $AttachObj->ContentType =~ /^text/ ) {
    return 1;
  }
}

my $content = $AttachObj->Content;
my @arrayBody = split(' ', $content);
foreach my $line (@arrayBody) {
 if( $line =~ m/^\QSet-CC:\E\s*(\S+)\s*$/m ) {
      $self->TicketObj->AddWatcher( Type => "Cc", Email => $1);
      $RT::Logger->info( "User ". $1 . " added as watcher to Ticket #" .
$self->TicketObj->Id);
 }
}

# strip special commands from email content
$content =~ s/^\QSet-CC:\E\s*(\S+)\s*$//gm;

# silently overwrite attachment content
$AttachObj->__Set( Field => 'Content', Value => $content );
1;


On 5/12/08 10:11 AM, "Johan Baarman" <johan.baarman at citec.fi> wrote:

> Hi list,
> 
> 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
> http://wiki.bestpractical.com/view/SetTicketPropertiesViaMail but I¹m not too
> confident with perl to get it work.
> 
> 
> My message body looks like this:
> 
> Set-CC:john.doe at mycompany.com
> Set-CC:marcus.whatever at mycompany.com
> Set-CC:brian.surname at mycompany.com
> 
> 
> And my scrip looks like:
> 
> my $AttachObj = $self->TransactionObj->Attachments->First;
> # go out if content is not text!
> unless( $AttachObj->ContentType =~ /^text/ ) {
>      return 1;
> }
> 
> my $content = $AttachObj->Content;
> if( $content =~ m/^\QSet-CC:\E\s*(\S+)\s*$/m ) {
>       $self->TicketObj->AddWatcher( Type => "Cc", Email => $1);
> }
> 
> # strip special commands from email content
> $content =~ s/^\QSet-CC:\E\s*(\S+)\s*$//gm;
> 
> # silently overwrite attachment content
> $AttachObj->__Set( Field => 'Content', Value => $content );
> 1;
> 
> I guess I should make the scrip go through each line but don¹t know how?
> 
> Thank in advance
> Johan ###########################################
> 
> This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.
> For more information, connect to http://www.f-secure.com/
> 
> _______________________________________________
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
> 
> Community help: http://wiki.bestpractical.com
> Commercial support: sales at bestpractical.com
> 
> 
> Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
> Buy a copy at http://rtbook.bestpractical.com

###########################################

This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.
For more information, connect to http://www.f-secure.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20080515/85bd87a9/attachment.htm>


More information about the rt-users mailing list