From 0a74d1f6ec2dfd8a5bf1688d051e1eb2a2b815e4 Mon Sep 17 00:00:00 2001 From: NickOvt Date: Thu, 7 Nov 2024 11:55:19 +0200 Subject: [PATCH] fix(fixes): ZMS-185 (#31) * fix logical error with tempfail * fix subject issue when using api. add debugJson to gelf * safer delete with check --- index.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 72b6188..948b7ee 100644 --- a/index.js +++ b/index.js @@ -193,7 +193,7 @@ module.exports.init = async app => { const originhost = serverHost || (envelope.originhost || '').replace('[', '').replace(']', ''); const transhost = (envelope.transhost || '').replace('[', '').replace(']', '') || originhost; - let subject = messageinfo.subject || 'no subject'; + let subject = messageinfo.subject || allHeadersParsed.Subject || 'no subject'; subject = subject.substring(0, subjectMaxLength); const messageIdHeaderVal = allHeadersParsed['Message-ID']?.replace('<', '').replace('>', ''); @@ -218,6 +218,15 @@ module.exports.init = async app => { }); const resBodyJson = await res.body.json(); + const debugJson = { ...resBodyJson }; + + ['SENDER', 'SENDER_GROUP', 'WEBHOOK'].forEach(sym => { + if (debugJson.symbols) { + delete debugJson.symbols[sym]; + } + }); + ['sender', 'action', 'zilter-id', 'client'].forEach(el => delete debugJson[el]); + if (res.statusCode === 401) { // unauthorized Zilter, default to tempfail error return loggelfForEveryUser(app, subject, { @@ -233,7 +242,8 @@ module.exports.init = async app => { _subject: subject, level: 5, _zilter_error: 'Unauthorized error 401', - _ip: envelope.origin + _ip: envelope.origin, + _debug_json: debugJson }); } @@ -258,7 +268,8 @@ module.exports.init = async app => { level: 5, _passed: 'N', _action: resBodyJson.action, - _ip: envelope.origin + _ip: envelope.origin, + _debug_json: debugJson }); } else if (resBodyJson.action && resBodyJson.action === 'accept') { // accepted, so not a tempfail @@ -276,7 +287,8 @@ module.exports.init = async app => { _subject: subject, level: 5, _passed: 'Y', - _ip: envelope.origin + _ip: envelope.origin, + _debug_json: debugJson }); } } catch (err) {