From 2b4b3458493f6134d91065512a14948e759f8d41 Mon Sep 17 00:00:00 2001 From: short <> Date: Fri, 11 Oct 2002 13:54:30 +0000 Subject: [PATCH] +Option --clean [[print:]]: drops old mails --- perlmail-submit | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/perlmail-submit b/perlmail-submit index 8025a78..43d3fdc 100755 --- a/perlmail-submit +++ b/perlmail-submit @@ -152,6 +152,43 @@ sub pending } } +sub clean +{ +my($keyword,$interval)=@_; + + # FIXME: SQL "now()" is raced against the block above + my $sth=$DBI->prepare("select id,time,retries from $DB_table where time>now()"); + $sth->execute(); + while (my $row=$sth->fetchrow_hashref()) { + warn "Message time in future: ".join(",",map( + "$_=".(!defined $row->{$_} ? "NULL" : $row->{$_}) + ,keys(%$row))); + } + + return if $interval eq ""; + local $_=$interval; + my $print=s/^print://; + s/(\d+)y/($1*12)."m"/ge; + s/(\d+)m/($1*30)."d"/ge; + s/(\d+)d/($1*24)."h"/ge; + s/(\d+)h/($1*60)."M"/ge; + s/(\d+)M/($1*60)."s"/ge; + my $sec=0; + $sec+=$1 while s/(\d+)s//g; + die "Interval parse error; left \"$_\", parsed: $interval" if $_ ne ""; + $sth=$DBI->prepare(($print ? "select id" : "delete") + ." from $DB_table where timeexecute(); + if (!$print) { + print $sth->rows()."\n"; + } + else { + while (my $row=$sth->fetchrow_hashref()) { + print $row->{"id"},"\n"; + } + } +} + $Getopt::Long::ignorecase=0; die if !GetOptions( @@ -159,6 +196,7 @@ die if !GetOptions( "store" ,\&store, "submit" ,\&submit, "pending",\&pending, + "clean:s",\&clean, "V|version",sub { print "lacemail-submit: $VERSION\n"; exit 0; }, ); exit 0; -- 1.8.3.1