Skip to content

Commit

Permalink
fix(logging): If DMARC was missing, then logging failed with an error
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Apr 19, 2024
1 parent 6807521 commit 830ad7d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ exports.increment_forward_counters = async function (connection) {
const ttlres = await plugin.ttlcounterAsync('wdf:' + key, increment, limit, false);
connection.loginfo(plugin, `Forward counter updated for ${key} (${increment}/${limit}): ${JSON.stringify(ttlres)}`);
} catch (err) {
connection.logerror(plugin, err);
connection.logerror(plugin, err.message);
}
}
};
Expand Down Expand Up @@ -543,7 +543,7 @@ exports.hook_rcpt = function (next, connection, params) {
returned = true;
const err = args && args[0];
if (err && /Error$/.test(err.name)) {
connection.logerror(plugin, err);
connection.logerror(plugin, err.message);
txn.notes.rejectCode = 'ERRC01';
return next(DENYSOFT, 'Failed to process recipient, try again [ERRC01]');
}
Expand Down Expand Up @@ -1193,7 +1193,7 @@ exports.hook_queue = function (next, connection) {
.increment_forward_counters(connection)
.then(next)
.catch(err => {
connection.logerror(plugin, err);
connection.logerror(plugin, err.message);
next();
});
}
Expand Down
15 changes: 8 additions & 7 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { parseReceived } = require('mailauth/lib/parse-received');

async function hookMail(plugin, connection, params) {
const txn = connection?.transaction;

if (!txn) {
return;
}
Expand All @@ -33,7 +34,7 @@ async function hookMail(plugin, connection, params) {
txn.notes.spfResult = spfResult;
} catch (err) {
txn.notes.spfResult = { error: err };
plugin.logerror(err, plugin, connection);
connection.logerror(plugin, err.message);
return;
}

Expand Down Expand Up @@ -71,7 +72,7 @@ async function hookDataPost(stream, plugin, connection) {
}
} catch (err) {
txn.notes.dkimResult = { error: err };
plugin.logerror(err, plugin, connection);
connection.logerror(plugin, err.message);
}

// Step 3. ARC
Expand All @@ -89,7 +90,7 @@ async function hookDataPost(stream, plugin, connection) {
}
} catch (err) {
txn.notes.arcResult = { error: err };
plugin.logerror(err, plugin, connection);
connection.logerror(plugin, err.message);
}
}

Expand Down Expand Up @@ -121,7 +122,7 @@ async function hookDataPost(stream, plugin, connection) {
}
} catch (err) {
txn.notes.dmarcResult = { error: err };
plugin.logerror(err, plugin, connection);
connection.logerror(plugin, err.message);
}
}

Expand All @@ -147,7 +148,7 @@ async function hookDataPost(stream, plugin, connection) {
txn.remove_header('bimi-indicator');
} catch (err) {
txn.notes.bimiResult = { error: err };
plugin.logerror(err, plugin, connection);
connection.logerror(plugin, err.message);
}
}

Expand Down Expand Up @@ -186,8 +187,8 @@ async function hookDataPost(stream, plugin, connection) {
_dkim_selector: result.selector,
_dkim_algo: result.algo,
_dkim_mod_len: result.modulusLength,
_dkim_canon_header: result.format.split('/').shift(),
_dkim_canon_body: result.format.split('/').pop(),
_dkim_canon_header: result.format?.split('/').shift(),
_dkim_canon_body: result.format?.split('/').pop(),
_dkim_body_size_source: result.sourceBodyLength,
_dkim_body_size_canon: result.canonBodyLengthTotal,
_dkim_body_size_limit: result.canonBodyLengthLimited && result.canonBodyLengthLimit,
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function dataPost(next, plugin, connection) {
next();
})
.catch(err => {
plugin.logerror(err, plugin, connection);
connection.logerror(plugin, err.message);
next();
});

Expand Down

0 comments on commit 830ad7d

Please sign in to comment.