X-Git-Url: https://git.jankratochvil.net/?a=blobdiff_plain;f=perlmail-submit;h=9de0b905828147a2399f51e599a34cfb841a1135;hb=de1c9a00bd2e44398aceb28d583cd5e3d8b80a36;hp=2901153700e7d1fc56ca3791c8b9391be9573ed5;hpb=b68782d3f8bca18eb93a2abf167541986decedfc;p=PerlMail.git diff --git a/perlmail-submit b/perlmail-submit index 2901153..9de0b90 100755 --- a/perlmail-submit +++ b/perlmail-submit @@ -17,8 +17,9 @@ use Fcntl qw(:flock); my $Lock_pathname="/tmp/LaceMail.lock"; -my $PeerAddr="dejhome.dyn.jankratochvil.net.:852"; -my $Socket_timeout=15; +#my $PeerAddr="dejhome.dyn.jankratochvil.net.:852"; +my $PeerAddr="127.0.0.1:2852"; +my $Socket_timeout=7600; # 15sec is NOT enough! my $DB_table="LaceMail_folder"; my $DBI_database="short"; my $DBI_user="short"; @@ -65,6 +66,7 @@ sub store local $/; $message=; } + close STDIN or cluck "close STDIN: $!"; my %row=( "message"=>$message, # assume "retries"=>0, @@ -75,6 +77,14 @@ sub store print $prep->{"mysql_insertid"}."\n"; } +sub forkoff +{ + my $pid=fork(); + confess if !defined $pid; + exit 0 if $pid; # parent + # child +} + my $submitonce_run=0; sub submitonce { @@ -140,20 +150,59 @@ sub submit sub pending { - my $sth=$DBI->prepare("select message from $DB_table where state='pending' order by id"); + my $sth=$DBI->prepare("select message from $DB_table where retries is not null order by id"); $sth->execute(); while (my $row=$sth->fetchrow_hashref()) { print $row->{"message"},"\n"; } } +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 retries is null and 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( "initdb" ,\&initdb, "store" ,\&store, + "forkoff",\&forkoff, "submit" ,\&submit, "pending",\&pending, + "clean:s",\&clean, "V|version",sub { print "lacemail-submit: $VERSION\n"; exit 0; }, ); exit 0;