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)
end
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
function createentry(self)
......@@ -33,5 +33,5 @@ function createentry(self)
end
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
......@@ -7,6 +7,10 @@ require("viewfunctions")
form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action
if page_info.action == "editentry" then
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
local order = { "remotehost", "enabled", "method", "remotemailbox", "remotepassword", "ssl", "localhost", "localmailbox", "localdomain" }
displayform(form, order)
......
......@@ -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">Entry</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>
<% for i,entry in ipairs(data.value) do %>
<TR>
<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 = "deleteentry?entry=" .. entry.entry, label="Delete " }) %>
<% 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.."&method="..entry.method.."&remotemailbox="..entry.remotemailbox.."&localdomain="..entry.localdomain, label="Delete " }) %>
</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="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>
<% end %>
</TABLE>
......
......@@ -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
......
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