/
mail-check.js
48 lines (44 loc) 路 1.38 KB
/
mail-check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const shell = require('child_process').execSync;
const exec = require('child_process').exec;
//this file contains two strings that query mu like `mu find --fields='f: s' 'NOT blahblah'`.
const queries = require('./mail-check-queries');
const refresh =
"Refresh | terminal=false bash='mbsync -a; pkill -2 -u $UID mu; sleep 1; mu index --maildir=~/Mail'";
const computedCount = shell(queries.count, '', { shell: true }).toString();
const computedContent = () =>
new Promise((resolve, reject) => {
exec(queries.content, { shell: true }, (e, st) => {
if (e) {
reject(e);
}
resolve(
st
.toString()
.split('\n')
.map(x => x.replace('<', '<').replace('>', '>'))
);
});
});
computedContent()
.then(content => {
if (computedCount !== '0') {
console.log(
`:mailbox_with_mail: ${computedCount.trim()} | size=11 usemarkup=false ansi=false`
);
console.log('---');
content.forEach(x => console.log(x));
console.log('---');
console.log(refresh);
console.log(
"View GNOME Shell Log | bash='journalctl /usr/bin/gnome-shell -f'"
);
}
})
.catch(() => {
console.log(':mailbox_with_no_mail: | size=11');
console.log('---');
console.log(refresh);
console.log(
"View GNOME Shell Log | bash='journalctl /usr/bin/gnome-shell -f'"
);
});