#!/usr/bin/perl -w

use strict;

my $QUARANTINE_DIR = "/etc/mail/spasm/quarantine";
my $MAX_DAYS = 21;
my $FIND = "/usr/bin/find";

my $MAX_SECONDS = $MAX_DAYS * 24 * 60 * 60;
my $CUR_SECONDS = time;

opendir(QDIR, $QUARANTINE_DIR) or die;
my @domains = readdir(QDIR);
closedir(QDIR);

for my $dom (@domains) {
    next if($dom =~ /^\./);
    opendir(DDIR, "$QUARANTINE_DIR/$dom") or die;
    my @qfiles = readdir(DDIR);
    closedir(DDIR);
    for my $qfile (@qfiles) {
        next if($qfile =~ /^\./);
        my @stats = stat("$QUARANTINE_DIR/$dom/$qfile");
        if($CUR_SECONDS - $stats[9] > $MAX_SECONDS) {
            unlink("$QUARANTINE_DIR/$dom/$qfile");
        }
    }
}
