Hi all,
is there an OTRS feature which would be able to bouce every new mail,
which ends in specific queue? I have script which was doing that in
previous version of OTRS, but it seems, that it's not compatible with
OTRS version 2.x. Can someone help debug it - see attached file.
TIA,
--alexm
#!/usr/bin/perl -w
use lib ("/opt/otrs/" , "/opt/otrs/Kernel/cpan-lib/");
use Kernel::Config;
use Kernel::System::Log;
use Kernel::System::DB;
use Kernel::System::Ticket;
use Kernel::System::User;
use Data::Dumper;
my $ConfigObject = Kernel::Config->new();
my $LogObject = Kernel::System::Log->new(
ConfigObject => $ConfigObject,
);
my $DBObject = Kernel::System::DB->new(
ConfigObject => $ConfigObject,
LogObject => $LogObject,
);
my $TimeObject = Kernel::System::Time->new(
ConfigObject => $ConfigObject,
);
my $TicketObject = Kernel::System::Ticket->new(
ConfigObject => $ConfigObject,
LogObject => $LogObject,
DBObject => $DBObject,
TimeObject => $TimeObject,
);
my $UserObject = Kernel::System::User->new(
ConfigObject => $ConfigObject,
LogObject => $LogObject,
DBObject => $DBObject,
);
my $user_id = $UserObject->GetUserIdByName(User=>'[EMAIL PROTECTED]');
my $ticket_num; #=$ARGV[0];
my $ticket_id; #=$ARGV[1] || 0;
my @AllTicketIDs;
sub bounce {
my ($ticket_id,$article)[EMAIL PROTECTED];
#my $ticket_id=shift @_;
$ticket_num=0;
if (!$ticket_num) { # We only got a ticket ID
$ticket_num=$TicketObject->TicketNumberLookup(TicketID=>$ticket_id);
}
# check how many articles ticket has
my @ArticleIDs = $TicketObject->ArticleIndex(
TicketID => $ticket_id
);
if (@ArticleIDs <= 1) { # Let's see if it's a new mail or followup
$subject='[BLA #: '.$ticket_num.'] '.$article{Subject};
} else {
$subject=$article{Subject};
}
# check if article has attachments
my %AttachIndex = $TicketObject->ArticleAttachmentIndex(
ArticleID => $article{ArticleID},
FileID => 1
);
my @test = sort keys %AttachIndex;
# collect parameters for bouncing mail
%ArticleSendParams=(TicketID=>$ticket_id,
From=>$article{From},
To=>$article{To},
Subject =>$subject,
Cc =>$article{Cc},
Bcc =>'[EMAIL PROTECTED]',
Body =>$article{Body},
UserID=>$user_id,
Loop =>1,
ArticleType =>'email-external',
SenderType =>'system',
HistoryComment =>'AutoForward to [EMAIL PROTECTED]',
HistoryType =>'Forward');
#print $ArticleSendParams;
if (@test) { # if article has attachments, add them to the parameters for
bouncing mail
foreach $key (@test) {
my %Attach = $TicketObject->ArticleAttachment(
ArticleID =>
$article{ArticleID},
FileID => $key);
$rA = \%Attach;
%ATS=('Content' => $$rA{"Content"},'ContentType' =>
$$rA{"ContentType"}, 'Filename' => $$rA{"Filename"});
push(@ATS,{%ATS});
$ArticleSendParams{'Attach'[EMAIL PROTECTED];
}
}
#print $ArticleSendParams;
#print Dumper(\%ArticleSendParams);
#print Dumper([EMAIL PROTECTED]);
#print Dumper([EMAIL PROTECTED]);
# send bouncing mail
$TicketObject->ArticleSend(%ArticleSendParams);
# change ticket status from new to open
$TicketObject->StateSet(TicketID=>$ticket_id,
UserID=>$user_id,
State=>'open');
=item
$TicketObject->ArticleSend(
TicketID=>$ticket_id,
From=>$article{From},
To=>'[EMAIL PROTECTED]',
Subject =>$subject,
Body => $article{Body},
UserID=>$user_id,
Loop => 1,
ArticleType => 'email-external',
SenderType => 'system',
HistoryComment => 'AutoForward to [EMAIL PROTECTED]',
HistoryType => 'Forward');
$TicketObject->StateSet(TicketID=>$ticket_id,
UserID=>$user_id,
State=>'open');
$TicketObject->MoveTicket(TicketID=>$ticket_id,
Queue=>'important_queue',
UserID=>1);
=cut
}
# find new tickets or new followups in queue important_queue
@AllTicketIDs = $TicketObject->TicketSearch(
Result => 'ARRAY',
Limit => 10000,
Queues =>
['important_queue'],
States => ['new'],
UserID=>1);
foreach $ticket_id (@AllTicketIDs) {
%article=$TicketObject->ArticleLastCustomerArticle(TicketID=>$ticket_id);
#print($article{ArticleID});
bounce($ticket_id,$article{ArticleID});
}
_______________________________________________
OTRS mailing list: dev - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/dev
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/dev