added new features, config layout changed

master
cheetah 4 years ago
parent 25e2cb5777
commit 8ccc849c39

@ -2,11 +2,15 @@
"pager": {
"url": "http://127.0.0.1:3000/api/message/advanced",
"params": {
"type": "simple",
"type": "duplex",
"routing": {
"device": "generic",
"device": "birdyslim",
"connectors": [
[ "pocsag", "133701D" ]
[ "dapnet", "dl-all#DXxxx" ],
[ "ecityruf", "2900000" ],
[ "dapnet", "dl-all#DLxxx" ],
[ "pocsag", "133701D" ],
[ "dummy", "works" ]
]
}
}
@ -14,8 +18,11 @@
"handling": {
"onlySimpleCounter": false,
"onlySimpleCounterFormat": "[unreadCount] ongelezen emails",
"processing": {
"default": "[subject] - [from]"
}
"processing": [
{ "subjectContains": "data transferred" , "format": "[subject] - CF" },
{ "mxdomainExact": "spamdomein.tld" , "ignore": true },
{ "mxdomainContains": "paypal.nl" , "format": "PP: [subject]" },
{ "ignore": true }
]
}
}
}

@ -4,7 +4,7 @@ let $ImapConnection
const config = require('./config.json')
config.imap = require('./credentials.json')
config.onmail = () => ScanUnread()
//config.onmail = () => ScanUnread()
const axios = require('axios')
@ -24,27 +24,41 @@ function main() {
.then(ScanUnread)
}
async function sendPage(payload) {
console.log(payload)
await axios.post(config.pager.url, Object.assign({ ...config.pager.params }, { payload }))
}
function checkMatch(mail, cmd) {
if (!!cmd.subjectContains && !(mail.subject.indexOf(cmd.subjectContains) > -1)) return 0 // subjectContains does not match
if (!!cmd.mxdomainExact && !(mail.from.value[0].address)) return 0
if (!!cmd.mxdomainContains && !(mail.from.value[0].address.indexOf(cmd.mxdomainContains) > -1)) return 0 // mxdomainContains does not match
return !!cmd.ignore ? 1 : 2 // if ignore is set, lets break with 1, otherwise send page with 2
}
async function processMail(mail) {
let handling = "default"
let payload = config.handling.processing[handling]
payload = payload.replace("[subject]", mail.subject)
payload = payload.replace("[from]", mail.from.text)
payload = payload.replace("[fromName]", mail.from.value.name || mail.from.value.address)
payload = payload.replace("[fromAddress]", mail.from.value.address)
sendPage(payload)
for (processCommand of config.handling.processing) {
let res = checkMatch(mail, processCommand)
if (res) {
if (!!processCommand.format && !processCommand.ignore) {
let payload = processCommand.format
payload = payload.replace("[subject]", mail.subject)
payload = payload.replace("[from]", mail.from.text)
payload = payload.replace("[fromName]", mail.from.value[0].name || mail.from.value[0].address)
payload = payload.replace("[fromAddress]", mail.from.value[0].address)
sendPage(payload)
}
}
}
}
function ScanUnread() {
return $ImapConnection.openBox('INBOX')
.then(() => $ImapConnection.search(searchCriteria, fetchOptions))
.then((emails) => {
console.log('unreadCount:', emails.length)
if (config.handling.onlySimpleCounter === true) {
if (emails.length > 0 && config.handling.onlySimpleCounter === true) {
sendPage(config.handling.onlySimpleCounterFormat.replace("[unreadCount]", emails.length))
} else {
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`
if (ignoreImapIDs.indexOf(mail.attributes.uid) > -1) continue // Skip already notified mails
ignoreImapIDs.push(mail.attributes.uid)

Loading…
Cancel
Save