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 }