From 2e681848aa1f2b9fb114a9f7c2d1bc125454ebfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Zieren?= Date: Thu, 29 Jun 2023 15:22:53 +0200 Subject: [PATCH] Notify via email about rejected messages to the forwarding address (fixes #41) --- main.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/main.js b/main.js index d27faf3..af341dd 100644 --- a/main.js +++ b/main.js @@ -887,13 +887,23 @@ async function processNewEmail() { } // Prevent accidental impersonation by allowing only known senders in the From:. - if (!parsedMessage.from || !parsedMessage.from.value.length) { - LOG.warn('Rejected incoming email without From:'); - continue; + let rejectedFrom = null; + if (!parsedMessage.from || !parsedMessage.from.value.length) { // never allowed + rejectedFrom = ''; + } else if (!CONFIG.options.incomingEmail.allowForwardingFrom.includes( // maybe not allowed + // Assume just one element in the From: header, for simplicity. + parsedMessage.from.value[0].address.toLowerCase())) { + rejectedFrom = parsedMessage.from.text; } - if (!CONFIG.options.incomingEmail.allowForwardingFrom.includes( - parsedMessage.from.value[0].address.toLowerCase())) { - LOG.warn(`Rejected incoming email from "${parsedMessage.from.text}"`); + if (rejectedFrom !== null) { + LOG.warn(`Rejecting incoming email from "${rejectedFrom}"`); + INBOUND.push({ + email: buildEmail('Fehlerteufel', 'Nachricht von fremdem Absender ignoriert', { + text: `Nachricht von "${rejectedFrom}" an ` + + `${CONFIG.options.incomingEmail.forwardingAddress} wurde ignoriert.\n\n` + + 'ACHTUNG: Diese Adresse sollte nicht veröffentlicht werden!',}), + ok: () => {} + }); continue; }