--- a/exigrey.pl Wed Jan 03 16:24:32 2007 +0000
+++ b/exigrey.pl Wed Jan 03 16:58:30 2007 +0000
@@ -33,6 +33,8 @@
do "@LIBDIR@/exigrey.pl"
or do "./exim-exigrey.pl" or die $!;
+my $VERSION = '$Id$';
+
my $opt_list;
my $opt_stats;
my $opt_insert;
@@ -66,9 +68,9 @@
my %h;
connectDB(\%h, shift);
iterate(%h, sub {
- my ($item, $v0, $v1, $dv) = @_;
- printf "%-16s:\t$v0 $v1 (%3ds %s %s)\n",
- $item, $dv,
+ my ($item, $v0, $v1, $c) = @_;
+ printf "%-16s:\t$v0 $v1 (%3d %s %s)\n",
+ $item, $c,
strftime("%F %T", localtime($v0)),
strftime("%F %T", localtime($v1));
});
@@ -83,9 +85,9 @@
my ($seen, $returned, $oldest_c, $oldest_u);
$oldest_c = $oldest_u = time();
iterate(%h, sub {
- my ($item, $v0, $v1, $dv) = @_;
+ my ($item, $v0, $v1, $c) = @_;
++$seen;
- ++$returned if $dv;
+ ++$returned if $c;
$oldest_c = $v0 if $v0 < $oldest_c;
$oldest_u = $v1 if $v1 < $oldest_u;
});
@@ -120,7 +122,7 @@
my $tmp = tmpfile();
my $db = connectDB(\%h, $_);
iterate(%h, sub {
- my ($item, $v0, $v1, $dv) = @_;
+ my ($item, $v0, $v1, $c) = @_;
my $rv = defined $opt_purge ? \$v0 : \$v1;
print $tmp "$item\0" if $$rv <= $cut;
});
@@ -154,14 +156,12 @@
}
# Helper to iterate over our hash and call the passed
-# "callback" function (item, v0, v1, delta)
+# "callback" function (item, v0, v1, count)
sub iterate(\%$) {
my ($hash, $sub) = @_;
while (my ($k, $v) = each %$hash) {
chop($k, $v);
- my ($v0, $v1) = split " ", $v;
- my $dv = $v1 - $v0;
- &$sub($k, $v0, $v1, $dv);
+ &$sub($k, (split(" ", $v), 0)[0..2]); # 0 for filling
}
}
--- a/exim-exigrey.pl Wed Jan 03 16:24:32 2007 +0000
+++ b/exim-exigrey.pl Wed Jan 03 16:58:30 2007 +0000
@@ -38,6 +38,7 @@
#
# dbm file is relativ to $spool_directory/grey, EXCEPT its name
# starts with "./" or "/".
+#
sub unseen($;$$) {
my ($item, $delay, $db) = @_;
$item .= "\0";
@@ -51,14 +52,15 @@
$db = connectDB(\%h, $db);
if (not exists $h{$item}) {
- $h{$item} = "$now $now\0";
+ $h{$item} = "$now $now 0\0";
$rc = "yes";
} else {
- my $created = (split " ", $h{$item})[0];
+ my ($created, $used, $count) = split " ", $h{$item}
if ($now - $created < $delay) { $rc = "yes" }
else {
$rc = "no";
- $h{$item} = "$created $now\0";
+ ++$count;
+ $h{$item} = "$created $now $count\0";
}
}
untie %h;