From fa1084e8d681187707259ed712f6d5d5c7b99526 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 29 Aug 2012 23:34:22 +0100 Subject: [PATCH] wip --- .gitignore | 1 + AwayMsg.pm | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ README | 0 config | 2 ++ mason/main | 36 ++++++++++++++++++++++++++++++++++++ schema | 14 ++++++++++++++ 6 files changed, 101 insertions(+) create mode 100644 .gitignore create mode 100644 AwayMsg.pm create mode 100644 README create mode 100644 config create mode 100644 mason/main create mode 100644 schema diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b25c15b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/AwayMsg.pm b/AwayMsg.pm new file mode 100644 index 0000000..468e9f0 --- /dev/null +++ b/AwayMsg.pm @@ -0,0 +1,48 @@ +module AwayMsg; + +package AwayMsg; +use strict; +use warnings; + +BEGIN { + use Exporter (); + our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); + $VERSION = 1.00; + @ISA = qw(Exporter); + @EXPORT = qw(&db_connect $dhb); + %EXPORT_TAGS = ( ); + @EXPORT_OK = qw(); +} + +sub db_connect () { + my $h = DBI->connect("dbi:SQLite:away.db", + { AutoCommit=>0, + RaiseError=>1, ShowErrorStatement=>1 + }) + or die "$DBI:errstr ?"; + + $dbh->do("BEGIN"); + + $dbh->do("CREATE TEMPORARY TABLE config (". + " emailaddr TEXT PRIMARY KEY NOT NULL,". + " username TEXT NOT NULL,". + " forwardfile TEXT NOT NULL". + ")"); + + open C, "config" or die $!; + while () { + s/^\s+//; + next if m/^\#/; + chomp or die; + s/\s+$//; + my @s = split; + die "$_ ?" unless @s==3; + $dbh->do("INSERT INTO config". + " (emailaddr, username, forwardfile)". + " VALUES (?,?,?)", + {}, @s); + } + $dbh->do("COMMIT"); + + return $h; +} diff --git a/README b/README new file mode 100644 index 0000000..e69de29 diff --git a/config b/config new file mode 100644 index 0000000..58e8495 --- /dev/null +++ b/config @@ -0,0 +1,2 @@ +nj@hemmel.com nickj .forward +nj@cumbriancef.com nickj .forward diff --git a/mason/main b/mason/main new file mode 100644 index 0000000..de9a0a3 --- /dev/null +++ b/mason/main @@ -0,0 +1,36 @@ +<%doc> +<%/doc> +<%init> +use AwayMsg; + +Email "out of office" setup + +

Email "out of office" setup

+

Our email addresses

+ + +<%perl> +my %row; +my $sth = $dbh->prepare("SELECT emailaddr, textid, expires" + " FROM schema + " RIGHT JOIN addresses USING (emailaddr)". + " JOIN texts USING (textid)", + " ORDER BY emailaddr"); + + + + + + + + + +% while ($row= $sth->fetchrow_hashref()) { + +% if (defined $row->{'textid'}) { +% my $expiry = expires2timet($row->{'expires'}); +% if ($expiry > time) { + + + +
AddressO-o-o statusWhich message?Expiry date
<% $row->{'emailaddr'} |h %>active<% $row->{'textid'} |h %><% $row->{'expires'} |h %> diff --git a/schema b/schema new file mode 100644 index 0000000..eb2ffb8 --- /dev/null +++ b/schema @@ -0,0 +1,14 @@ + +CREATE TABLE texts ( + textid INTEGER PRIMARY KEY NOT NULL, + name TEXT NOT NULL, + subject TEXT NOT NULL, + text TEXT NOT NULL, + expires TEXT + ); + +CREATE TABLE addresses ( + emailaddr TEXT PRIMARY KEY NOT NULL, + textid INTEGER + ); + -- 2.30.2