From 03864cdc55648f287a019fc2eff5df26f204ffb0 Mon Sep 17 00:00:00 2001 From: cheetah Date: Sat, 20 Mar 2021 03:23:50 +0000 Subject: [PATCH] fixed a bug, where you get double the notifications when a new mail arrives and the old ones are not read yet --- config.json | 2 +- index.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/config.json b/config.json index 70cc629..f4d8535 100644 --- a/config.json +++ b/config.json @@ -6,7 +6,7 @@ "routing": { "device": "generic", "connectors": [ - [ "pocsag", "77174D" ] + [ "pocsag", "77174A" ] ] } } diff --git a/index.js b/index.js index b2bac7a..01dfcf1 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ const fetchOptions = { markSeen: false, struct: true, } - +const ignoreImapIDs = [] function main() { ImapSimple .connect(config) @@ -31,7 +31,7 @@ async function processMail(mail) { let payload = config.handling[handling] payload = payload.replace("[subject]", mail.subject) payload = payload.replace("[from]", mail.from.text) - payload = payload.replace("[fromName]", mail.from.value.name) + payload = payload.replace("[fromName]", mail.from.value.name || mail.from.value.address) payload = payload.replace("[fromAddress]", mail.from.value.address) sendPage(payload) } @@ -43,6 +43,8 @@ function ScanUnread() { for (let mail of emails) { const all = mail.parts.filter(x=>x.which=='')[0] const idHeader = `Imap-Id: ${ mail.attributes.uid }\r\n` + if (ignoreImapIDs.indexOf(mail.attributes.uid) > -1) continue // Skip already notified mails + ignoreImapIDs.push(mail.attributes.uid) mailparser.simpleParser(idHeader + all.body).then(processMail) } })