|
@@ -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
|
|