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.
This commit is contained in:
potato-20
2026-06-06 15:48:17 +05:30
parent 7f63e73ec3
commit 1704bdfa79
+10 -4
View File
@@ -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
}