Skip to content

Commit f520fd8

Browse files
committed
Add condition to remove temp email file based on REMOVE_TEMP_EMAIL variable.
1 parent 31c6ab8 commit f520fd8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

postfix/usr/local/bin/mailparse.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ KINESIS_REGION="${KINESIS_REGION:-}"
1515
WEBHOOK_URL="${WEBHOOK_URL:-}"
1616
FORWARD_EMAIL="${FORWARD_EMAIL:-}"
1717
DOMAIN_FILTER="${DOMAIN_FILTER:-msg.domaineasy.com}"
18+
REMOVE_TEMP_EMAIL="${REMOVE_TEMP_EMAIL:-true}"
1819

1920
# Log the incoming email for debugging purposes
2021
echo "Email received at $(date)"
@@ -36,15 +37,21 @@ echo "Received an email from: $from to $to with subject: $subject"
3637
# Check if the 'To' field matches the specified domain
3738
if [ -n "$DOMAIN_FILTER" ] && ! grep -iq "^To:.*@$DOMAIN_FILTER" "$TEMP_EMAIL_FILE"; then
3839
echo "Email does not match the 'To' domain '$DOMAIN_FILTER'. Ignoring."
39-
rm -f "$TEMP_EMAIL_FILE"
40+
41+
# Conditionally remove the temp email file based on the REMOVE_TEMP_EMAIL variable
42+
if [ "$REMOVE_TEMP_EMAIL" = "true" ]; then
43+
rm -f "$TEMP_EMAIL_FILE"
44+
fi
4045
exit 0
4146
fi
4247

4348
# Read the entire email content
4449
email_content=$(cat "$TEMP_EMAIL_FILE")
4550

46-
# Cleanup: remove the temporary email file as soon as possible
47-
rm -f "$TEMP_EMAIL_FILE"
51+
# Cleanup: Conditionally remove the temporary email file
52+
if [ "$REMOVE_TEMP_EMAIL" = "true" ]; then
53+
rm -f "$TEMP_EMAIL_FILE"
54+
fi
4855

4956
# Function to send email to Kinesis
5057
send_to_kinesis() {

0 commit comments

Comments
 (0)