-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (52 loc) · 1.92 KB
/
index.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const { config } = require('./config')
const { create } = require('xmlbuilder2')
class Filter {
constructor(config) {
this.feed = create({version: '1.0', encoding: 'UTF-8'})
.ele('feed', {
'xmlns': 'http://www.w3.org/2005/Atom',
'xmlns:apps': 'http://schemas.google.com/apps/2006'
})
if (!config) {
return
}
for (let label in config) {
this.add(label, config[label])
}
}
add(label, options) {
options = {
...options,
from: options.from === undefined ? `*@${label}` : options.from,
}
let entry = this.feed.ele('entry')
entry.ele('category', {term: 'filter'}).up()
if (options.from) {
entry.ele('apps:property', {name: 'from', value: options.from}).up()
}
if (options.match) {
entry.ele('apps:property', {name: 'hasTheWord', value: options.match}).up()
}
if (options.neMatch) {
entry.ele('apps:property', {name: 'doesNotHaveTheWord', value: options.neMatch}).up()
}
entry.ele('apps:property', {name: 'label', value: label}).up()
entry.ele('apps:property', {name: 'shouldArchive', value: options.archive === false ? 'false' : 'true'}).up()
entry.ele('apps:property', {name: 'shouldMarkAsRead', value: options.read === true ? 'true' : 'false'}).up()
entry.up()
if (options.labels) {
for (let sublabel in options.labels) {
this.add(`${label}/${sublabel}`, {
from: options.from,
match: options.match,
neMatch: options.neMatch,
...options.labels[sublabel]
})
}
}
}
end() {
return this.feed.end({prettyPrint: true})
}
}
console.log(new Filter(config).end())