Postgres outbound Quarantine - Catch and Release

Jump to navigation Jump to search

This script was executed when a quarantined email landed in folder monitored by incrontab.

It would create a list of files in the folder whether they were old or new and send an email to the users specified in @mailrcpt. The user would then click on the link provided which would take them to a web page with options to send the mail, delete the mail, or purge and lock the user out of the account if the contents suggest the user had his account hacked. This was to prevent the banning of our email IP by other networks.

#!/usr/bin/perl -w
use strict;
use warnings;
use Net::SMTP;
use Sys::Syslog qw( :DEFAULT :macros );

system("chmod 0777 /var/lib/amavis/virusmails/* -R");

my $qdir="/var/lib/amavis/virusmails";
my @filelist=`ls $qdir`;

if (@filelist){
my @MAIL;
my @mailrcpt=('email1@domain.tld', 'email2@domain.tld');
#my @mailrcpt=('email1@domain.tld');
my $smtp;
my $filename;

my $body="There are suspected SPAM email messages quarantined at /var/lib/amavis/virusmail on server.domain.tld.\n
Below are links to each individual message\n\n";

push(@MAIL, $body);

foreach $filename(@filelist) {
  chomp $filename;
  if ($filename =~ /release$/) { next };
  if ($filename =~ /purge$/) { next };
  push(@MAIL, "http://mailserver.tld:port/cgi-bin/$filename\n");

&dologging("Quarantined files in queue: $filename");

$smtp = Net::SMTP->new('server.domain.tld');
$smtp->datasend("Subject: Quarantined messages on server.domain.tld\n");
 foreach my $mailline (@MAIL) {

sub dologging ($) {
    my $logthis=shift;
    syslog('info', $logthis);