Moving to Spam Queue but old Scrips are still triggered

Good Nighttime,
I’m using Requesttracker 4.4.x to handle the ingoing requests. Filtering out spam is done by SpamAssassin, which adds the score into the header of the e-mail. I’m planing to use this information to move all e-mails/tickets above a given score to the spam queue.

Setup:

  1. A new queue called Spam was created.
  2. All Scrips that send out E-Mails on the global level have been removed from the Spam queue
  3. A Scrip with the following configuration has been created

Condition:

return 0 unless $self->TransactionObj->Type eq "Create";
return 0 if $self->TicketObj->QueueObj->Name eq "Spam";
return 1;

Preparation:

my $spamscore = 5;
my $match     = '\*' x $spamscore;
my $inMessage = $self->TransactionObj->Attachments->First;
return 0 if ( !$inMessage );
return 0 if ( !$inMessage->GetHeader('Received') );
my $spamLevel = $inMessage->GetHeader('X-Spam-Level');

my $spam = ( $spamLevel !~ /$match/i ) ? 0 : 1;

if ($spam) {
    my $newqueue = 'Spam';
    $self->TicketObj->SetQueue($newqueue);
    $self->TicketObj->SetStatus('rejected');
}
return 1;

Cleanup:

my $score = $self->TransactionObj->Attachments->First->GetHeader('X-Spam-Score');
unless ($score) {
    my $t =$self->TransactionObj->Attachments->First > GetHeader('X-Spam-Status');
    $t = ~/score=(-?\d+(|:.\d+)?)/ && ( $score = $1 );
}

$self->TicketObj->DeleteWatcher( Type => 'Requestor' );
$self->TicketObj->DeleteWatcher( Type => 'Cc' );
$self->TicketObj->DeleteWatcher( Type => 'AdminCC' );
$self->TicketObj->DeleteWatcher( Type => 'Owner' );
$self->TicketObj->SetPriority( -int($score) ) if $score;

return 1;

Problem:
After sending the GTUBE Test-Mail the e-mail is still send out to the AdminCC with the wrong queue in the subject. If I’m looking the ticket up into the webinterface the actions are successfully performed.

How can I adjust this scrip to prevent outgoing e-mails in case of detected spam?

Thank you in advance!

$self->TicketObj->DeleteWatcher( Type => ‘AdminCC’ );

Does this work or should the field be ‘AdminCc’?

It neither works with the changed upper/lowercase, nor if it remove those statements alltogether

Is this scrip attached to the non-spam queue? Does that queue have scrips that can email still, and if so, are any running before this scrip does?

The scrip is attached to all queues with the highest priority in the overview and namend 00000 Move to Spam. Every other scrip has a a higher number than this one.

Yeah, I think unfortunately this is the way it works. If you turn on debugging and watch the logs while the ticket is created, you’ll see the recipients are calculated before the scrip is ran.

Personally I’d handle this before RT got the email.