chiark / gitweb /
wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 29 Aug 2012 22:34:22 +0000 (23:34 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 29 Aug 2012 22:34:22 +0000 (23:34 +0100)
.gitignore [new file with mode: 0644]
AwayMsg.pm [new file with mode: 0644]
README [new file with mode: 0644]
config [new file with mode: 0644]
mason/main [new file with mode: 0644]
schema [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..b25c15b
--- /dev/null
@@ -0,0 +1 @@
+*~
diff --git a/AwayMsg.pm b/AwayMsg.pm
new file mode 100644 (file)
index 0000000..468e9f0
--- /dev/null
@@ -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 (<C>) {
+       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 (file)
index 0000000..e69de29
diff --git a/config b/config
new file mode 100644 (file)
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 (file)
index 0000000..de9a0a3
--- /dev/null
@@ -0,0 +1,36 @@
+<%doc>
+<%/doc>
+<%init>
+use AwayMsg;
+<html lang="en"><head>
+<title>Email "out of office" setup</title>
+</head><body>
+<h1>Email "out of office" setup</h1>
+<h2>Our email addresses</h2>
+
+
+<%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");
+</%perl>
+
+<table>
+<tr>
+<td>Address</td>
+<td>O-o-o status</td>
+<td>Which message?</td>
+<td>Expiry date</td>
+</tr><tr>
+% while ($row= $sth->fetchrow_hashref()) {
+<td><% $row->{'emailaddr'} |h %></td>
+%     if (defined $row->{'textid'}) {
+%         my $expiry = expires2timet($row->{'expires'});
+%        if ($expiry > time) {
+<td>active</td>
+<td><% $row->{'textid'} |h %></td>
+<td><% $row->{'expires'} |h %></td>
+<td>
diff --git a/schema b/schema
new file mode 100644 (file)
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
+       );
+