From 09f74a7383d50e1613123331ee85c47eb22fd790 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Wed, 14 Aug 2024 20:01:42 +0100 Subject: Update script to use mblaze --- ansible/roles/postfix/files/services/fortune-reply.sh | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'ansible') 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 -- cgit v1.2.3