#!/usr/bin/perl
#

my $minute = 60;
my $hour = 60*$minute;
my $day = 24*$hour;

use DB_File;

require ("/etc/mail/mimedefang-filter-greylist");

sub greylist_convert() {
	my %GDB;
	my $now = time();
	my $r = 0;
	if (tie(%GDB,'DB_File','/var/spool/MIMEDefang/.greylistdb')) {
		foreach my $key ( keys %GDB) {
			# key == I:<$p_ip><$p_sender><$p_recipient>
			my $data = $GDB{$key};
			if ($data) {
				my ($created,$modified,$reset,$accepted,$count,$ip,$sender,$recipient,$x) = split(/;/,$data,9);
				$insert_sth->execute(undef,$ip, $sender, $recipient, $created, $modified, $reset, $accepted, $count);
				$r++;
			}
		}
		untie %GDB;
		$insert_sth->finish();
                $greylist_dbh->commit();
		$greylist_dbh->disconnect();
	}
	return $r;
}

my $count = greylist_convert();
print("Converted $count records.\n") if ($count);
