-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-mailserver.sh
More file actions
executable file
·695 lines (602 loc) · 21.5 KB
/
test-mailserver.sh
File metadata and controls
executable file
·695 lines (602 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
#!/bin/bash
################################################################################
# Mailserver Client-Side Test Suite
#
# Tests all email functions and logs verbose details about issues
# Usage: ./test-mailserver.sh [OPTIONS]
#
# Options:
# --host HOST Mailserver hostname/IP (default: localhost)
# --smtp-port PORT SMTP port (default: 25)
# --submission-port PORT Submission port (default: 587)
# --smtps-port PORT SMTPS port (default: 465)
# --smtp-alt-port PORT Alternate SMTP port (default: 2525)
# --imap-port PORT IMAP port (default: 143)
# --imaps-port PORT IMAPS port (default: 993)
# --pop3-port PORT POP3 port (default: 110)
# --pop3s-port PORT POP3S port (default: 995)
# --https-port PORT HTTPS/Admin port (default: 443)
# --admin-port PORT HTTP Admin port (default: 8080)
# --username USER Test account username (default: testuser)
# --domain DOMAIN Test domain (default: example.com)
# --password PASS Test account password (default: password123)
# --admin-user USER Admin username (default: admin)
# --admin-pass PASS Admin password (default: admin)
# --test-email EMAIL Destination email for test message (optional)
# --no-web Skip web dashboard tests
# --no-smtp Skip SMTP tests
# --no-imap Skip IMAP tests
# --no-pop3 Skip POP3 tests
# --no-send-test Skip test email sending
# --no-fetch-inbox Skip inbox fetching
# --verbose Verbose output (shows all commands)
# --help Show this help message
################################################################################
set -e
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
HOST="${HOST:-localhost}"
SMTP_PORT="${SMTP_PORT:-25}"
SUBMISSION_PORT="${SUBMISSION_PORT:-587}"
SMTPS_PORT="${SMTPS_PORT:-465}"
SMTP_ALT_PORT="${SMTP_ALT_PORT:-2525}"
IMAP_PORT="${IMAP_PORT:-143}"
IMAPS_PORT="${IMAPS_PORT:-993}"
POP3_PORT="${POP3_PORT:-110}"
POP3S_PORT="${POP3S_PORT:-995}"
HTTPS_PORT="${HTTPS_PORT:-443}"
ADMIN_PORT="${ADMIN_PORT:-8080}"
USERNAME="${USERNAME:-testuser}"
DOMAIN="${DOMAIN:-example.com}"
PASSWORD="${PASSWORD:-password123}"
ADMIN_USER="${ADMIN_USER:-admin}"
ADMIN_PASS="${ADMIN_PASS:-admin}"
TEST_EMAIL="${TEST_EMAIL:-}"
EMAIL="${USERNAME}@${DOMAIN}"
VERBOSE="${VERBOSE:-0}"
TEST_WEB="${TEST_WEB:-1}"
TEST_SMTP="${TEST_SMTP:-1}"
TEST_IMAP="${TEST_IMAP:-1}"
TEST_POP3="${TEST_POP3:-1}"
TEST_SEND_EMAIL="${TEST_SEND_EMAIL:-1}"
TEST_FETCH_INBOX="${TEST_FETCH_INBOX:-1}"
# Statistics
TESTS_RUN=0
TESTS_PASSED=0
TESTS_FAILED=0
ISSUES=()
# Log file
LOGFILE="mailserver-test-$(date +%Y%m%d-%H%M%S).log"
################################################################################
# Utility Functions
################################################################################
log() {
echo -e "$*" | tee -a "$LOGFILE"
}
log_quiet() {
echo "$*" >> "$LOGFILE"
}
log_test() {
echo -e "${BLUE}[TEST]${NC} $*" | tee -a "$LOGFILE"
}
log_pass() {
echo -e "${GREEN}[PASS]${NC} $*" | tee -a "$LOGFILE"
((TESTS_PASSED++))
}
log_fail() {
echo -e "${RED}[FAIL]${NC} $*" | tee -a "$LOGFILE"
((TESTS_FAILED++))
ISSUES+=("$*")
}
log_info() {
echo -e "${BLUE}ℹ${NC} $*" | tee -a "$LOGFILE"
}
log_warn() {
echo -e "${YELLOW}⚠${NC} $*" | tee -a "$LOGFILE"
}
log_section() {
echo "" | tee -a "$LOGFILE"
echo -e "${BLUE}════════════════════════════════════════${NC}" | tee -a "$LOGFILE"
echo -e "${BLUE}$*${NC}" | tee -a "$LOGFILE"
echo -e "${BLUE}════════════════════════════════════════${NC}" | tee -a "$LOGFILE"
}
verbose_log() {
if [[ $VERBOSE -eq 1 ]]; then
log_quiet " $ $*"
fi
}
# Check port connectivity with verbose failure details
check_port() {
local port="$1"
local name="$2"
log_test "Checking $name on port $port"
local error_output
if error_output=$(timeout 5 bash -c "cat < /dev/null > /dev/tcp/$HOST/$port" 2>&1); then
log_pass "Connected to $name on port $port"
return 0
else
local reason="unknown"
if echo "$error_output" | grep -qi "connection refused"; then
reason="Connection refused — the service is not listening on $HOST:$port"
elif echo "$error_output" | grep -qi "timed out"; then
reason="Connection timed out — the host $HOST is unreachable or a firewall is blocking port $port"
elif echo "$error_output" | grep -qi "no route"; then
reason="No route to host — network configuration issue reaching $HOST"
elif echo "$error_output" | grep -qi "name or service not known"; then
reason="DNS resolution failed — hostname '$HOST' cannot be resolved"
elif [[ -n "$error_output" ]]; then
reason="$error_output"
fi
log_fail "Cannot connect to $name on port $port — Reason: $reason"
log_quiet " Host: $HOST, Port: $port, Service: $name"
return 1
fi
}
# Test web API
test_web_api() {
local endpoint="$1"
local method="${2:-GET}"
local data="$3"
if [[ -n "$data" ]]; then
curl -s -X "$method" \
-u "$ADMIN_USER:$ADMIN_PASS" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "$data" \
"http://$HOST:$ADMIN_PORT$endpoint" 2>&1
else
curl -s -X "$method" \
-u "$ADMIN_USER:$ADMIN_PASS" \
"http://$HOST:$ADMIN_PORT$endpoint" 2>&1
fi
}
test_smtp_presence() {
local port="$1"
local label="$2"
local timeout_secs=5
local response
log_test "$label: Service presence on port $port"
response=$(timeout $timeout_secs bash -c "
exec 3<>/dev/tcp/$HOST/$port
timeout 2 head -1 <&3
" 2>&1)
if [[ $response == 220* ]]; then
log_pass "$label: Service banner received ($response)"
return 0
else
log_fail "$label: No valid SMTP banner on port $port — Response: $response"
return 1
fi
}
test_imap_presence() {
local timeout_secs=5
local response
log_test "IMAP: Service presence on port $IMAP_PORT"
response=$(timeout $timeout_secs bash -c "
exec 3<>/dev/tcp/$HOST/$IMAP_PORT
timeout 2 head -1 <&3
" 2>&1)
if [[ $response == "* OK"* ]]; then
log_pass "IMAP: Service banner received"
log_quiet " Banner: $response"
return 0
else
log_fail "IMAP: Invalid or missing banner — Response: $response"
return 1
fi
}
test_imap_invalid_login() {
local timeout_secs=5
local bad_pass="${PASSWORD}__invalid"
local response
log_test "IMAP: Reject invalid credentials"
response=$(timeout $timeout_secs bash -c "
exec 3<>/dev/tcp/$HOST/$IMAP_PORT
timeout 1 head -1 <&3
echo 'A001 LOGIN \"$EMAIL\" \"$bad_pass\"' >&3
timeout 2 cat <&3 | sed -n '/^A001 /p' | head -1
echo 'A002 LOGOUT' >&3
" 2>&1)
if [[ $response == *"A001 NO"* ]] || [[ $response == *"A001 BAD"* ]]; then
log_pass "IMAP: Invalid credentials correctly rejected"
return 0
else
log_fail "IMAP: Invalid credentials were not rejected — Response: $response"
return 1
fi
}
test_pop3_presence() {
local timeout_secs=5
local response
log_test "POP3: Service presence on port $POP3_PORT"
response=$(timeout $timeout_secs bash -c "
exec 3<>/dev/tcp/$HOST/$POP3_PORT
timeout 2 head -1 <&3
" 2>&1)
if [[ $response == +OK* ]]; then
log_pass "POP3: Service banner received"
log_quiet " Banner: $response"
return 0
else
log_fail "POP3: Invalid or missing banner — Response: $response"
return 1
fi
}
test_pop3_login() {
local username="$1"
local password="$2"
local should_succeed="$3"
local timeout_secs=5
local response
response=$(timeout $timeout_secs bash -c "
exec 3<>/dev/tcp/$HOST/$POP3_PORT
timeout 1 head -1 <&3
echo 'USER $username' >&3
timeout 1 head -1 <&3
echo 'PASS $password' >&3
timeout 1 head -1 <&3
echo 'QUIT' >&3
" 2>&1)
if [[ "$should_succeed" == "yes" ]]; then
if [[ $response == *"+OK"* ]] && [[ $response != *"-ERR"* ]]; then
log_pass "POP3: Login accepted for $username"
return 0
else
log_fail "POP3: Login failed for $username — Response: $response"
return 1
fi
else
if [[ $response == *"-ERR"* ]]; then
log_pass "POP3: Invalid credentials correctly rejected"
return 0
else
log_fail "POP3: Invalid credentials were not rejected — Response: $response"
return 1
fi
fi
}
# IMAP: Login and fetch inbox
test_imap_login() {
local response
local timeout_secs=5
log_test "IMAP: Login with credentials"
verbose_log "imap_login $EMAIL / ****"
response=$(timeout $timeout_secs bash -c "
exec 3<>/dev/tcp/$HOST/$IMAP_PORT
# Read greeting
timeout 1 head -1 <&3
# Send LOGIN command
echo 'A001 LOGIN \"$EMAIL\" \"$PASSWORD\"' >&3
# Read tagged response for LOGIN
timeout 2 cat <&3 | sed -n '/^A001 /p' | head -1
# Close connection
echo 'A002 LOGOUT' >&3
" 2>&1)
if [[ $response == *"A001 OK"* ]]; then
log_pass "IMAP: Successfully logged in as $EMAIL"
log_quiet " Response: $(echo "$response" | tail -1)"
return 0
else
log_fail "IMAP: Login failed for $EMAIL — Server response: $response"
log_quiet " Full response: $response"
return 1
fi
}
# IMAP: Fetch inbox
test_imap_fetch_inbox() {
local timeout_secs=10
local response
log_test "IMAP: Fetch INBOX"
verbose_log "imap_fetch_inbox $EMAIL"
response=$(timeout $timeout_secs bash -c "
exec 3<>/dev/tcp/$HOST/$IMAP_PORT
# Read greeting
timeout 1 head -1 <&3
# Send LOGIN
echo 'A001 LOGIN \"$EMAIL\" \"$PASSWORD\"' >&3
timeout 2 cat <&3 | sed -n '/^A001 /p' | head -1
# Select INBOX
echo 'A002 SELECT INBOX' >&3
timeout 2 cat <&3 | sed -n '/^\* [0-9]\+ EXISTS\|^A002 /p' | head -10
# Logout
echo 'A003 LOGOUT' >&3
" 2>&1)
if [[ $response == *"A001 OK"* ]] && [[ $response == *"A002 OK"* || $response == *"EXISTS"* ]]; then
local msg_count=$(echo "$response" | grep -oE '[0-9]+ EXISTS' | head -1)
if [[ -z "$msg_count" ]]; then
msg_count="0 messages"
fi
log_pass "IMAP: Fetched INBOX ($msg_count)"
log_quiet " Response: $(echo "$response" | tail -3)"
return 0
else
log_warn "IMAP: Could not fetch INBOX"
log_quiet " Response: $response"
return 1
fi
}
# SMTP: Send test email
test_smtp_send_email() {
local recipient="$1"
local timeout_secs=10
local response
local msg_id="test-$(date +%s)"
if [[ -z "$recipient" ]]; then
log_warn "SMTP: No recipient specified, skipping send test"
return 0
fi
log_test "SMTP: Send test email to $recipient"
verbose_log "smtp_send_email $EMAIL -> $recipient"
response=$(timeout $timeout_secs bash -c "
exec 3<>/dev/tcp/$HOST/$SMTP_PORT
# Read greeting
timeout 1 head -1 <&3
# Send EHLO
echo 'EHLO mailserver-test'
timeout 1 head -1 <&3
# Send MAIL FROM
echo 'MAIL FROM:<$EMAIL>'
timeout 1 head -1 <&3
# Send RCPT TO
echo 'RCPT TO:<$recipient>'
timeout 1 head -1 <&3
# Send DATA
echo 'DATA'
timeout 1 head -1 <&3
# Send message
echo 'From: $EMAIL'
echo 'To: $recipient'
echo 'Subject: Mailserver Test - $msg_id'
echo 'Date: '$(date -R)
echo ''
echo 'This is a test email from the mailserver test suite.'
echo 'Test ID: $msg_id'
echo 'Time: '$(date)
echo '.'
timeout 1 head -1 <&3
# Send QUIT
echo 'QUIT'
" 2>&1)
if [[ $response == *"250"* ]] || [[ $response == *"OK"* ]]; then
log_pass "SMTP: Test email sent to $recipient"
log_quiet " Message ID: $msg_id"
log_quiet " Response: $(echo "$response" | tail -1)"
return 0
else
log_fail "SMTP: Failed to send test email to $recipient — Server response: $response"
log_quiet " Full response: $response"
return 1
fi
}
show_help() {
head -40 "$0" | tail -30
}
parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
--host) HOST="$2"; shift 2 ;;
--smtp-port) SMTP_PORT="$2"; shift 2 ;;
--submission-port) SUBMISSION_PORT="$2"; shift 2 ;;
--smtps-port) SMTPS_PORT="$2"; shift 2 ;;
--smtp-alt-port) SMTP_ALT_PORT="$2"; shift 2 ;;
--imap-port) IMAP_PORT="$2"; shift 2 ;;
--imaps-port) IMAPS_PORT="$2"; shift 2 ;;
--pop3-port) POP3_PORT="$2"; shift 2 ;;
--pop3s-port) POP3S_PORT="$2"; shift 2 ;;
--https-port) HTTPS_PORT="$2"; shift 2 ;;
--admin-port) ADMIN_PORT="$2"; shift 2 ;;
--username) USERNAME="$2"; shift 2 ;;
--domain) DOMAIN="$2"; shift 2 ;;
--password) PASSWORD="$2"; shift 2 ;;
--admin-user) ADMIN_USER="$2"; shift 2 ;;
--admin-pass) ADMIN_PASS="$2"; shift 2 ;;
--test-email) TEST_EMAIL="$2"; shift 2 ;;
--no-web) TEST_WEB=0; shift ;;
--no-smtp) TEST_SMTP=0; shift ;;
--no-imap) TEST_IMAP=0; shift ;;
--no-pop3) TEST_POP3=0; shift ;;
--no-send-test) TEST_SEND_EMAIL=0; shift ;;
--no-fetch-inbox) TEST_FETCH_INBOX=0; shift ;;
--verbose) VERBOSE=1; shift ;;
--help) show_help; exit 0 ;;
*) echo "Unknown option: $1"; show_help; exit 1 ;;
esac
done
EMAIL="${USERNAME}@${DOMAIN}"
}
################################################################################
# Test Suites
################################################################################
test_connectivity() {
log_section "CONNECTIVITY TESTS"
check_port "$SMTP_PORT" "SMTP" || true
check_port "$SUBMISSION_PORT" "SMTP Submission" || true
check_port "$SMTPS_PORT" "SMTPS (Implicit TLS)" || true
check_port "$SMTP_ALT_PORT" "SMTP Alternate" || true
check_port "$IMAP_PORT" "IMAP" || true
check_port "$IMAPS_PORT" "IMAPS (Implicit TLS)" || true
check_port "$POP3_PORT" "POP3" || true
check_port "$POP3S_PORT" "POP3S (Implicit TLS)" || true
if [[ $TEST_WEB -eq 1 ]]; then
check_port "$ADMIN_PORT" "Web Admin (HTTP)" || true
fi
}
test_smtp_protocol() {
log_section "SMTP PROTOCOL TESTS"
test_smtp_presence "$SMTP_PORT" "SMTP" || true
log_info "Note: Full SMTP testing requires TLS/STARTTLS support."
test_smtp_presence "$SUBMISSION_PORT" "SMTP Submission" || true
log_info "Note: Submission port ($SUBMISSION_PORT) requires STARTTLS and authentication."
log_test "SMTPS: Service presence on port $SMTPS_PORT"
log_info "SMTPS uses implicit TLS, so plain TCP banner checks are skipped."
log_info "Note: SMTPS port ($SMTPS_PORT) uses implicit TLS."
test_smtp_presence "$SMTP_ALT_PORT" "SMTP Alternate" || true
log_info "Note: Alternate SMTP port ($SMTP_ALT_PORT) for ISPs that block port 25."
if [[ -z "$TEST_EMAIL" ]]; then
log_warn "SMTP: No test recipient specified (use --test-email)"
elif [[ $TEST_SEND_EMAIL -eq 1 ]]; then
test_smtp_send_email "$TEST_EMAIL" || true
fi
}
test_imap_protocol() {
log_section "IMAP PROTOCOL TESTS"
test_imap_presence || true
log_test "IMAPS: Service presence on port $IMAPS_PORT"
log_info "IMAPS uses implicit TLS, so plain TCP banner checks are skipped."
log_info "Note: IMAPS port ($IMAPS_PORT) uses implicit TLS."
if [[ $TEST_FETCH_INBOX -eq 1 ]]; then
test_imap_login || true
test_imap_invalid_login || true
test_imap_fetch_inbox || true
fi
}
test_pop3_protocol() {
log_section "POP3 PROTOCOL TESTS"
test_pop3_presence || true
log_test "POP3: Authenticate with valid credentials"
test_pop3_login "$EMAIL" "$PASSWORD" "yes" || true
log_test "POP3: Reject invalid credentials"
test_pop3_login "$EMAIL" "${PASSWORD}__invalid" "no" || true
log_test "POP3S: Service presence on port $POP3S_PORT"
log_info "POP3S uses implicit TLS, so plain TCP banner checks are skipped."
log_info "Note: POP3S port ($POP3S_PORT) uses implicit TLS."
}
test_web_dashboard() {
log_section "WEB DASHBOARD TESTS"
log_test "Web: Dashboard accessibility"
if response=$(test_web_api "/" "GET"); then
if [[ $response == *"<!DOCTYPE"* ]] || [[ $response == *"<html"* ]]; then
log_pass "Web: Dashboard accessible"
elif [[ $response == *"Unauthorized"* ]]; then
log_fail "Web: Authentication failed (check admin credentials)"
log_quiet " Admin user: $ADMIN_USER"
else
log_warn "Web: Unexpected response"
log_quiet " Response: ${response:0:200}"
fi
else
log_fail "Web: Dashboard unreachable"
fi
log_test "Web: Accounts page"
if response=$(test_web_api "/accounts" "GET"); then
if [[ $response == *"Accounts"* ]] || [[ $response == *"account"* ]]; then
log_pass "Web: Accounts page accessible"
else
log_fail "Web: Accounts page not working"
log_quiet " Response: ${response:0:200}"
fi
else
log_fail "Web: Accounts page unreachable"
fi
log_test "Web: Domains page"
if response=$(test_web_api "/domains" "GET"); then
if [[ $response == *"Domain"* ]] || [[ $response == *"domain"* ]]; then
log_pass "Web: Domains page accessible"
else
log_fail "Web: Domains page not working"
log_quiet " Response: ${response:0:200}"
fi
else
log_fail "Web: Domains page unreachable"
fi
log_test "Web: Logs pages"
if response=$(test_web_api "/logs/email" "GET"); then
if [[ $response == *"Email"* ]] || [[ $response == *"log"* ]]; then
log_pass "Web: Email logs page accessible"
else
log_fail "Web: Email logs not working"
fi
else
log_fail "Web: Email logs unreachable"
fi
}
test_system_info() {
log_section "SYSTEM INFORMATION"
log_info "Mailserver: $HOST"
log_info "Test Account: $EMAIL"
log_info "Password: ****"
log_info "Admin User: $ADMIN_USER"
log_info "Test Recipient: ${TEST_EMAIL:-<not specified>}"
log_info "SMTP Port: $SMTP_PORT"
log_info "Submission Port: $SUBMISSION_PORT"
log_info "SMTPS Port: $SMTPS_PORT"
log_info "SMTP Alternate Port: $SMTP_ALT_PORT"
log_info "IMAP Port: $IMAP_PORT"
log_info "IMAPS Port: $IMAPS_PORT"
log_info "POP3 Port: $POP3_PORT"
log_info "POP3S Port: $POP3S_PORT"
log_info "Admin HTTP Port: $ADMIN_PORT"
log_info "Log File: $LOGFILE"
}
print_summary() {
log_section "TEST SUMMARY"
log_info "Tests Passed: $TESTS_PASSED"
if [[ $TESTS_FAILED -gt 0 ]]; then
log_fail "Tests Failed: $TESTS_FAILED"
echo "" | tee -a "$LOGFILE"
echo -e "${RED}Issues Found:${NC}" | tee -a "$LOGFILE"
for issue in "${ISSUES[@]}"; do
echo -e " ${RED}×${NC} $issue" | tee -a "$LOGFILE"
done
else
log_pass "All tests passed!"
fi
echo "" | tee -a "$LOGFILE"
log_info "Full log: $LOGFILE"
}
################################################################################
# Main
################################################################################
main() {
parse_args "$@"
clear
echo -e "${BLUE}"
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ Mailserver Client-Side Test Suite ║"
echo "║ ║"
echo "║ Testing comprehensive email functionality ║"
echo "║ Host: $HOST"
echo "╚════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
log "Test started at $(date)"
log "Configuration:"
log " Host: $HOST"
log " SMTP Port: $SMTP_PORT"
log " Submission Port: $SUBMISSION_PORT"
log " SMTPS Port: $SMTPS_PORT"
log " SMTP Alternate Port: $SMTP_ALT_PORT"
log " IMAP Port: $IMAP_PORT"
log " IMAPS Port: $IMAPS_PORT"
log " POP3 Port: $POP3_PORT"
log " POP3S Port: $POP3S_PORT"
log " Admin Port: $ADMIN_PORT"
log " Test Account: $EMAIL"
test_system_info
test_connectivity
if [[ $TEST_SMTP -eq 1 ]]; then
test_smtp_protocol
fi
if [[ $TEST_IMAP -eq 1 ]]; then
test_imap_protocol
fi
if [[ $TEST_POP3 -eq 1 ]]; then
test_pop3_protocol
fi
if [[ $TEST_WEB -eq 1 ]]; then
test_web_dashboard
fi
print_summary
log ""
log "Test completed at $(date)"
# Exit with appropriate code
if [[ $TESTS_FAILED -gt 0 ]]; then
exit 1
else
exit 0
fi
}
main "$@"