89ad050222
CRITICAL FIXES (5 issues):
1. email-diagnostics.sh: Fix inverted sender/recipient extraction logic
- Lines 292-303: Corrected pattern matching to properly extract recipients and senders
- Removed inverted grep patterns that were looking for wrong log entry types
2. mail-log-analyzer.sh: Fix string comparison with percent sign
- Line 1184-1186: Properly extract numeric value before '%' character
- Use sed to isolate leading digits for numeric comparison
3. email-diagnostics.sh: Fix malformed grep syntax
- Line 525-527: Corrected grep command structure with -e options
- Changed to -iE with pipe patterns and proper file argument placement
4. mail-log-analyzer.sh: Fix overly broad domain bounce pattern
- Line 749: Changed from "^.*${domain}" to "\b${domain}$"
- Prevents false positives from substring domain matches
5. mail-log-analyzer.sh: Fix undefined TEMP_LOG variable
- Line 860: Changed TEMP_LOG to MAIL_LOG (the actual global variable)
- Added error handling with 2>/dev/null
HIGH SEVERITY FIXES (2 issues):
6. mail-log-analyzer.sh: Fix AWK uninitialized variable
- Lines 1447-1456: Added BEGIN block to initialize print_line = 0
- Prevents first log entries from being incorrectly filtered
7. mail-log-analyzer.sh: Fix overly permissive bounce detection pattern
- Line 247: Changed from "(==|defer)" to more specific pattern
- Prevents false positives from non-bounce defer messages
MODERATE FIXES (3 issues):
8. mail-queue-inspector.sh: Fix queue message count mismatch
- Line 41: Changed head -40 to head -20 to match label
9. deliverability-test.sh: Fix fragile SMTP connection test
- Lines 102-106: Added nc availability check and fallback to bash TCP
- Proper variable quoting and error handling
10. blacklist-check.sh: Replace deprecated host command with dig
- Line 52: Changed from host to dig +short for consistency and timeout control
All scripts pass syntax validation.
Impact: Logic errors fixed, no security issues introduced, all existing functionality preserved.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
67 lines
1.8 KiB
Bash
Executable File
67 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
################################################################################
|
|
# Mail Queue Inspector
|
|
################################################################################
|
|
# Purpose: View and analyze mail queue
|
|
################################################################################
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
source "$SCRIPT_DIR/lib/common-functions.sh"
|
|
source "$SCRIPT_DIR/lib/system-detect.sh"
|
|
source "$SCRIPT_DIR/lib/email-functions.sh"
|
|
|
|
show_banner "Mail Queue Inspector"
|
|
|
|
# Detect MTA
|
|
MTA=$(detect_mta)
|
|
|
|
if [ "$MTA" = "unknown" ]; then
|
|
print_error "No supported mail server (Exim/Postfix) detected"
|
|
exit 1
|
|
fi
|
|
|
|
print_info "Detected mail server: $MTA"
|
|
echo ""
|
|
|
|
# Show queue summary
|
|
if [ "$MTA" = "exim" ]; then
|
|
print_header "Queue Summary"
|
|
queue_count=$(exim -bpc)
|
|
if [ "$queue_count" -gt 0 ]; then
|
|
print_warning "$queue_count messages in queue"
|
|
else
|
|
print_success "Mail queue is empty"
|
|
fi
|
|
echo ""
|
|
|
|
# Show queue details if not empty
|
|
if [ "$queue_count" -gt 0 ]; then
|
|
print_header "Recent Queue Messages (last 20)"
|
|
exim -bp | head -20
|
|
echo ""
|
|
|
|
print_header "Frozen Messages"
|
|
frozen=$(exim -bp | grep frozen | wc -l)
|
|
if [ "$frozen" -gt 0 ]; then
|
|
print_warning "$frozen frozen messages found"
|
|
exim -bp | grep frozen | head -10
|
|
else
|
|
print_success "No frozen messages"
|
|
fi
|
|
fi
|
|
|
|
elif [ "$MTA" = "postfix" ]; then
|
|
print_header "Queue Summary"
|
|
mailq | tail -1
|
|
echo ""
|
|
|
|
print_header "Queue Details"
|
|
mailq | head -50
|
|
fi
|
|
|
|
echo ""
|
|
print_info "Use 'exim -Mvl <message_id>' to view message details"
|
|
print_info "Use 'exim -Mrm <message_id>' to remove a message"
|
|
echo ""
|