From 1704bdfa79ef4a720299b85f78dcc1d3cb10f7d8 Mon Sep 17 00:00:00 2001 From: potato-20 Date: Sat, 6 Jun 2026 15:48:17 +0530 Subject: [PATCH] Fix --mx host:port parsing and incorrect no-MX message (#2986) When a port was appended to the domain (e.g. "--mx example.com:25"), the suffix was passed straight into the MX DNS lookup, so no MX records were found. Strip a trailing :port off the domain before the lookup and use it as the port to test. Also fix the no-MX message, which printed $1 (the run date) instead of the domain, plus a "records(s)" typo. --- testssl.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/testssl.sh b/testssl.sh index fbf4a8f..0721c94 100755 --- a/testssl.sh +++ b/testssl.sh @@ -23652,21 +23652,27 @@ draw_line() { run_mx_all_ips() { local fname_date="$1" + local domain="$2" local mxs mx - local mxport + local mxport=${3:-25} local -i ret=0 local word="" STARTTLS_PROTOCOL="smtp" + # A port may be appended to the domain, e.g. "--mx example.com:587" (#2986). + # Strip it off before the MX DNS lookup and use it as the port to test. + if [[ "$domain" =~ :[0-9]+$ ]]; then + mxport="${domain##*:}" + domain="${domain%:*}" + fi # test first higher priority servers - mxs=$(get_mx_record "$2" | sort -n | sed -e 's/^.* //' -e 's/\.$//' | tr '\n' ' ') + mxs=$(get_mx_record "$domain" | sort -n | sed -e 's/^.* //' -e 's/\.$//' | tr '\n' ' ') if [[ $CMDLINE_IP == one ]]; then word="as instructed one" # with highest priority mxs=${mxs%% *} else word="the only" fi - mxport=${3:-25} if [[ -n "$LOGFILE" ]] || [[ -n "$PARENT_LOGFILE" ]]; then prepare_logging "${fname_date}" else @@ -23707,7 +23713,7 @@ run_mx_all_ips() { outln pr_bold "Done testing all MX records (on port $mxport): "; outln "$mxs" else - prln_bold " $1 has no MX records(s)" + prln_bold " $domain has no MX record(s)" fi return $ret }