diff options
Diffstat (limited to 'fetchmail-model.lua')
-rw-r--r-- | fetchmail-model.lua | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/fetchmail-model.lua b/fetchmail-model.lua index 7b0e3df..b92e1e7 100644 --- a/fetchmail-model.lua +++ b/fetchmail-model.lua @@ -46,12 +46,27 @@ local function parseconfigfile(file) return retval end -local function findentryline(entryname) +local function findentryline(entryname, method, remotemailbox, localdomain) if entryname and entryname ~= "" then config = config or parseconfigfile(fs.read_file(configfile)) for i,entry in ipairs(config or {}) do if (entry[1] == "server" or entry[1] == "poll" or entry[1] == "skip") and entry[2] == entryname then - return entry + local reverseentry = {} + for i,word in ipairs(entry) do reverseentry[word] = i end + -- For pop3domain, check the localdomain + if method == "pop3domain" and (reverseentry["local"] or reverseentry["localdomains"]) then + if entry[(reverseentry["local"] or reverseentry["localdomains"])+1] == localdomain then + return entry + end + -- For etrn, no further check + elseif method == "etrn" and reverseentry["etrn"] then + return entry + -- For pop3 and imap, check the username + elseif method == "pop3" or method == "imap" then + if reverseentry["username"] and entry[reverseentry["username"]+1] == remotemailbox then + return entry + end + end end end end @@ -392,20 +407,28 @@ function readentries() local reverseentry = {} for i,word in ipairs(entry) do reverseentry[word] = i end local method = "error" + local localdomain = "" if reverseentry["local"] or reverseentry["localdomains"] then method = "pop3domain" + if entry[(reverseentry["local"] or reverseentry["localdomains"])+1] then + localdomain = entry[(reverseentry["local"] or reverseentry["localdomains"])+1] + end elseif reverseentry["proto"] or reverseentry["protocol"] then method = entry[(reverseentry["proto"] or reverseentry["protocol"])+1] or method end local enabled = true if entry[1] == "skip" then enabled=false end - table.insert(entries.value, {entry=entry[2], method=method, enabled=enabled}) + local username = "" + if reverseentry["username"] and entry[reverseentry["username"]+1] then + username = entry[reverseentry["username"]+1] + end + table.insert(entries.value, {entry=entry[2], method=method, enabled=enabled, remotemailbox=username, localdomain=localdomain}) end end return entries end -function readentry(entryname) +function readentry(entryname, meth, remotemailbx, localdom) local enabled = cfe({ type="boolean", value=true, label="Enable" }) local method = cfe({ type="select", value="pop3", label="Method", option=methods }) local remotehost = cfe({ value=entryname, label="Remote Host" }) @@ -416,7 +439,7 @@ function readentry(entryname) local localdomain = cfe({ label="Local Domain" }) local ssl = cfe({ type="boolean", value=false, label="SSL Encryption" }) - local entry = findentryline(entryname) + local entry = findentryline(entryname, meth, remotemailbx, localdom) if entry then if entry[1] == "skip" then enabled.value = false @@ -454,7 +477,7 @@ end function updateentry(entrystruct) local success, entrystruct = validateentry(entrystruct) - local entry = findentryline(entrystruct.value.remotehost.value) + local entry = findentryline(entrystruct.value.remotehost.value, entrystruct.value.method.value, entrystruct.value.remotemailbox.value, entrystruct.value.localdomain.value) if not entry then entrystruct.value.remotehost.errtxt = "Entry not found" success = false @@ -471,7 +494,7 @@ end function createentry(entrystruct) local success, entrystruct = validateentry(entrystruct) - local entry = findentryline(entrystruct.value.remotehost.value) + local entry = findentryline(entrystruct.value.remotehost.value, entrystruct.value.method.value, entrystruct.value.remotemailbox.value, entrystruct.value.localdomain.value) if entry then entrystruct.value.remotehost.errtxt = "Entry already exists" success = false @@ -480,15 +503,15 @@ function createentry(entrystruct) if success then writeentryline(entrystruct) else - entrystruct.errtxt = "Failed to update entry" + entrystruct.errtxt = "Failed to create entry" end return entrystruct end -function deleteentry(entryname) +function deleteentry(entryname, method, remotemailbox, localdomain) local retval = cfe({ value="Deleted entry", label="Delete Fetchmail Entry Result" }) - local entry = findentryline(entryname) + local entry = findentryline(entryname, method, remotemailbox, localdomain) if entry then writeentryline(nil, entry) else |