From 8b294424211f992a399bc48919b4f868c23530b9 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 30 Aug 2012 01:40:36 +0100 Subject: [PATCH] wip --- AwayMsg.pm | 16 +++++++++++++--- mason/main | 44 ++++++++++++++++++++++++++++++++------------ schema | 2 +- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/AwayMsg.pm b/AwayMsg.pm index 4833455..d6f63a5 100644 --- a/AwayMsg.pm +++ b/AwayMsg.pm @@ -12,7 +12,8 @@ BEGIN { our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); - @EXPORT = qw(db_connect db_commit expires2timet + @EXPORT = qw(db_connect db_commit + expires2timet expirestime2show $dbh); %EXPORT_TAGS = ( ); @EXPORT_OK = qw(); @@ -49,7 +50,7 @@ sub nooutput ($) { sub expires2timet ($) { my ($str) = @_; - if ($str eq '') { + if ($str eq '' or $str =~ m/never/i) { return undef; } open F, "-|", qw(date -d),'$str',qw(+%s) or die $!; @@ -59,11 +60,20 @@ sub expires2timet ($) { return $dtime+0; } +sub expirestime2show ($) { + my ($tt) = @_; + if (!defined $tt) { + return 'never'; + } else { + return strftime("%Y-%m-%d %H:%M"); + } +} + sub db_commit () { 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"); + " USING (textid) WHERE desc IS NULL"); $dbh->do("COMMIT"); } diff --git a/mason/main b/mason/main index 5997c3a..e8c29e6 100755 --- a/mason/main +++ b/mason/main @@ -1,25 +1,24 @@ <%init> use AwayMsg; db_connect(); +my ($sth,$row,$sthi,$rowi); Email "out of office" setup

Email "out of office" setup

-

Email addresses and their configuration

- +

Email addresses and their configuration

<%perl> -my %row; -my $sth = $dbh->prepare(<prepare(<execute(); - @@ -27,7 +26,6 @@ END -% $sth->execute(); % while (my $row= $sth->fetchrow_hashref()) { @@ -38,12 +36,8 @@ END % } else { % } - -% if (defined $expires) { - -% } else { - -% } + + % } else { @@ -52,3 +46,29 @@ END % }
AddressWhich message? Expiry date
<% $row->{'emailaddr'} |h %>active<% $row->{'name'} |h %><% $row->{'expires'} |h %>never<% $row->{'desc'} |h %><% expirestime2show($expires) |h %>inactive
+ +

Outbound messages

+<%perl> +$sth = $dbh->prepare("SELECT * FROM texts ORDER BY desc"); +$sthi = $dbh->prepare(<execute(); + +% while (my $row= $sth->fetchrow_hashref()) { +

Message "<% $row->{'desc'} |h %>"

+ + + + + +
Short name:<% $row->{'desc'} |h %>
Expires:<% + expirestime2show(expires2timet($row->{'expires'})) + |h %>
Subject:<% $row->{'subject'} |h %>
+

+

+<% $row->{'text'} |h %>
+
+% } diff --git a/schema b/schema index aaeb0d9..afcda29 100644 --- a/schema +++ b/schema @@ -1,7 +1,7 @@ CREATE TABLE texts ( textid INTEGER PRIMARY KEY NOT NULL, - name TEXT NOT NULL, + desc TEXT NOT NULL, subject TEXT NOT NULL, text TEXT NOT NULL, expires TEXT NOT NULL -- 2.30.2