From: Ian Jackson Date: Thu, 30 Aug 2012 00:19:52 +0000 (+0100) Subject: wip X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=nj-awaymsg.git;a=commitdiff_plain;h=0652dacb9b7ebbdd9c5ec7502ee5a5533a22cdc8 wip --- diff --git a/AwayMsg.pm b/AwayMsg.pm index e20d6b6..4833455 100644 --- a/AwayMsg.pm +++ b/AwayMsg.pm @@ -5,13 +5,15 @@ use strict; use warnings; use DBI; +use Data::Dumper; BEGIN { use Exporter (); our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); - @EXPORT = qw(&db_connect &db_commit $dbh); + @EXPORT = qw(db_connect db_commit expires2timet + $dbh); %EXPORT_TAGS = ( ); @EXPORT_OK = qw(); } @@ -45,10 +47,23 @@ sub nooutput ($) { } } +sub expires2timet ($) { + my ($str) = @_; + if ($str eq '') { + return undef; + } + open F, "-|", qw(date -d),'$str',qw(+%s) or die $!; + my $dtime = ; + $?=0; $!=0; close F or die "$? $!"; + $dtime =~ m/^\d+$/ or die "$dtime ?"; + return $dtime+0; +} sub db_commit () { - nooutput("SELECT * FROM addresses LEFT JOIN config USING (emailaddr)"); - nooutput("SELECT * FROM addresses LEFT JOIN texts USING (textid)"); + nooutput("SELECT * FROM addresses LEFT JOIN config". + " USING (emailaddr) WHERE forwardfile IS NULL"); + nooutput("SELECT * FROM addresses LEFT JOIN texts". + " USING (textid) WHERE name IS NULL"); $dbh->do("COMMIT"); } diff --git a/mason/main b/mason/main index ec7c653..5997c3a 100755 --- a/mason/main +++ b/mason/main @@ -6,39 +6,44 @@ db_connect(); Email "out of office" setup

Email "out of office" setup

-

Our email addresses

+

Email addresses and their configuration

<%perl> my %row; my $sth = $dbh->prepare(< - +
- + +% $sth->execute(); % while (my $row= $sth->fetchrow_hashref()) { % if (defined $row->{'textid'}) { -% my $expiry = expires2timet($row->{'expires'}); -% if ($expiry > time) { - -% } else { +% my $expires = expires2timet($row->{'expires'}); +% if (defined($expires) && $expires < time) { +% } else { + % } - + +% if (defined $expires) { +% } else { + +% } % } else {
AddressO-o-o statusStatus Which message? Expiry date
<% $row->{'emailaddr'} |h %>activeexpiredactive<% $row->{'textid'} |h %><% $row->{'name'} |h %><% $row->{'expires'} |h %>neverinactive