Commit 6c8e660d authored by Ted Trask's avatar Ted Trask

Modified fetchmail to specify an entry by server, method, mailbox, and domain...

Modified fetchmail to specify an entry by server, method, mailbox, and domain instead of just by server.

git-svn-id: svn://svn.alpinelinux.org/acf/fetchmail/trunk@1598 ab2d0c66-481e-0410-8bed-d214d4d58bed
parent a1165702
...@@ -25,7 +25,7 @@ function listentries(self) ...@@ -25,7 +25,7 @@ function listentries(self)
end end
function editentry(self) function editentry(self)
return controllerfunctions.handle_form(self, function() return self.model.readentry(self.clientdata.entry) end, self.model.updateentry, self.clientdata, "Save", "Edit Entry", "Entry Saved") return controllerfunctions.handle_form(self, function() return self.model.readentry(self.clientdata.entry, self.clientdata.method, self.clientdata.remotemailbox, self.clientdata.localdomain) end, self.model.updateentry, self.clientdata, "Save", "Edit Entry", "Entry Saved")
end end
function createentry(self) function createentry(self)
...@@ -33,5 +33,5 @@ function createentry(self) ...@@ -33,5 +33,5 @@ function createentry(self)
end end
function deleteentry(self) function deleteentry(self)
return self:redirect_to_referrer(self.model.deleteentry(self.clientdata.entry)) return self:redirect_to_referrer(self.model.deleteentry(self.clientdata.entry, self.clientdata.method, self.clientdata.remotemailbox, self.clientdata.localdomain))
end end
...@@ -7,6 +7,10 @@ require("viewfunctions") ...@@ -7,6 +7,10 @@ require("viewfunctions")
form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action
if page_info.action == "editentry" then if page_info.action == "editentry" then
form.value.remotehost.contenteditable = false form.value.remotehost.contenteditable = false
form.value.method.type = "text"
form.value.method.contenteditable = false
form.value.remotemailbox.contenteditable = false
form.value.localdomain.contenteditable = false
end end
local order = { "remotehost", "enabled", "method", "remotemailbox", "remotepassword", "ssl", "localhost", "localmailbox", "localdomain" } local order = { "remotehost", "enabled", "method", "remotemailbox", "remotepassword", "ssl", "localhost", "localmailbox", "localdomain" }
displayform(form, order) displayform(form, order)
......
...@@ -18,17 +18,19 @@ io.write("</span>") ...@@ -18,17 +18,19 @@ io.write("</span>")
<TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Action</TD> <TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Action</TD>
<TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Entry</TD> <TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Entry</TD>
<TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Enabled</TD> <TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Enabled</TD>
<TD style="white-space:nowrap;text-align:left;" class="header">Method</TD> <TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Method</TD>
<TD style="white-space:nowrap;text-align:left;" class="header">Remote Mailbox / Domain</TD>
</TR> </TR>
<% for i,entry in ipairs(data.value) do %> <% for i,entry in ipairs(data.value) do %>
<TR> <TR>
<TD style="padding-right:20px;white-space:nowrap;"> <TD style="padding-right:20px;white-space:nowrap;">
<% io.write(html.link{value = "editentry?entry=" .. entry.entry.."&redir="..page_info.orig_action, label="Edit " }) %> <% io.write(html.link{value = "editentry?entry=" .. entry.entry.."&method="..entry.method.."&remotemailbox="..entry.remotemailbox.."&localdomain="..entry.localdomain.."&redir="..page_info.orig_action, label="Edit " }) %>
<% io.write(html.link{value = "deleteentry?entry=" .. entry.entry, label="Delete " }) %> <% io.write(html.link{value = "deleteentry?entry=" .. entry.entry.."&method="..entry.method.."&remotemailbox="..entry.remotemailbox.."&localdomain="..entry.localdomain, label="Delete " }) %>
</TD> </TD>
<TD style="padding-right:20px;white-space:nowrap;"><%= entry.entry %></TD> <TD style="padding-right:20px;white-space:nowrap;"><%= entry.entry %></TD>
<TD style="padding-right:20px;white-space:nowrap;"><%= entry.enabled %></TD> <TD style="padding-right:20px;white-space:nowrap;"><%= entry.enabled %></TD>
<TD style="white-space:nowrap;" width="90%"><%= entry.method %></TD> <TD style="padding-right:20px;white-space:nowrap;"><%= entry.method %></TD>
<TD style="white-space:nowrap;" width="90%"><% if entry.localdomain and entry.localdomain ~= "" then io.write(entry.localdomain) else io.write(entry.remotemailbox) end %></TD>
</TR> </TR>
<% end %> <% end %>
</TABLE> </TABLE>
......
...@@ -46,12 +46,27 @@ local function parseconfigfile(file) ...@@ -46,12 +46,27 @@ local function parseconfigfile(file)
return retval return retval
end end
local function findentryline(entryname) local function findentryline(entryname, method, remotemailbox, localdomain)
if entryname and entryname ~= "" then if entryname and entryname ~= "" then
config = config or parseconfigfile(fs.read_file(configfile)) config = config or parseconfigfile(fs.read_file(configfile))
for i,entry in ipairs(config or {}) do 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 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 end
end end
...@@ -392,20 +407,28 @@ function readentries() ...@@ -392,20 +407,28 @@ function readentries()
local reverseentry = {} local reverseentry = {}
for i,word in ipairs(entry) do reverseentry[word] = i end for i,word in ipairs(entry) do reverseentry[word] = i end
local method = "error" local method = "error"
local localdomain = ""
if reverseentry["local"] or reverseentry["localdomains"] then if reverseentry["local"] or reverseentry["localdomains"] then
method = "pop3domain" 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 elseif reverseentry["proto"] or reverseentry["protocol"] then
method = entry[(reverseentry["proto"] or reverseentry["protocol"])+1] or method method = entry[(reverseentry["proto"] or reverseentry["protocol"])+1] or method
end end
local enabled = true local enabled = true
if entry[1] == "skip" then enabled=false end 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
end end
return entries return entries
end end
function readentry(entryname) function readentry(entryname, meth, remotemailbx, localdom)
local enabled = cfe({ type="boolean", value=true, label="Enable" }) local enabled = cfe({ type="boolean", value=true, label="Enable" })
local method = cfe({ type="select", value="pop3", label="Method", option=methods }) local method = cfe({ type="select", value="pop3", label="Method", option=methods })
local remotehost = cfe({ value=entryname, label="Remote Host" }) local remotehost = cfe({ value=entryname, label="Remote Host" })
...@@ -416,7 +439,7 @@ function readentry(entryname) ...@@ -416,7 +439,7 @@ function readentry(entryname)
local localdomain = cfe({ label="Local Domain" }) local localdomain = cfe({ label="Local Domain" })
local ssl = cfe({ type="boolean", value=false, label="SSL Encryption" }) 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 then
if entry[1] == "skip" then if entry[1] == "skip" then
enabled.value = false enabled.value = false
...@@ -454,7 +477,7 @@ end ...@@ -454,7 +477,7 @@ end
function updateentry(entrystruct) function updateentry(entrystruct)
local success, entrystruct = validateentry(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 if not entry then
entrystruct.value.remotehost.errtxt = "Entry not found" entrystruct.value.remotehost.errtxt = "Entry not found"
success = false success = false
...@@ -471,7 +494,7 @@ end ...@@ -471,7 +494,7 @@ end
function createentry(entrystruct) function createentry(entrystruct)
local success, entrystruct = validateentry(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 if entry then
entrystruct.value.remotehost.errtxt = "Entry already exists" entrystruct.value.remotehost.errtxt = "Entry already exists"
success = false success = false
...@@ -480,15 +503,15 @@ function createentry(entrystruct) ...@@ -480,15 +503,15 @@ function createentry(entrystruct)
if success then if success then
writeentryline(entrystruct) writeentryline(entrystruct)
else else
entrystruct.errtxt = "Failed to update entry" entrystruct.errtxt = "Failed to create entry"
end end
return entrystruct return entrystruct
end end
function deleteentry(entryname) function deleteentry(entryname, method, remotemailbox, localdomain)
local retval = cfe({ value="Deleted entry", label="Delete Fetchmail Entry Result" }) 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 if entry then
writeentryline(nil, entry) writeentryline(nil, entry)
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment