From 7be2f3bf93b30ecb0dd4555d579cca336050fb53 Mon Sep 17 00:00:00 2001 From: cschantz Date: Wed, 31 Dec 2025 19:16:27 -0500 Subject: [PATCH] Fix bounce detection to exclude successful deliveries - Exclude lines with 'saved mail to' (successful deliveries) - Exclude lines with '=>' (delivery confirmations) - Only show actual bounce/failure messages - Updated both counting and display sections This fixes the bounce section showing 'saved mail to INBOX' which are actually successful deliveries, not bounces. --- modules/email/email-diagnostics.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/email/email-diagnostics.sh b/modules/email/email-diagnostics.sh index e8a1e47..e405a0e 100755 --- a/modules/email/email-diagnostics.sh +++ b/modules/email/email-diagnostics.sh @@ -159,8 +159,8 @@ delivered=$(grep -ci "=> .*$search_pattern\|delivered.*$search_pattern" "$TEMP_M delivered=$(echo "$delivered" | head -1 | tr -d '\n\r') sent=$(grep -ci "<=.*$search_pattern" "$TEMP_MATCHES" 2>/dev/null || echo 0) sent=$(echo "$sent" | head -1 | tr -d '\n\r') -# Only count actual email bounces, not auth failures -bounced=$(grep -i "$search_pattern" "$TEMP_MATCHES" | grep -v "authenticator failed\|Authentication failed" | grep -ci "550\|551\|552\|553\|554\|bounced\|Mail delivery failed" 2>/dev/null || echo 0) +# Only count actual email bounces, not auth failures or successful deliveries +bounced=$(grep -i "$search_pattern" "$TEMP_MATCHES" | grep -v "authenticator failed\|Authentication failed\|saved mail to\|=>" | grep -ci "550\|551\|552\|553\|554\|bounced\|Mail delivery failed\|** " 2>/dev/null || echo 0) bounced=$(echo "$bounced" | head -1 | tr -d '\n\r') deferred=$(grep -ci "deferred.*$search_pattern\|retry.*$search_pattern\|temporarily rejected" "$TEMP_MATCHES" 2>/dev/null || echo 0) deferred=$(echo "$deferred" | head -1 | tr -d '\n\r') @@ -511,7 +511,7 @@ if [ "$bounced" -gt 0 ]; then echo "" print_warning "PROOF - These emails failed delivery:" echo "" - grep -i "$search_pattern" "$TEMP_MATCHES" | grep -v "authenticator failed\|Authentication failed" | grep -i "550\|551\|552\|553\|554\|bounced\|Mail delivery failed" | tail -5 | while read line; do + grep -i "$search_pattern" "$TEMP_MATCHES" | grep -v "authenticator failed\|Authentication failed\|saved mail to\|=>" | grep -i "550\|551\|552\|553\|554\|bounced\|Mail delivery failed\|** " | tail -5 | while read line; do timestamp=$(echo "$line" | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}|[A-Z][a-z]{2} [0-9]+ [0-9]{2}:[0-9]{2}:[0-9]{2}' | head -1) if [ -n "$timestamp" ]; then echo -e " ${RED}[$timestamp]${NC} $line" @@ -524,7 +524,7 @@ if [ "$bounced" -gt 0 ]; then # Extract bounce reasons print_header "COMMON BOUNCE REASONS" echo "" - grep -i "$search_pattern" "$TEMP_MATCHES" | grep -v "authenticator failed\|Authentication failed" | grep -i "550\|551\|bounced" | grep -oE "550 [^:]*|551 [^:]*|User unknown|Mailbox.*full|Relay.*denied|No such user" | sort | uniq -c | sort -rn | head -5 + grep -i "$search_pattern" "$TEMP_MATCHES" | grep -v "authenticator failed\|Authentication failed\|saved mail to" | grep -i "550\|551\|bounced\|** " | grep -oE "550 [^(]*|551 [^(]*|User unknown|Mailbox.*full|Relay.*denied|No such user|does not exist" | sort | uniq -c | sort -rn | head -5 echo "" fi