Skip to content

Commit

Permalink
smtp_proxy: handle dead sender more gracefully (#3286)
Browse files Browse the repository at this point in the history
* q/proxy: check client is alive b4 sending cmd
  • Loading branch information
msimerson authored Mar 24, 2024
1 parent 2ab13b2 commit 4877ac6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
15 changes: 5 additions & 10 deletions docs/plugins/queue/smtp_proxy.md
Original file line number Diff line number Diff line change
@@ -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
-------------
Expand Down
3 changes: 1 addition & 2 deletions plugins/queue/smtp_forward.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
11 changes: 10 additions & 1 deletion plugins/queue/smtp_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,22 @@ 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)}`);
}

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");
}
Expand All @@ -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);
}

Expand Down

0 comments on commit 4877ac6

Please sign in to comment.