Skip to content

Commit

Permalink
fix(logs): Log received chain comments (#28)
Browse files Browse the repository at this point in the history
* log received

* Log received chain by comments
  • Loading branch information
andris9 authored Feb 12, 2024
1 parent b46c914 commit 3633ed2
Show file tree
Hide file tree
Showing 3 changed files with 269 additions and 206 deletions.
13 changes: 12 additions & 1 deletion lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { spf: checkSpf } = require('mailauth/lib/spf');
const { dkimVerify } = require('mailauth/lib/dkim/verify');
const { bimi } = require('mailauth/lib/bimi');
const libmime = require('libmime');
const { parseReceived } = require('mailauth/lib/parse-received');

async function hookMail(plugin, connection, params) {
const txn = connection?.transaction;
Expand Down Expand Up @@ -150,6 +151,14 @@ async function hookDataPost(stream, plugin, connection) {
}
}

const receivedChain = dkimResult?.headers?.parsed.filter(r => r.key === 'received').map(row => parseReceived(row.line));
const receivedChainComment = []
.concat(receivedChain || [])
.reverse()
.map(entry => entry?.by?.comment)
.filter(value => value)
.join(', ');

for (let result of dkimResult?.results || []) {
if (result.info) {
connection.auth_results(result.info);
Expand Down Expand Up @@ -180,6 +189,7 @@ async function hookDataPost(stream, plugin, connection) {
_dkim_body_size_source: result.sourceBodyLength,
_dkim_body_size_canon: result.canonBodyLengthTotal,
_dkim_body_size_limit: result.canonBodyLengthLimited && result.canonBodyLengthLimit,
_dkim_canon_mime_start: result.mimeStructureStart,
_dkim_signing_headers: signingHeaders.join(','),
_dkim_signing_headers_content_type: signingHeaders.includes('content-type') ? 'yes' : 'no',
_spf_status: txn.notes.spfResult?.status?.result,
Expand All @@ -190,7 +200,8 @@ async function hookDataPost(stream, plugin, connection) {
_bimi_comment: bimiResult?.status?.comment,
_bimi_vmc: bimiResult?.status?.result === 'pass' && (bimiResult?.authority ? 'yes' : 'no'),
_content_type_count: contentTypeHeaders.length,
_content_type_boundary: contentTypeHeaders.length ? contentTypeHeaders.at(-1)?.params?.boundary?.substr(0, 20) : null
_content_type_boundary: contentTypeHeaders.length ? contentTypeHeaders.at(-1)?.params?.boundary?.substr(0, 20) : null,
_received_by_comment: receivedChainComment
});
}
}
Expand Down
Loading

0 comments on commit 3633ed2

Please sign in to comment.