$(ENV_DIR)/www/doc/perl \
$(ENV_DIR)/www/images
install --mode 755 blerg.cgi aux/cgi/*.cgi $(ENV_DIR)/lib/cgi-bin/
- install --mode 755 blergtool blerglatest $(ENV_DIR)/bin/
+ install --mode 755 blergtool blerglatest aux/bin/* $(ENV_DIR)/bin/
install --mode 644 www/favicon.gif www/favicon.ico www/index.html \
www/welcome.html \
$(ENV_DIR)/www/
+#!/usr/bin/perl
+use Blerg::Database;
+use Mail::Message;
+use POSIX qw/strftime/;
+use strict;
+use v5.10;
+
+my $t1 = time;
+my $t0 = $t1 - 86400;
+
+sub send_email {
+ my ($username) = @_;
+
+ if (!Blerg::Database::exists($username)) {
+ return;
+ }
+
+ my $email_conf_path = Blerg::Database::configuration->{data_path} . "/$username/email";
+ if (!-f $email_conf_path) {
+ return;
+ }
+
+ open CONF, $email_conf_path;
+ my $email = <CONF>;
+ close CONF;
+
+ my $blerg = Blerg::Database->open_existing($username);
+ my @items = $blerg->subscription_list;
+ $blerg->close;
+
+ if (!@items) {
+ return;
+ }
+
+ my $feeditems;
+ for my $i (@items) {
+ use Data::Dumper;
+ $blerg = Blerg::Database->open_existing($i->{author})
+ or next;
+
+ my $ts = $blerg->timestamp($i->{record});
+ if ($ts >= $t0 && $ts < $t1) {
+ my $data = $blerg->fetch($i->{record});
+ next if !defined $data;
+ my $date = strftime('%T %b %-d %Y (%Z)', localtime($ts));
+ $feeditems .= "== $i->{author} at $date\n\n$data\n\n\n";
+ }
+
+ $blerg->close;
+ }
+
+ if (!defined $feeditems) {
+ return;
+ }
+
+ Mail::Message->build(
+ From => Mail::Address->new('BlergBot', 'noreply@blerg.cc'),
+ To => Mail::Address->new($username, $email),
+ Subject => 'Blërg Daily Digest',
+ Mail::Message::Field->new('Content-Type', 'text/plain', 'charset="utf8"'),
+ data => <<EMAIL
+Hello, $username! Here is your daily digest:
+
+$feeditems
+- Blërg
+EMAIL
+ )->send;
+}
+
+send_email('bytex64');