From 8b3a76e10879ab75a6144936dae2145496eb88b8 Mon Sep 17 00:00:00 2001 From: analogic Date: Thu, 11 Apr 2024 17:44:57 +0200 Subject: [PATCH] check for local_mx only when default route is used (#3307) It only checks local mx if it falls through to the DNS looked up route - so any plugin's mx is excluded. --------- Co-authored-by: SH Co-authored-by: Matt Simerson --- Changes.md | 1 + outbound/hmail.js | 30 +++++++++++++----------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Changes.md b/Changes.md index b15ccdf15..c01b1767d 100644 --- a/Changes.md +++ b/Changes.md @@ -3,6 +3,7 @@ #### Changed +- check for local_mx only when default route is used #3307 - test: add a connection.response test case with DSN #3305 - deps: bump all versions to latest #3303 - auth_base: enable disabling constrain_sender at runtime #3298 diff --git a/outbound/hmail.js b/outbound/hmail.js index 68f57f726..9ba5cdfd5 100644 --- a/outbound/hmail.js +++ b/outbound/hmail.js @@ -228,8 +228,10 @@ class HMailItem extends events.EventEmitter { // if none of the above return codes, drop through to this... mx_lookup.lookup_mx(this.todo.domain, (err, mxs) => { - this.found_mx(err, mxs); - }); + if (mxs) mxs.forEach(m => { m.from_dns = true; }); + + this.found_mx (err, mxs) + }) } found_mx (err, mxs) { @@ -272,15 +274,11 @@ class HMailItem extends events.EventEmitter { if (mxlist[mx].path) { this.mxlist.push(mxlist[mx]); } - else if (obc.cfg.ipv6_enabled) { - this.mxlist.push( - { exchange: mxlist[mx].exchange, priority: mxlist[mx].priority, port: mxlist[mx].port, using_lmtp: mxlist[mx].using_lmtp, family: 'AAAA' }, - { exchange: mxlist[mx].exchange, priority: mxlist[mx].priority, port: mxlist[mx].port, using_lmtp: mxlist[mx].using_lmtp, family: 'A' } - ); - } else { - mxlist[mx].family = 'A'; - this.mxlist.push(mxlist[mx]); + if (obc.cfg.ipv6_enabled) { + this.mxlist.push(Object.assign({}, mxlist[mx], { family: 'AAAA' })); + } + this.mxlist.push(Object.assign({}, mxlist[mx], { family: 'A' })); } } this.try_deliver(); @@ -300,11 +298,9 @@ class HMailItem extends events.EventEmitter { const mx = this.mxlist.shift(); const host = mx.exchange; - if (!obc.cfg.local_mx_ok) { - if (await net_utils.is_local_host(host)) { - this.loginfo(`MX ${host} is local, skipping since local_mx_ok=false`) - return this.try_deliver(); // try next MX - } + if (!obc.cfg.local_mx_ok && mx.from_dns && await net_utils.is_local_host(host)) { + this.loginfo(`MX ${host} is local, skipping since local_mx_ok=false`) + return this.try_deliver(); // try next MX } this.force_tls = this.todo.force_tls; @@ -371,7 +367,7 @@ class HMailItem extends events.EventEmitter { host = mx.path; } - this.logdebug(`delivering from: ${mx.bind_helo} to: ${host}:${port}${mx.using_lmtp ? " using LMTP" : ""} (${delivery_queue.length()}) (${temp_fail_queue.length()})`) + this.logdebug(`delivering from: ${mx.bind_helo} to: ${host}:${port}${mx.using_lmtp ? " using LMTP" : ""}${mx.from_dns ? " (via DNS)" : ""} (${delivery_queue.length()}) (${temp_fail_queue.length()})`) client_pool.get_client(port, host, mx.bind, !!mx.path, (err, socket) => { if (err) { if (/connection timed out|connect ECONNREFUSED/.test(err)) { @@ -729,7 +725,7 @@ class HMailItem extends events.EventEmitter { // The response is our challenge return send_command(cram_md5_response(mx.auth_user, mx.auth_pass, resp)); default: - // This shouldn't happen... + // This shouldn't happen... } } // Error