From 4877ac6ef9a94a038cbd0bc0bd5e8d1e70c3fba5 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Sun, 24 Mar 2024 08:55:57 -0700 Subject: [PATCH] smtp_proxy: handle dead sender more gracefully (#3286) * q/proxy: check client is alive b4 sending cmd --- docs/plugins/queue/smtp_proxy.md | 15 +++++---------- plugins/queue/smtp_forward.js | 3 +-- plugins/queue/smtp_proxy.js | 11 ++++++++++- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/docs/plugins/queue/smtp_proxy.md b/docs/plugins/queue/smtp_proxy.md index dac6a9d2c..f8dfc9dfd 100644 --- a/docs/plugins/queue/smtp_proxy.md +++ b/docs/plugins/queue/smtp_proxy.md @@ -1,16 +1,11 @@ # queue/smtp\_proxy ================ -This plugin delivers to another mail server. This is a common setup when you -want to have a mail server with a solid pedigree of outbound delivery to -other hosts, and inbound delivery to users. - -In comparison to `queue/smtp_forward`, this plugin makes a connection at -MAIL FROM time to the ongoing SMTP server. This can be a benefit in that -you get any SMTP-time filtering that the ongoing server provides, in -particular one important facility to some setups is recipient filtering. -However be aware that other than connect and HELO-time filtering, you will -have as many connections to your ongoing SMTP server as you have to Haraka. +This plugin delivers to another mail server. This is a common setup when you want to have a mail server with a solid pedigree of outbound delivery to other hosts, and inbound delivery to users. + +In comparison to `queue/smtp_forward`, this plugin makes a connection at MAIL FROM time to the ongoing SMTP server. This can be a benefit in that you get any SMTP-time filtering that the ongoing server provides, in particular one important facility to some setups is recipient filtering. + +Be aware that other than connect and HELO-time filtering, you will have as many connections to your ongoing SMTP server as you have to Haraka. ## Configuration ------------- diff --git a/plugins/queue/smtp_forward.js b/plugins/queue/smtp_forward.js index cca069192..4d035b761 100644 --- a/plugins/queue/smtp_forward.js +++ b/plugins/queue/smtp_forward.js @@ -247,8 +247,7 @@ exports.queue_forward = function (next, connection) { ); function get_rs () { - if (txn) return txn.results; - return connection.results; + return connection?.transaction?.results ? connection.transaction.results : connection.results } function dead_sender () { diff --git a/plugins/queue/smtp_proxy.js b/plugins/queue/smtp_proxy.js index 05bd61d49..5948a7382 100644 --- a/plugins/queue/smtp_proxy.js +++ b/plugins/queue/smtp_proxy.js @@ -79,6 +79,10 @@ exports.hook_mail = function (next, connection, params) { exports.hook_rcpt_ok = (next, connection, recipient) => { const { smtp_client } = connection.notes; if (!smtp_client) return next(); + if (smtp_client.is_dead_sender(this, connection)) { + delete connection.notes.smtp_client; + return; + } smtp_client.next = next; smtp_client.send_command('RCPT', `TO:${recipient.format(!smtp_client.smtp_utf8)}`); } @@ -86,6 +90,11 @@ exports.hook_rcpt_ok = (next, connection, recipient) => { exports.hook_data = (next, connection) => { const { smtp_client } = connection.notes; if (!smtp_client) return next(); + + if (smtp_client.is_dead_sender(this, connection)) { + delete connection.notes.smtp_client; + return; + } smtp_client.next = next; smtp_client.send_command("DATA"); } @@ -96,11 +105,11 @@ exports.hook_queue = function (next, connection) { const { smtp_client } = connection.notes; if (!smtp_client) return next(); - smtp_client.next = next; if (smtp_client.is_dead_sender(this, connection)) { delete connection.notes.smtp_client; return; } + smtp_client.next = next; smtp_client.start_data(connection.transaction.message_stream); }