commit 83af65ef06a63ecc4549cd293fe9afa75a4bb8b2
parent e1f0d8620b139a1a5c84972c6121e052e4f3a212
Author: Antoine Amarilli <a3nm@a3nm.net>
Date: Wed, 27 Nov 2019 14:50:20 +0100
Merge branch 'master' of a3nm.net:git/mybin
Diffstat:
8 files changed, 58 insertions(+), 80 deletions(-)
diff --git a/find-reminder.sh b/find-reminder.sh
@@ -1,17 +0,0 @@
-#!/bin/bash
-
-ID="$1"
-atq | cut -f1 | while read job;
-do
- FILE=`at -c $job | grep 'reminder-send.sh' | cut -d ' ' -f2`
- if [ -n "$FILE" ]
- then
- if grep "^In-Reply-To: $ID" ~/logs/reminder/$FILE > /dev/null
- then
- echo $job
- fi
- else
- echo "WARNING: no file found for job: $job"
- fi
-done
-
diff --git a/get_email_header b/get_email_header
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+# adapted from https://stackoverflow.com/a/39464990/414272
+
+from email.parser import BytesParser
+from email.header import Header, decode_header
+from email.errors import HeaderParseError
+from sys import argv, stdin
+
+header = argv[1]
+
+# TODO: for some reason this does not work when piping
+message = BytesParser().parse(stdin.buffer)
+try:
+ subj = ''.join([
+ frag.decode(enc if enc else "utf-8")
+ if isinstance(frag, bytes) else frag
+ for frag, enc in decode_header(message[header])])
+except (HeaderParseError, UnicodeDecodeError): # maybe warn about error?
+ subj = message['subject']
+ subj = subj.decode("utf-8") if isinstance(subj, bytes) else subj
+print(subj)
+
+
diff --git a/prepare_email_forward b/prepare_email_forward
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+# adapted from https://stackoverflow.com/a/16509278
+
+import sys
+import os.path as op
+from email.mime.multipart import MIMEMultipart
+from email.mime.base import MIMEBase
+from email.mime.text import MIMEText
+from email.utils import COMMASPACE, formatdate
+from email import encoders
+
+FROM = sys.argv[1]
+TO = sys.argv[2]
+SUBJECT = sys.argv[3]
+IN_REPLY_TO = sys.argv[4]
+FILE = sys.argv[5]
+TEXT = sys.argv[6]
+
+msg = MIMEMultipart()
+msg['From'] = FROM
+msg['To'] = TO
+msg['Date'] = formatdate(localtime=True)
+msg['Subject'] = SUBJECT
+msg['In-Reply-To'] = IN_REPLY_TO
+
+msg.attach(MIMEText(TEXT))
+
+part = MIMEBase('message', "rfc822")
+with open(FILE, 'rb') as file:
+ part.set_payload(file.read())
+encoders.encode_base64(part)
+part.add_header('Content-Disposition', 'inline')
+msg.attach(part)
+
+print (msg.as_string())
diff --git a/reminder-queue.sh b/reminder-queue.sh
@@ -1,9 +0,0 @@
-#!/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
@@ -1,5 +0,0 @@
-#!/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
@@ -1,28 +0,0 @@
-#!/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
@@ -1,12 +0,0 @@
-#!/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
@@ -1,9 +0,0 @@
-#!/usr/bin/zsh
-
-# TODO: sometimes the message-ID is on a separate line after "Message-ID:"
-grep -i '^Message-id' | cut -d ' ' -f2 | while read l;
-do
- echo "Scheduled reminders for $l:"
- atq | grep "^`~/bin/find-reminder.sh $l` "
-done
-