fixed a bug, where you get double the notifications when a new mail arrives and the old ones are not read yet

master
cheetah 4 years ago
parent cdb6ecb7eb
commit 03864cdc55

@ -6,7 +6,7 @@
"routing": { "routing": {
"device": "generic", "device": "generic",
"connectors": [ "connectors": [
[ "pocsag", "77174D" ] [ "pocsag", "77174A" ]
] ]
} }
} }

@ -14,7 +14,7 @@ const fetchOptions = {
markSeen: false, markSeen: false,
struct: true, struct: true,
} }
const ignoreImapIDs = []
function main() { function main() {
ImapSimple ImapSimple
.connect(config) .connect(config)
@ -31,7 +31,7 @@ async function processMail(mail) {
let payload = config.handling[handling] let payload = config.handling[handling]
payload = payload.replace("[subject]", mail.subject) payload = payload.replace("[subject]", mail.subject)
payload = payload.replace("[from]", mail.from.text) 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) payload = payload.replace("[fromAddress]", mail.from.value.address)
sendPage(payload) sendPage(payload)
} }
@ -43,6 +43,8 @@ function ScanUnread() {
for (let mail of emails) { for (let mail of emails) {
const all = mail.parts.filter(x=>x.which=='')[0] const all = mail.parts.filter(x=>x.which=='')[0]
const idHeader = `Imap-Id: ${ mail.attributes.uid }\r\n` 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) mailparser.simpleParser(idHeader + all.body).then(processMail)
} }
}) })

Loading…
Cancel
Save