aboutsummaryrefslogtreecommitdiffstats
path: root/ansible
diff options
context:
space:
mode:
authorGravatar Johannes Christ <[email protected]>2024-09-02 20:25:31 +0200
committerGravatar Joe Banks <[email protected]>2024-09-03 10:43:39 +0100
commitee27b437ce1dea269aa213c11f5ce54bb55f0951 (patch)
tree3a4d3163e87d5145aeac2a824a009c64d5397c49 /ansible
parentInclude sender date as a unix timestamp (diff)
Delay Fredrick vacation script replies by 10 minutes
Untested. We should expand this (later) such that when an e-mail is sent outside of Fredrick's regular working hours, the script (like Fredrick) needs more time to get back to you, since he needs to practice his Qi.
Diffstat (limited to 'ansible')
-rw-r--r--ansible/roles/postfix/tasks/main.yml1
-rw-r--r--ansible/roles/postfix/templates/services/fredrick-reply.sh.j221
2 files changed, 21 insertions, 1 deletions
diff --git a/ansible/roles/postfix/tasks/main.yml b/ansible/roles/postfix/tasks/main.yml
index ac476e0..b708dbd 100644
--- a/ansible/roles/postfix/tasks/main.yml
+++ b/ansible/roles/postfix/tasks/main.yml
@@ -13,6 +13,7 @@
- postfix-policyd-spf-python
# Mail scripting utilities
- mblaze
+ - at
state: present
tags:
- role::postfix
diff --git a/ansible/roles/postfix/templates/services/fredrick-reply.sh.j2 b/ansible/roles/postfix/templates/services/fredrick-reply.sh.j2
index 0bfbf01..f4ef663 100644
--- a/ansible/roles/postfix/templates/services/fredrick-reply.sh.j2
+++ b/ansible/roles/postfix/templates/services/fredrick-reply.sh.j2
@@ -50,6 +50,16 @@ FRED_RESPONSE=$(curl -X POST "$FREDRICK_ENDPOINT" \
# Fredrick likes to try add a Subject: line on sometimes
FILTERED=$(echo "$FRED_RESPONSE" | grep -v "^Subject:")
+# Path where scheduled replies are stored
+REPLIES_PATH=/var/tmp/fredrick-vacation-replies
+
+if [ ! -d "$REPLIES_PATH" ]; then
+ # -p is to prevent race conditions from concurrent script runs
+ mkdir -p "$REPLIES_PATH"
+fi
+
+REPLY_PATH=$(mktemp --tmpdir="$REPLIES_PATH" --suffix=.eml)
+
(
echo "Subject: $REPLY_SUBJECT"
echo "From: Fredrick <[email protected]>"
@@ -63,4 +73,13 @@ FILTERED=$(echo "$FRED_RESPONSE" | grep -v "^Subject:")
# Quote the original message
echo "On $MESSAGE_DATE, $SENDER_DISPLAY_NAME wrote:"
echo "$BODY" | awk -F '\n' '{ print "> " $1 }'
-) | /usr/sbin/sendmail -t
+) > "$REPLY_PATH"
+
+ATSCRIPT=$(mktemp --suffix=fredrick-atscript.sh)
+
+cat > "$ATSCRIPT" <<EOF
+/usr/sbin/sendmail -t < "$REPLY_PATH"
+rm "$REPLY_PATH"
+EOF
+
+at -f "$ATSCRIPT" now + 10 min