Skip to content

Commit

Permalink
Add condition to remove temp email file based on REMOVE_TEMP_EMAIL va…
Browse files Browse the repository at this point in the history
…riable.
  • Loading branch information
nsouto committed Sep 11, 2024
1 parent 31c6ab8 commit f520fd8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions postfix/usr/local/bin/mailparse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ KINESIS_REGION="${KINESIS_REGION:-}"
WEBHOOK_URL="${WEBHOOK_URL:-}"
FORWARD_EMAIL="${FORWARD_EMAIL:-}"
DOMAIN_FILTER="${DOMAIN_FILTER:-msg.domaineasy.com}"
REMOVE_TEMP_EMAIL="${REMOVE_TEMP_EMAIL:-true}"

# Log the incoming email for debugging purposes
echo "Email received at $(date)"
Expand All @@ -36,15 +37,21 @@ echo "Received an email from: $from to $to with subject: $subject"
# Check if the 'To' field matches the specified domain
if [ -n "$DOMAIN_FILTER" ] && ! grep -iq "^To:.*@$DOMAIN_FILTER" "$TEMP_EMAIL_FILE"; then
echo "Email does not match the 'To' domain '$DOMAIN_FILTER'. Ignoring."
rm -f "$TEMP_EMAIL_FILE"

# Conditionally remove the temp email file based on the REMOVE_TEMP_EMAIL variable
if [ "$REMOVE_TEMP_EMAIL" = "true" ]; then
rm -f "$TEMP_EMAIL_FILE"
fi
exit 0
fi

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

# Cleanup: remove the temporary email file as soon as possible
rm -f "$TEMP_EMAIL_FILE"
# Cleanup: Conditionally remove the temporary email file
if [ "$REMOVE_TEMP_EMAIL" = "true" ]; then
rm -f "$TEMP_EMAIL_FILE"
fi

# Function to send email to Kinesis
send_to_kinesis() {
Expand Down

0 comments on commit f520fd8

Please sign in to comment.