|
@@ -1,74 +0,0 @@
|
1
|
|
-os = require "os"
|
2
|
|
-socket = require "socket"
|
3
|
|
-
|
4
|
|
-function shortname()
|
5
|
|
- local long = socket.dns.gethostname()
|
6
|
|
- return string.gmatch(long, '[^.]+')()
|
7
|
|
-end
|
8
|
|
-
|
9
|
|
-function get_queue(mbox)
|
10
|
|
- --TODO: try to get tail
|
11
|
|
- return mbox.FILTER_QUEUE:is_newer(84)
|
12
|
|
-end
|
13
|
|
-
|
14
|
|
-function _notifirc1(subj, from, body)
|
15
|
|
- --notify about message using (pre-configured) notifirc
|
16
|
|
- local fd = assert(io.popen('notifirc -f - "message preview:"', "w"))
|
17
|
|
- local fmt = "> %s\n> %s\n> BODY: %s"
|
18
|
|
- fd:write(fmt:format(subj, from, body))
|
19
|
|
- fd:close()
|
20
|
|
-end
|
21
|
|
-
|
22
|
|
-function notifirc_all(seq)
|
23
|
|
- for _, mesg in ipairs(seq) do
|
24
|
|
- mbox, uid = table.unpack(mesg)
|
25
|
|
- subj = mbox[uid]:fetch_field('Subject')
|
26
|
|
- from = mbox[uid]:fetch_field('From')
|
27
|
|
- body = mbox[uid]:fetch_body()
|
28
|
|
- _notifirc1(subj, from, body)
|
29
|
|
- end
|
30
|
|
-end
|
31
|
|
-
|
32
|
|
-function _partinf_compare(a, b)
|
33
|
|
- if not type(a) == type(b) then
|
34
|
|
- return false
|
35
|
|
- end
|
36
|
|
- if type(a) == 'number' then
|
37
|
|
- return a == b
|
38
|
|
- elseif type(a) == 'string' then
|
39
|
|
- return a:lower() == b:lower()
|
40
|
|
- end
|
41
|
|
-end
|
42
|
|
-
|
43
|
|
-function has_part_like(query, structure)
|
44
|
|
- if structure == nil then
|
45
|
|
- return false
|
46
|
|
- end
|
47
|
|
- for partid, partinf in pairs(structure) do
|
48
|
|
- local part_answer = true
|
49
|
|
- -- check all query parts
|
50
|
|
- for qkey, qvalue in pairs(query) do
|
51
|
|
- value = partinf[qkey]
|
52
|
|
- if not _partinf_compare(value, qvalue) then
|
53
|
|
- part_answer = false
|
54
|
|
- break
|
55
|
|
- end
|
56
|
|
- end
|
57
|
|
- if part_answer then
|
58
|
|
- return true
|
59
|
|
- end
|
60
|
|
- end
|
61
|
|
- return false
|
62
|
|
-end
|
63
|
|
-
|
64
|
|
-function filter_part_like(query, seq)
|
65
|
|
- result = Set {}
|
66
|
|
- for _, mesg in ipairs(seq) do
|
67
|
|
- mbox, uid = table.unpack(mesg)
|
68
|
|
- structure = mbox[uid]:fetch_structure()
|
69
|
|
- if has_part_like(query, structure) then
|
70
|
|
- table.insert(result, mesg)
|
71
|
|
- end
|
72
|
|
- end
|
73
|
|
- return result
|
74
|
|
-end
|