Skip to content

Commit

Permalink
Added new plugin hook sender:responseError, allow configuratble defer…
Browse files Browse the repository at this point in the history
… times
  • Loading branch information
andris9 committed Dec 14, 2023
1 parent 97e5c23 commit 9e49fba
Show file tree
Hide file tree
Showing 4 changed files with 553 additions and 548 deletions.
15 changes: 9 additions & 6 deletions lib/sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const base32 = require('base32.js');
// handle DNS resolving
require('./ip-tools');

const ttlMinutes = [
const DEFAULT_DEFER_TIMES = [
5 /* 5 */, 7 /* 12 */, 8 /* 20 */, 25 /* 45 */, 75 /* 2h */, 120 /* 4h */, 240 /* 8h */, 240 /* 12h */, 240 /* 16h */, 240 /* 20h */, 240 /* 24h */,
240 /* 28h */, 240 /* 32h */, 240 /* 36h */, 240 /* 40h */, 240 /* 44h */, 240 /* 48h */
];
].map(v => v * 60 * 1000);

const POLICY_RESPONSE = '550 Failed to establish a TLS connection to the MX server as requested by policy';

Expand Down Expand Up @@ -143,7 +143,9 @@ class Sender extends EventEmitter {
return;
}
responseSent = true;
this.handleResponseError(delivery, connection, err, continueSending);
plugins.handler.runHooks('sender:responseError', [delivery, connection, err], () => {
this.handleResponseError(delivery, connection, err, continueSending);
});
};

this.sendCommand('GET', (err, delivery) => {
Expand Down Expand Up @@ -723,9 +725,10 @@ class Sender extends EventEmitter {
bounce.action = 'reject';
}

if (bounce.action !== 'reject' && deferredCount < ttlMinutes.length) {
//let ttl = Math.min(Math.pow(5, Math.min(deferredCount + 1, 4)), 180) * 60 * 1000;
let ttl = ttlMinutes[deferredCount] * 60 * 1000;
const deferTimes = delivery.deferTimes && Array.isArray(delivery.deferTimes) && delivery.deferTimes.length ? delivery.deferTimes : DEFAULT_DEFER_TIMES;

if (bounce.action !== 'reject' && deferredCount < deferTimes.length) {
const ttl = deferTimes[deferredCount];
log.info(
this.logName,
'id=%s %s.%s DEFERRED[%s] from=%s to=%s src=%s mx=%s id=%s (%s)',
Expand Down
Loading

0 comments on commit 9e49fba

Please sign in to comment.