ソースを参照

Simplify configuration

The host split turned to be a vast overengineering.
Alois Mahdal 8 年 前
コミット
49af39bb88
共有3 個のファイルを変更した15 個の追加36 個の削除を含む
  1. 12
    26
      src/common.lua
  2. 2
    3
      src/imapdomo.skel
  3. 1
    7
      src/main.lua.skel

+ 12
- 26
src/common.lua ファイルの表示

@@ -1,19 +1,10 @@
1 1
 os = require "os"
2
-socket = require "socket"
3 2
 
4 3
 
5 4
 ------------------------------------------------------------------------------
6 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 8
 function file_exists(name)
18 9
     --
19 10
     -- True if file *name* exists
@@ -27,39 +18,34 @@ function file_exists(name)
27 18
     end
28 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 28
         return
38 29
     end
39 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 37
     local valid = {
46 38
         newmail = true,
47 39
         rewind = true,
48 40
         cleanup = true,
49 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 45
         return nil
54 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 49
 end
64 50
 
65 51
 

+ 2
- 3
src/imapdomo.skel ファイルの表示

@@ -15,9 +15,8 @@ usage() {
15 15
             "-c DIR      change to DIR before doing anything"                 \
16 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 21
        "four valid actions are understood; since you must write handler for"  \
23 22
        "each action you want to use, the meanings below are purely a guide:"  \

+ 1
- 7
src/main.lua.skel ファイルの表示

@@ -2,10 +2,4 @@
2 2
 
3 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()