Fix integer expression errors in failure categorization

Sanitize all grep counts to remove newlines that cause
'integer expression required' errors
This commit is contained in:
cschantz
2025-12-31 19:24:00 -05:00
parent d730da404e
commit 9d79d00fa0
+7 -1
View File
@@ -514,13 +514,19 @@ if [ "$bounced" -gt 0 ]; then
TEMP_BOUNCES="/tmp/email_bounces_$$.txt"
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\|** " > "$TEMP_BOUNCES" 2>/dev/null
# Categorize failures
# Categorize failures (sanitize counts to remove newlines)
recipient_unknown=$(grep -ci "user unknown\|No such user\|does not exist\|recipient rejected\|Recipient address rejected\|550.*User" "$TEMP_BOUNCES" 2>/dev/null || echo 0)
recipient_unknown=$(echo "$recipient_unknown" | head -1 | tr -d '\n\r')
mailbox_full=$(grep -ci "mailbox.*full\|quota.*exceeded\|552\|insufficient.*space\|over.*quota" "$TEMP_BOUNCES" 2>/dev/null || echo 0)
mailbox_full=$(echo "$mailbox_full" | head -1 | tr -d '\n\r')
relay_denied=$(grep -ci "relay.*denied\|relay.*not.*permitted\|relaying denied\|554.*relay" "$TEMP_BOUNCES" 2>/dev/null || echo 0)
relay_denied=$(echo "$relay_denied" | head -1 | tr -d '\n\r')
blocked=$(grep -ci "blocked\|blacklist\|550.*spam\|554.*spam\|Policy rejection" "$TEMP_BOUNCES" 2>/dev/null || echo 0)
blocked=$(echo "$blocked" | head -1 | tr -d '\n\r')
dns_failure=$(grep -ci "domain.*not.*found\|Host.*unknown\|Name.*not.*resolve\|MX.*not.*found" "$TEMP_BOUNCES" 2>/dev/null || echo 0)
dns_failure=$(echo "$dns_failure" | head -1 | tr -d '\n\r')
connection_fail=$(grep -ci "timeout\|connection.*refused\|connection.*failed\|Network.*unreachable" "$TEMP_BOUNCES" 2>/dev/null || echo 0)
connection_fail=$(echo "$connection_fail" | head -1 | tr -d '\n\r')
print_info "Failure breakdown by reason:"
echo ""