Browse Source

Add common config for imapfilter

Alois Mahdal 8 years ago
parent
commit
b59fdc7c7a

+ 1
- 0
.gitignore View File

@@ -3,6 +3,7 @@
3 3
 .netrwhist
4 4
 */gittum/private.gitconfig
5 5
 */vim/bundle/private/*
6
+dotfiles/imapfilter/private
6 7
 dotfiles/moc/cache/
7 8
 dotfiles/moc/equalizer
8 9
 dotfiles/moc/last_directory

+ 55
- 0
dotfiles/imapfilter/common/functions.lua View File

@@ -0,0 +1,55 @@
1
+socket = require "socket"
2
+
3
+function shortname()
4
+    local long = socket.dns.gethostname()
5
+    return string.gmatch(long, '[^.]+')()
6
+end
7
+
8
+function get_queue(mbox)
9
+    --TODO: try to get tail
10
+    return mbox.FILTER_QUEUE:is_newer(84)
11
+end
12
+
13
+function _partinf_compare(a, b)
14
+    if not type(a) == type(b) then
15
+        return false
16
+    end
17
+    if type(a) == 'number' then
18
+        return a == b
19
+    elseif type(a) == 'string' then
20
+        return a:lower() == b:lower()
21
+    end
22
+end
23
+
24
+function has_part_like(query, structure)
25
+    if structure == nil then
26
+        return false
27
+    end
28
+    for partid, partinf in pairs(structure) do
29
+        local part_answer = true
30
+        -- check all query parts
31
+        for qkey, qvalue in pairs(query) do
32
+            value = partinf[qkey]
33
+            if not _partinf_compare(value, qvalue) then
34
+                part_answer = false
35
+                break
36
+            end
37
+        end
38
+        if part_answer then
39
+            return true
40
+        end
41
+    end
42
+    return false
43
+end
44
+
45
+function filter_part_like(query, seq)
46
+    result = Set {}
47
+    for _, mesg in ipairs(seq) do
48
+        mbox, uid = table.unpack(mesg)
49
+        structure = mbox[uid]:fetch_structure()
50
+        if has_part_like(query, structure) then
51
+            table.insert(result, mesg)
52
+        end
53
+    end
54
+    return result
55
+end

+ 6
- 0
dotfiles/imapfilter/config.lua View File

@@ -0,0 +1,6 @@
1
+dofile ".imapfilter/common/functions.lua"
2
+
3
+host_folder = ".imapfilter/host/" .. shortname()
4
+dofile (host_folder .. "/accounts.lua")
5
+dofile (host_folder .. "/options.lua")
6
+dofile (host_folder .. "/rules.lua")

+ 1
- 0
dotfiles/imapfilter/host View File

@@ -0,0 +1 @@
1
+../../external/dotfiles/imapfilter/host

+ 4
- 0
dotfiles/imapfilter/private/README View File

@@ -0,0 +1,4 @@
1
+Keep here only files that are never to leave the particular
2
+machine ie. never to be backed up or synchronized.
3
+
4
+This folder should be auto-ignored by all such tools.