Browse Source

Simplify configuration

The host split turned to be a vast overengineering.
Alois Mahdal 8 years ago
parent
commit
49af39bb88
3 changed files with 15 additions and 36 deletions
  1. 12
    26
      src/common.lua
  2. 2
    3
      src/imapdomo.skel
  3. 1
    7
      src/main.lua.skel

+ 12
- 26
src/common.lua View File

1
 os = require "os"
1
 os = require "os"
2
-socket = require "socket"
3
 
2
 
4
 
3
 
5
 ------------------------------------------------------------------------------
4
 ------------------------------------------------------------------------------
6
 -- config and handling                                                      --
5
 -- config and handling                                                      --
7
 ------------------------------------------------------------------------------
6
 ------------------------------------------------------------------------------
8
 
7
 
9
-function shortname()
10
-    --
11
-    -- Short hostname
12
-    --
13
-    local long = socket.dns.gethostname()
14
-    return string.gmatch(long, '[^.]+')()
15
-end
16
-
17
 function file_exists(name)
8
 function file_exists(name)
18
     --
9
     --
19
     -- True if file *name* exists
10
     -- True if file *name* exists
27
     end
18
     end
28
 end
19
 end
29
 
20
 
30
-function init_host(session)
21
+function do_if_exists(filename)
31
     --
22
     --
32
-    -- Do host-specific init, if exists
23
+    -- Do file from home, if exists
33
     --
24
     --
34
-    local init = session.dirs.host .. "/init.lua"
35
-    if file_exists(init) then
36
-        dofile(init)
25
+    local file = os.getenv("IMAPFILTER_HOME") .. "/" .. filename
26
+    if file_exists(file) then
27
+        dofile(file)
37
         return
28
         return
38
     end
29
     end
39
 end
30
 end
40
 
31
 
41
-function handle(session)
32
+function handle()
42
     --
33
     --
43
-    -- Look for action handler in session dirs; do first one that exists
34
+    -- Handle action if it's valid
44
     --
35
     --
36
+    local action = os.getenv("IMAPDOMO_ACTION")
45
     local valid = {
37
     local valid = {
46
         newmail = true,
38
         newmail = true,
47
         rewind = true,
39
         rewind = true,
48
         cleanup = true,
40
         cleanup = true,
49
         migrate = true
41
         migrate = true
50
     }
42
     }
51
-    if not valid[session.action] then
52
-        error("invalid action: " .. session.action)
43
+    if not valid[action] then
44
+        error("invalid action: " .. action)
53
         return nil
45
         return nil
54
     end
46
     end
55
-    init_host(session)
56
-    for k,v in ipairs({session.dirs.host, session.dirs.default}) do
57
-        attempt = v .. "/handlers/" .. session.action .. ".lua"
58
-        if file_exists(attempt) then
59
-            dofile(attempt)
60
-            return
61
-        end
62
-    end
47
+    do_if_exists("init.lua")
48
+    do_if_exists("handlers/" .. action .. ".lua")
63
 end
49
 end
64
 
50
 
65
 
51
 

+ 2
- 3
src/imapdomo.skel View File

15
             "-c DIR      change to DIR before doing anything"                 \
15
             "-c DIR      change to DIR before doing anything"                 \
16
             "-d          turn on debugging mode"                              \
16
             "-d          turn on debugging mode"                              \
17
        --                                                                     \
17
        --                                                                     \
18
-       "imapdomo will try to read .imapdomo/host/HOSTNAME/init.lua and"       \
19
-       ".imapdomo/host/HOSTNAME/handlers/ACTION.lua, where HOSTNAME is your"  \
20
-       "short hostname (eg. 'foo' in 'foo.example.com')."                     \
18
+       "imapdomo will try to read init.lua and handlers/ACTION.lua from its"  \
19
+       "configuration directory."                                             \
21
        ""                                                                     \
20
        ""                                                                     \
22
        "four valid actions are understood; since you must write handler for"  \
21
        "four valid actions are understood; since you must write handler for"  \
23
        "each action you want to use, the meanings below are purely a guide:"  \
22
        "each action you want to use, the meanings below are purely a guide:"  \

+ 1
- 7
src/main.lua.skel View File

2
 
2
 
3
 dofile "__IMAPDOMO_SHARE__/common.lua"
3
 dofile "__IMAPDOMO_SHARE__/common.lua"
4
 
4
 
5
-handle({
6
-    action = os.getenv("IMAPDOMO_ACTION"),
7
-    dirs = {
8
-        host = os.getenv("IMAPFILTER_HOME") .. "/host/" .. shortname(),
9
-        defhost = os.getenv("IMAPFILTER_HOME") .. "/default",
10
-    }
11
-})
5
+handle()