I wrote the following script to handle forwarding the quarantined messages in /opt/zimbra/amavisd-new-2.5.2/quarantine/ that weren't obvious spam

.
Code:
#!/usr/bin/perl -w
#
# send_quarantine.pl
#
# Script to send message caught by Amavis quarantine. Feed the raw message
# into STDIN: ./send_quarantine.pl < virus-EHzL3YEPv56N
#
# Assumptions:
#
# Amavis has added an X-Envelope-From header listing original From address.
# Use it as the From in the SMTP call.
#
# Amavis has added an X-Envelope-To header that breaks out the original To,
# Cc, Bcc, etc. Use it as the To in the SMTP call.
#
# The first Received header marks the beginning of the good RFC822 message
# that will be fed into the SMTP call.
#
# Script is NOT responsible for removing the quarantined message. It just
# feeds it to and SMTP handler, that's it.
#
# Inspired by infect script at http://www.amavis.org/contrib/furio.infect
#
# Jay MacDonald - ThinkTek Solutions
#
# Licensing information: do whatever you want with this script.
# There is no warranty. The author brings no responsibility for
# any problem or damage related with the use of this script.
#
use Net::SMTP;
my $mailhost = "localhost";
my $port = 25;
my $inTo=0;
my $inFrom=0;
my $inMsg=0;
my $From='';
my $ToList='';
my $Subject='';
while ( <> ) {
if ( $inFrom && /^\S/ ) {
# No longer reading an X-Envelope-From header
$inFrom=0;
}
if ( $inTo && /^\S/ ) {
# No longer reading an X-Envelope-To header
$inTo=0;
}
if ( /^X-Envelope-From:\s*(.*)\s*$/ ) {
# Found X-Envelope-From header, start building $From
$inFrom=1;
$From=$1;
}
elsif ( $inFrom && /^\s/ ) {
# Still in X-Envelope-From, keep building $From
s/\s//g;
$From .= $_;
}
elsif ( /^X-Envelope-To:\s*(.*)\s*$/ ) {
# Found X-Envelope-To header, start building $ToList
$inTo=1;
($ToList=$1) =~ s/\s//g;
}
elsif ( $inTo && /^\s/ ) {
# Still in X-Envelope-To, keep building $ToList
s/\s//g;
$ToList .= $_;
}
elsif ( /^Received:\s/ ) {
# Assuming first Received header is where we start the real message
# Start building $msg
$msg=$_;
$inMsg=1;
}
elsif ( $inMsg ) {
if ( /^Subject:\s/ ) {
# A nice to have. Note: doesn't capture multi line header
$Subject = $_;
chomp ($Subject);
}
$msg .= $_;
}
}
if ( $From && $ToList ) {
print "===> From = $From\n";
print "===> ToList = $ToList\n";
print "===> Subject = $Subject\n";
print "\n";
print "===> Sending message:";
# Split the recipients into a list for passing to recipient function
@recipients = split(/,/, $ToList);
# Define the smtp object, build it out and send the message
$smtp = Net::SMTP->new($mailhost, Port => $port);
$smtp->mail($From);
$smtp->recipient(@recipients, { SkipBad => 1 });
$smtp->data();
$smtp->datasend($msg);
$smtp->dataend();
$smtp->quit;
# I never had anything fail, so not sure what would happen. Just send OK.
print " OK\n";
} else {
print "Error: From and ToList not set. Check the message and edit if required\n";
}