diff --git a/modules/email/mail-log-analyzer.sh b/modules/email/mail-log-analyzer.sh index 5656338..154314e 100755 --- a/modules/email/mail-log-analyzer.sh +++ b/modules/email/mail-log-analyzer.sh @@ -628,16 +628,16 @@ analyze_domain_performance() { fi done - # Track bounced messages per domain - grep "==" -- "$log_file" 2>/dev/null | while IFS= read -r line; do + # Track bounced messages per domain - Use SAME pattern as primary bounce detection (line 243) + grep -E "^[0-9]{4}-[0-9]{2}-[0-9]{2}.*==" -- "$log_file" 2>/dev/null | while IFS= read -r line; do if [[ "$line" =~ @([a-zA-Z0-9.-]+\.[a-zA-Z]{2,}) ]]; then local domain="${BASH_REMATCH[1]}" - echo "$domain" >> "$TEMP_DIR/"domains_bounced.$$ + echo "$domain" >> "$TEMP_DIR/domains_bounced.$$" # Capture bounce reason if [[ "$line" =~ (550|551|552|553|554)[[:space:]](.{1,80}) ]]; then local reason="${BASH_REMATCH[2]}" - echo "$domain|$reason" >> "$TEMP_DIR/"domain_bounce_reasons.$$ + echo "$domain|$reason" >> "$TEMP_DIR/domain_bounce_reasons.$$" fi fi done @@ -797,8 +797,8 @@ gather_statistics() { # Count received messages TOTAL_RECEIVED=$(grep -c "=>" -- "$log_file" 2>/dev/null || echo "0") - # Count deferrals - TOTAL_DEFERRED=$(grep -c "defer" -- "$log_file" 2>/dev/null || echo "0") + # Count deferrals - Use word boundary to match only actual deferral markers + TOTAL_DEFERRED=$(grep -cE "defer[red]*[^a-z]|deferred[^a-z]" -- "$log_file" 2>/dev/null || echo "0") # Count rejections TOTAL_REJECTED=$(grep -cE "(reject|denied)" -- "$log_file" 2>/dev/null | tr -d '\n' || echo "0")