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@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
SetTicketPropertiesViaMail - Request Tracker Wiki but I¹m not too
confident with perl to get it work.
My message body looks like this:
Set-CC:john.doe@mycompany.com
Set-CC:marcus.whatever@mycompany.com
Set-CC:brian.surname@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/
The rt-users Archives
Community help: http://wiki.bestpractical.com
Commercial support: sales@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/