commit 42a8353ee57c5accefaad1e0cbf0f2fb0ed3fd73
parent b32019ce8c8cc9cb2bc4df845824445b5adb3d3b
Author: Antoine Amarilli <a3nm@a3nm.net>
Date: Wed, 18 Oct 2017 10:01:53 +0200
commit ugly reminder stuff
Diffstat:
6 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/find-reminder.sh b/find-reminder.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+ID="$1"
+atq | cut -f1 | while read job;
+do
+ FILE=`at -c $job | grep 'reminder-send.sh' | cut -d ' ' -f2`
+ if grep "^In-Reply-To: $ID" ~/logs/reminder/$FILE > /dev/null
+ then
+ echo $job
+ fi
+done
+
diff --git a/reminder-queue.sh b/reminder-queue.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/zsh
+
+NAME=$({date +%s; echo --; basename `mktemp`} | tr -d '\n')
+cat > ~/logs/reminder/$NAME.origmail
+cat ~/logs/reminder/$NAME.origmail | ~/bin/reminder.pl > ~/logs/reminder/$NAME
+echo "$NAME `date +%s` $@" >> ~/logs/reminders
+(echo "reminder-send.sh $NAME" | at "$@" 2>> ~/logs/reminders) \
+ && echo "Queued reminder $NAME for $@"
+
diff --git a/reminder-send.sh b/reminder-send.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+cat ~/logs/reminder/$1 | /usr/sbin/sendmail -t
+mv ~/logs/reminder/$1 ~/logs/reminder/sent
+
diff --git a/reminder.pl b/reminder.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+my $subject, $msgid, $body = 0;
+
+while (<>) {
+ if ($body) {
+ print;
+ next;
+ }
+ chop;
+ if (/^Subject: (.*)$/) {
+ $subject = $1;
+ }
+ if (/^Message-[Ii][Dd]: (.*)$/) {
+ $msgid = $1;
+ }
+ if (/^$/) {
+ if (!$body) {
+ print "From: Reminder <a3nm\@localhost>\n";
+ print "To: Antoine Amarilli <a3nm\@localhost>\n";
+ print "Subject: PING $subject\n";
+ print "In-Reply-To: $msgid\n";
+ print "\n";
+ $body = 1;
+ }
+ }
+}
+
diff --git a/remove-reminder.sh b/remove-reminder.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+set -x
+grep -i '^Message-id' | cut -d ' ' -f2 | while read l;
+do
+ echo "will delete"
+ ~/bin/find-reminder.sh $l
+ echo "last chance to abort..."
+ sleep 2
+ atrm `~/bin/find-reminder.sh $l | cut -f1`
+ #TODO remove the files from ~/logs/reminders
+done
diff --git a/show-reminder.sh b/show-reminder.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/zsh
+
+grep -i '^Message-id' | cut -d ' ' -f2 | while read l;
+do
+ echo "Scheduled reminders for $l:"
+ atq | grep "^`~/bin/find-reminder.sh $l` "
+done
+