aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2024-08-14 20:01:42 +0100
committerGravatar Joe Banks <[email protected]>2024-08-14 20:02:35 +0100
commit09f74a7383d50e1613123331ee85c47eb22fd790 (patch)
tree2343c28908f6f7198c07190ad958a9ca13c8e19b
parentAdd fortune reply script (diff)
Update script to use mblaze
-rwxr-xr-xansible/roles/postfix/files/services/fortune-reply.sh16
1 files changed, 5 insertions, 11 deletions
diff --git a/ansible/roles/postfix/files/services/fortune-reply.sh b/ansible/roles/postfix/files/services/fortune-reply.sh
index 6dbfe9b..97f2ce8 100755
--- a/ansible/roles/postfix/files/services/fortune-reply.sh
+++ b/ansible/roles/postfix/files/services/fortune-reply.sh
@@ -4,31 +4,25 @@
EMAIL=$(cat)
# Extract the sender's email address
-SENDER=$(echo "$EMAIL" | grep -i "^From:" | head -n 1 | sed -E 's/.*<([^>]+)>.*/\1/;t;s/^From:[[:space:]]*//')
-
-# Filter for invalid emails or attempted spoofs that were injected into the From header
-if ! echo "$SENDER" | grep -qE '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$'; then
- echo "Attempted spoof detected, quitting."
- exit 1
-fi
+SENDER=$(echo "$EMAIL" | maddr -a -h from -)
# Extract the Message-ID of the original email
-MESSAGE_ID=$(echo "$EMAIL" | grep -i "^Message-ID:" | head -n 1 | awk '{print $2}')
+MESSAGE_ID=$(echo "$EMAIL" | mhdr -h message-id -)
# Extract the original Subject and prefix it with "Re: " if necessary
-ORIGINAL_SUBJECT=$(echo "$EMAIL" | grep -i "^Subject:" | head -n 1 | sed -E 's/Subject: (Re: )?(.+)/\2/')
+ORIGINAL_SUBJECT=$(echo "$EMAIL" | mhdr -h subject -)
# Construct the reply subject
REPLY_SUBJECT="Re: $ORIGINAL_SUBJECT"
# Extract the To address
-TO_ADDRESS=$(echo "$EMAIL" | grep -i "^To:" | sed -E 's/To: (.*)/\1/')
+TO_ADDRESS=$(echo "$EMAIL" | maddr -a -h to -)
# Generate the fortune output
if [[ "$TO_ADDRESS" =~ "fortune+cowsay" ]]; then
FORTUNE_OUTPUT=$(/usr/games/fortune | /usr/games/cowsay)
else
- FORTUNE_OUTPUT=$(/usr/games/fortune)
+ FORTUNE_OUTPUT=$(/usr/games/fortune)
fi
# Send a reply with the proper headers