Browse Source

Add experimental ruleset manager

Alois Mahdal 4 years ago
parent
commit
cb298d08c9
4 changed files with 31 additions and 0 deletions
  1. 1
    0
      mkit.ini
  2. 1
    0
      packaging/debian/install
  3. 1
    0
      packaging/template.spec
  4. 28
    0
      src/imaprules.lua

+ 1
- 0
mkit.ini View File

@@ -39,6 +39,7 @@
39 39
 [files]
40 40
     bin     = src/imapdomo
41 41
     share   = src/imapdomo.lua
42
+    share   = src/imaprules.lua
42 43
     share   = src/main.lua
43 44
 
44 45
 #mkit version=0.0.40

+ 1
- 0
packaging/debian/install View File

@@ -1,3 +1,4 @@
1 1
 /usr/bin/imapdomo
2 2
 /usr/share/imapdomo/imapdomo.lua
3
+/usr/share/imapdomo/imaprules.lua
3 4
 /usr/share/imapdomo/main.lua

+ 1
- 0
packaging/template.spec View File

@@ -30,6 +30,7 @@ make %{?_smp_mflags}
30 30
 %dir %{_datadir}/%{name}
31 31
 %{_bindir}/%{name}
32 32
 %{_datadir}/%{name}/imapdomo.lua
33
+%{_datadir}/%{name}/imaprules.lua
33 34
 %{_datadir}/%{name}/main.lua
34 35
 
35 36
 %changelog

+ 28
- 0
src/imaprules.lua View File

@@ -0,0 +1,28 @@
1
+local pkg = {}
2
+
3
+pkg.STATE = {}
4
+
5
+pkg.SET = function(loader, ruleset)
6
+    pkg.STATE.loader = loader or function() return true end
7
+    pkg.STATE.ruleset = ruleset or {}
8
+    return true
9
+end
10
+
11
+pkg.RUN = function()
12
+    local i
13
+    for _, rule in ipairs(pkg.STATE.ruleset) do
14
+        i = rule.loader()
15
+        if not i then return end
16
+        rule.action(i)
17
+    end
18
+    pkg.SET()
19
+end
20
+
21
+pkg.ADD = function(action, loader)
22
+    local rule = {}
23
+    rule.action = action
24
+    rule.loader = loader or pkg.STATE.loader
25
+    table.insert(pkg.STATE, rule)
26
+end
27
+
28
+return pkg