summaryrefslogtreecommitdiffstats
path: root/fetchmail-model.lua
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-02-04 16:52:27 +0000
committerMika Havela <mika.havela@gmail.com>2008-02-04 16:52:27 +0000
commit10086c539c85fd11cd1c5339e7659b8c04ffb525 (patch)
tree7d9418973296190778d586e50e0c1cbbe32b67bd /fetchmail-model.lua
parent2eb595dbab74f76c42f44193945eba48144873ba (diff)
downloadacf-fetchmail-10086c539c85fd11cd1c5339e7659b8c04ffb525.tar.bz2
acf-fetchmail-10086c539c85fd11cd1c5339e7659b8c04ffb525.tar.xz
Config-tab information: Some config-info is displayed in the config-tab.
Postmaster and etrn info (if it exists in the config). git-svn-id: svn://svn.alpinelinux.org/acf/fetchmail/trunk@688 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'fetchmail-model.lua')
-rw-r--r--fetchmail-model.lua118
1 files changed, 111 insertions, 7 deletions
diff --git a/fetchmail-model.lua b/fetchmail-model.lua
index 2be471b..5f589b4 100644
--- a/fetchmail-model.lua
+++ b/fetchmail-model.lua
@@ -85,6 +85,105 @@ local function getmailboxes()
return mailboxes
end
+local function read_config()
+--[[
+imap/pop3 lines are:
+1 2 3 4 5 6 7 8 9 10
+poll <host> protocol <proto> no dns username <uname> password <passwd>
+11 12 13 14 15 16 17
+is <localmailbox> smtphost <desthost> no rewrite fetchall
+
+pop3domain lines are:
+1 2 3 4 5 6 7 8 9 10 11 12
+poll <host> localdomainst <domain> protocol pop3 no dns username <uname> password <passwd>
+13 14 15 16 17 18 19 20 21 22
+to * here smtphost <desthost> smtpaddress <domain> no rewrite fetchall
+
+etrn is:
+1 2 3 4 5 6
+pool <host> protocol etrn smtpdomain <mydomain>
+--]]
+-- local configcontent = {}
+ local configcontent_popimap = {}
+ local configcontent_popdomain = {}
+ local configcontent_postmaster = {}
+ local configcontent_etrn = {}
+ local path = configfile
+ local valid = nil
+ configcontenttable = fs.read_file_as_array(path) or {}
+ for k,v in pairs(configcontenttable) do
+ if (string.match(v, "^%s*#Begin Fetchmail Webconf")) then valid=1 end
+ if (valid) then
+-- if not (configcontent[k]) then configcontent[k] = {} end
+-- if not (configcontent_popimap[k]) then configcontent_popimap[k] = {} end
+-- if not (configcontent_popdomain[k]) then configcontent_popdomain[k] = {} end
+
+ local DISABLED = string.match(v, "^%s*(#)")
+
+ -- Set parameters for POP3 or IMAP
+ local val = {RHOST=2, CHECK=9 ,METHOD=4, RBOX=8, PASSWD=10, LBOX=12, LHOST=14}
+ local configcontent = {}
+ configcontent[k] = {}
+ for kk,vv in pairs(val) do
+ configcontent[k][kk] = tostring(string.match(v,"^%s*" .. string.rep("%S*%s*",vv-1) .. "(%S*)%s*"))
+ end
+ -- Remove quotes from passwords
+ if (configcontent[k]["PASSWD"]) then
+ configcontent[k]["PASSWD"] = string.match(configcontent[k]["PASSWD"], "^\"(.-)\"")
+ end
+ -- Check if row is valid config
+ if (configcontent[k]["CHECK"]) and (string.lower(configcontent[k]["CHECK"]) == "password") then
+ table.insert(configcontent_popimap,configcontent[k])
+ end
+
+ -- Set parameters for POP3domain
+ local val = {RHOST=2, METHOD=6, RBOX=10, CHECK=11, PASSWD=12, LHOST=17, DOMAIN=19,}
+ local configcontent = {}
+ configcontent[k] = {}
+ for kk,vv in pairs(val) do
+ configcontent[k][kk] = tostring(string.match(v,"^%s*" .. string.rep("%S*%s*",vv-1) .. "(%S*)%s*"))
+ end
+ -- Remove quotes from passwords
+ if (configcontent[k]["PASSWD"]) then
+ configcontent[k]["PASSWD"] = string.match(configcontent[k]["PASSWD"], "^\"(.-)\"")
+ end
+ -- Check if row is valid config
+ if (configcontent[k]["CHECK"]) and (string.lower(configcontent[k]["CHECK"]) == "password") then
+ table.insert(configcontent_popdomain,configcontent[k])
+ end
+
+ -- Set parameters for etrn
+ local val = {ETRNSMTPHOST=2, CHECK=4, ETRNDOMAIN=6}
+ local configcontent = {}
+ configcontent[k] = {}
+ for kk,vv in pairs(val) do
+ configcontent[k][kk] = tostring(string.match(v,"^%s*" .. string.rep("%S*%s*",vv-1) .. "(%S*)%s*"))
+ end
+ -- Check if row is valid config
+ if (configcontent[k]["CHECK"]) and (string.lower(configcontent[k]["CHECK"]) == "etrn") then
+ configcontent_etrn=configcontent[k]
+ end
+
+ -- Set parameters for postmaster
+ local val = {CHECK=2, POSTMASTER=3}
+ local configcontent = {}
+ configcontent[k] = {}
+ for kk,vv in pairs(val) do
+ configcontent[k][kk] = tostring(string.match(v,"^%s*" .. string.rep("%S*%s*",vv-1) .. "(%S*)%s*"))
+ end
+ -- Check if row is valid config
+ if (configcontent[k]["CHECK"]) and (string.lower(configcontent[k]["CHECK"]) == "postmaster") then
+ configcontent_postmaster=configcontent[k]
+ end
+
+
+ end
+ if (string.match(v, "^%s*#End Fetchmail Webconf")) then valid=nil end
+ end
+ configcontent = configcontent_postmaster
+ return configcontent,configcontent_etrn,configcontent_postmaster
+
+end
-- ################################################################################
-- PUBLIC FUNCTIONS
@@ -139,7 +238,6 @@ function get_filedetails()
local config = {}
local filenameerrtxt
if (fs.is_file(path)) then
- configcontent = getopts.getoptsfromfile(path) or config
filedetails = fs.stat(path)
config = getconfig(path)
else
@@ -190,12 +288,18 @@ function get_filedetails()
end
function getconfig()
local config = {}
- if (fs.is_file(configfile)) then
- configcontent = getopts.getoptsfromfile(configfile) or config
- else
+ local configcontent, configcontentetrn, configcontent_postmaster = read_config()
+ if not (fs.is_file(configfile)) then
config["configfile"] = "Config file '".. configfile .. "' is missing!"
end
+ config["debug"] = cfe({
+ name="debug",
+ label = "Debug info",
+ type = "longtext",
+ value = configcontent,
+ })
+
-- Next section selects which configurations we should show to the user
@@ -214,17 +318,17 @@ function getconfig()
config["postmaster"] = cfe({
name="postmaster",
label = "Postmaster",
- value = "xxx@xxx.xx",
+ value = configcontent_postmaster["POSTMASTER"],
})
config["etrnremote"] = cfe({
name="etrnremote",
label = "Remote server",
- value = "xxx",
+ value = configcontentetrn["ETRNSMTPHOST"],
})
config["etrnquedomain"] = cfe({
name="etrnquedomain",
label = "Queued domain",
- value = "xxx",
+ value = configcontentetrn["ETRNDOMAIN"],
})
--[[