Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defer options similar to spamassassin.js #32

Merged
merged 3 commits into from
Feb 23, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ exports.load_rspamd_ini = function () {
'+rmilter_headers.enabled',
'+soft_reject.enabled',
'+smtp_message.enabled',
'-defer.error',
'-defer.timeout',
],
}, () => {
plugin.load_rspamd_ini();
Expand Down Expand Up @@ -231,6 +233,7 @@ exports.hook_data_post = function (next, connection) {
if (!connection) return;
if (!connection.transaction) return;
connection.transaction.results.add(plugin, {err: 'timeout'});
if (plugin.cfg.defer.timeout) return nextOnce(DENYSOFT, 'Rspamd scan timeout');
nextOnce();
}, timeout * 1000);

Expand All @@ -242,14 +245,17 @@ exports.hook_data_post = function (next, connection) {
res.on('data', (chunk) => { rawData += chunk; });

res.on('end', () => {
if (!connection.transaction) return nextOnce(); //client gone

const r = plugin.parse_response(rawData, connection);
if (!r || !r.data || !r.log) return nextOnce();

if (!r || !r.data || !r.log) {
if (plugin.cfg.defer.error) return nextOnce(DENYSOFT, 'Rspamd scan error');
return nextOnce();
}

r.log.emit = true; // spit out a log entry
r.log.time = (Date.now() - start)/1000;

if (!connection.transaction) return nextOnce();

connection.transaction.results.add(plugin, r.log);
if (r.data.symbols) connection.transaction.results.add(plugin, { symbols: r.data.symbols });

Expand All @@ -274,8 +280,9 @@ exports.hook_data_post = function (next, connection) {
})

req.on('error', (err) => {
if (!connection || !connection.transaction) return;
if (!connection.transaction) return nextOnce(); // client gone
msimerson marked this conversation as resolved.
Show resolved Hide resolved
connection.transaction.results.add(plugin, { err: err.message});
if (plugin.cfg.defer.error) return nextOnce(DENYSOFT, 'Rspamd scan error');
nextOnce();
});

Expand Down