From e5e70b744b88a8acb59e090f653a341cbc1f179e Mon Sep 17 00:00:00 2001 From: justin Date: Thu, 4 Jun 2026 12:33:53 -0500 Subject: [PATCH] Guard bounce watcher against empty queue IDs --- scripts/bounce-watcher.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/bounce-watcher.sh b/scripts/bounce-watcher.sh index 160a53f..890f25a 100644 --- a/scripts/bounce-watcher.sh +++ b/scripts/bounce-watcher.sh @@ -45,7 +45,7 @@ tail -F "$LOG" 2>/dev/null | while IFS= read -r line; do RCPT=$(echo "$line" | sed -n 's/.*to=<\([^>]*\)>.*/\1/p') # Only report if this was a campaign email - if [ -n "$RCPT" ] && [ -n "${CAMPAIGN_QIDS[$QID]+x}" ]; then + if [ -n "$QID" ] && [ -n "$RCPT" ] && [ -n "${CAMPAIGN_QIDS[$QID]+x}" ]; then # Refresh campaign UUID periodically if [ -z "$CURRENT_UUID" ]; then CURRENT_UUID=$(get_campaign_uuid) @@ -68,7 +68,7 @@ tail -F "$LOG" 2>/dev/null | while IFS= read -r line; do QID=$(echo "$line" | sed -n 's/.*postfix\/[a-z]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') RCPT=$(echo "$line" | sed -n 's/.*to=<\([^>]*\)>.*/\1/p') - if [ -n "$RCPT" ] && [ -n "${CAMPAIGN_QIDS[$QID]+x}" ]; then + if [ -n "$QID" ] && [ -n "$RCPT" ] && [ -n "${CAMPAIGN_QIDS[$QID]+x}" ]; then if [ -z "$CURRENT_UUID" ]; then CURRENT_UUID=$(get_campaign_uuid) fi @@ -87,7 +87,9 @@ tail -F "$LOG" 2>/dev/null | while IFS= read -r line; do # Clean up old QIDs when they're removed from queue if echo "$line" | grep -q "removed$"; then QID=$(echo "$line" | sed -n 's/.*postfix\/[a-z]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') - unset CAMPAIGN_QIDS[$QID] 2>/dev/null + if [ -n "$QID" ]; then + unset CAMPAIGN_QIDS[$QID] 2>/dev/null + fi # Refresh campaign UUID every 100 removed messages REMOVED_COUNT=$((${REMOVED_COUNT:-0} + 1)) if [ $((REMOVED_COUNT % 100)) -eq 0 ]; then