#!/usr/bin/perl
use DBI;
require "/etc/mail/mimedefang-filter-greylist";
my $DATABASE="greylist";
my $minute = 60;
my $hour = 60*$minute;
my $day = 24*$hour;

my $gdb_delete = $gdb_grey + (1*$hour);

my $now = time();

my $greylist_dbh = DBI->connect("DBI:mysql:database=$DATABASE","greylist","YOURPASSWORD",
        { RaiseError => 1, AutoCommit => 0 })
        or die $DBI::errstr;

# If it hasn't been modified in the $gdb_delete seconds AND
# it has an accepted time of zero, and it has a count of zero, delete it
my $sql = qq{ DELETE FROM greylist_data
           WHERE accepted = 0 AND count = 0 AND (modified+$gdb_delete) < $now};
my $sth = $greylist_dbh->prepare($sql);

$sth->execute();
$sth->finish();
$greylist_dbh->commit();
$greylist_dbh->disconnect();
print("Deleted " .  $sth->rows . " records.\n");
