summaryrefslogtreecommitdiffstats
path: root/fetchmail-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'fetchmail-model.lua')
-rw-r--r--fetchmail-model.lua129
1 files changed, 64 insertions, 65 deletions
diff --git a/fetchmail-model.lua b/fetchmail-model.lua
index 5f589b4..330e68f 100644
--- a/fetchmail-model.lua
+++ b/fetchmail-model.lua
@@ -31,58 +31,54 @@ local function getmethods()
return methods
end
-local function getmailboxes()
- local mailboxes = {}
- for i=1,2 do
- local objects = cfe({})
- objects.label = "Mailbox_" .. tostring(i)
- objects.method = cfe({
- name="method",
- label = "Method",
- type = "select",
- value = "",
- option = getmethods(),
- })
- objects.disabled = cfe({
- name="disabled",
- type="checkbox",
- label = "Disabled",
- checked = "yes",
- })
- objects.remotehost = cfe({
- name="remotehost",
- label = "RemoteHost",
- value = "xxx_RemoteHost",
- })
- objects.remotemailbox = cfe({
- name="remotemailbox",
- label = "Mailbox",
- value = "xxx_RemoteMailbox",
- })
- objects.remotepassword = cfe({
- name="remotepassword",
- label = "Password",
- type = "text",
- value = "xxx_password",
- })
- objects.localhost = cfe({
- name="localhost",
- label = "LocalHost",
- value = "xxx_LocalHost",
- })
- objects.localmailbox = cfe({
- name="localmailbox",
- label = "LocalMailbox",
- value = "xxx_LocalMailbox",
- })
- objects.localdomain = cfe({
- name="localdomain",
- label = "LocalDomain",
- value = "xxx_LocalDomain",
- })
- table.insert(mailboxes, objects)
- end
- return mailboxes
+local function getmailboxes(t)
+ local objects = cfe({})
+ objects.label = "Mailbox " .. tostring(t["RBOX"])
+ objects.method = cfe({
+ name="method",
+ label = "Method",
+ type = "select",
+ value = t["METHOD"],
+ option = getmethods(),
+ })
+ objects.disabled = cfe({
+ name="disabled",
+ type="checkbox",
+ label = "Disabled",
+ checked = t["DISABLED"],
+ })
+ objects.remotehost = cfe({
+ name="remotehost",
+ label = "RemoteHost",
+ value = t["RHOST"],
+ })
+ objects.remotemailbox = cfe({
+ name="remotemailbox",
+ label = "Mailbox",
+ value = t["RBOX"],
+ })
+ objects.remotepassword = cfe({
+ name="remotepassword",
+ label = "Password",
+ type = "passwd",
+ value = t["PASSWD"],
+ })
+ objects.localhost = cfe({
+ name="localhost",
+ label = "LocalHost",
+ value = t["LHOST"],
+ })
+ objects.localmailbox = cfe({
+ name="localmailbox",
+ label = "LocalMailbox",
+ value = t["LBOX"],
+ })
+ objects.localdomain = cfe({
+ name="localdomain",
+ label = "LocalDomain",
+ value = t["DOMAIN"],
+ })
+ return objects
end
local function read_config()
@@ -103,16 +99,14 @@ etrn is:
1 2 3 4 5 6
pool <host> protocol etrn smtpdomain <mydomain>
--]]
--- local configcontent = {}
- local configcontent_popimap = {}
- local configcontent_popdomain = {}
+ local mailboxes = {}
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 (string.match(v, "^%s*#Begin Fetchmail")) 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
@@ -124,6 +118,7 @@ pool <host> protocol etrn smtpdomain <mydomain>
local val = {RHOST=2, CHECK=9 ,METHOD=4, RBOX=8, PASSWD=10, LBOX=12, LHOST=14}
local configcontent = {}
configcontent[k] = {}
+ configcontent[k]["DISABLED"] = DISABLED
for kk,vv in pairs(val) do
configcontent[k][kk] = tostring(string.match(v,"^%s*" .. string.rep("%S*%s*",vv-1) .. "(%S*)%s*"))
end
@@ -133,29 +128,33 @@ pool <host> protocol etrn smtpdomain <mydomain>
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])
+ table.insert(mailboxes,getmailboxes(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] = {}
+ configcontent[k]["DISABLED"] = DISABLED
for kk,vv in pairs(val) do
configcontent[k][kk] = tostring(string.match(v,"^%s*" .. string.rep("%S*%s*",vv-1) .. "(%S*)%s*"))
end
+ -- Display this config as Method=pop3domain (as the current options in the view)
+ configcontent[k]["METHOD"] = "pop3domain"
-- 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])
+ table.insert(mailboxes,getmailboxes(configcontent[k]))
end
-- Set parameters for etrn
local val = {ETRNSMTPHOST=2, CHECK=4, ETRNDOMAIN=6}
local configcontent = {}
configcontent[k] = {}
+ configcontent[k]["DISABLED"] = DISABLED
for kk,vv in pairs(val) do
configcontent[k][kk] = tostring(string.match(v,"^%s*" .. string.rep("%S*%s*",vv-1) .. "(%S*)%s*"))
end
@@ -168,6 +167,7 @@ pool <host> protocol etrn smtpdomain <mydomain>
local val = {CHECK=2, POSTMASTER=3}
local configcontent = {}
configcontent[k] = {}
+ configcontent[k]["DISABLED"] = DISABLED
for kk,vv in pairs(val) do
configcontent[k][kk] = tostring(string.match(v,"^%s*" .. string.rep("%S*%s*",vv-1) .. "(%S*)%s*"))
end
@@ -178,10 +178,9 @@ pool <host> protocol etrn smtpdomain <mydomain>
end
- if (string.match(v, "^%s*#End Fetchmail Webconf")) then valid=nil end
+ if (string.match(v, "^%s*#End Fetchmail")) then valid=nil end
end
- configcontent = configcontent_postmaster
- return configcontent,configcontent_etrn,configcontent_postmaster
+ return mailboxes,configcontent_postmaster,configcontent_etrn
end
-- ################################################################################
@@ -288,7 +287,7 @@ function get_filedetails()
end
function getconfig()
local config = {}
- local configcontent, configcontentetrn, configcontent_postmaster = read_config()
+ local mailboxes,configcontent_postmaster,configcontent_etrn = read_config()
if not (fs.is_file(configfile)) then
config["configfile"] = "Config file '".. configfile .. "' is missing!"
end
@@ -313,7 +312,7 @@ function getconfig()
config["mailboxes"] = cfe({
name="mailboxes",
label = "Mailboxes",
- value = getmailboxes(),
+ value = mailboxes,
})
config["postmaster"] = cfe({
name="postmaster",
@@ -323,12 +322,12 @@ function getconfig()
config["etrnremote"] = cfe({
name="etrnremote",
label = "Remote server",
- value = configcontentetrn["ETRNSMTPHOST"],
+ value = configcontent_etrn["ETRNSMTPHOST"],
})
config["etrnquedomain"] = cfe({
name="etrnquedomain",
label = "Queued domain",
- value = configcontentetrn["ETRNDOMAIN"],
+ value = configcontent_etrn["ETRNDOMAIN"],
})
--[[