fix some of the issues from PR #4 (still does not work but the initial work should be done)

This commit is contained in:
BuckarooBanzay 2020-08-02 16:19:07 +02:00
parent f5f21feb49
commit 6bf2e5fc41
3 changed files with 21 additions and 38 deletions

30
api.lua
View file

@ -29,36 +29,20 @@ function mail.send(src, dst, subject, body)
end
-- log mail send action
if m.cc or m.bcc then
if m.cc then
cc = "CC: " .. m.cc
if m.bcc then
cc = cc .. " - "
end
else
cc = ""
end
if m.bcc then
bcc = "BCC: " .. m.bcc
else
bcc = ""
end
extra = "(" .. cc .. bcc .. ") "
else
extra = ""
end
minetest.log("action", "[mail] '" .. m.from .. "' sends mail to '" .. m.to ..
extra .. "' with subject '" .. m.subject .. "' and body: '" .. m.body .. "'")
minetest.log("action", "[mail] '" .. m.from .. "' sends mail to '" .. m.to .. "', " ..
"cc: ''" .. m.cc .. "', " ..
"bcc: ''" .. m.bcc .. "', " ..
"with subject '" .. m.subject .. "' and body: '" .. m.body .. "'")
-- normalize to, cc and bcc while compiling a list of all recipients
local recipients = {}
m.to = normalize_players_and_add_recipients(m.to, recipients)
m.to = mail.normalize_players_and_add_recipients(m.to, recipients)
if m.cc then
m.cc = normalize_players_and_add_recipients(m.cc, recipients)
m.cc = mail.normalize_players_and_add_recipients(m.cc, recipients)
end
if m.bcc then
m.bcc = normalize_players_and_add_recipients(m.bcc, recipients)
m.bcc = mail.normalize_players_and_add_recipients(m.bcc, recipients)
end
-- form the actual mail

27
gui.lua
View file

@ -99,23 +99,22 @@ end
function mail.show_compose(name, defaultto, defaultsubj, defaultbody, defaultcc, defaultbcc)
local formspec = [[
size[8,7.2]
field[0.25,0.5;4,1;to;To:;%s]
field[0.25,0.5;4,1;to;CC:;%s]
field[0.25,0.5;4,1;to;BCC:;%s]
field[0.25,1.7;8,1;subject;Subject:;%s]
textarea[0.25,2.4;8,5;body;;%s]
button[0.5,6.7;3,1;cancel;Cancel]
button[7,0;1,0.5;cancel;X]
button[4.5,6.7;3,1;send;Send]
size[8,9.2]
field[0.25,0.5;8,1;to;To:;%s]
field[0.25,1.5;8,1;cc;CC:;%s]
field[0.25,2.5;8,1;bcc;BCC:;%s]
field[0.25,3.7;8,1;subject;Subject:;%s]
textarea[0.25,4.4;8,5;body;;%s]
button[0.5,8.7;3,1;cancel;Cancel]
button[4.5,8.7;3,1;send;Send]
]] .. theme
formspec = string.format(formspec,
minetest.formspec_escape(defaultto),
minetest.formspec_escape(defaultcc) or "",
minetest.formspec_escape(defaultbcc) or "",
minetest.formspec_escape(defaultsubj),
minetest.formspec_escape(defaultbody),
minetest.formspec_escape(defaultcc),
minetest.formspec_escape(defaultbcc))
minetest.formspec_escape(defaultbody))
minetest.show_formspec(name, "mail:compose", formspec)
end
@ -221,8 +220,8 @@ function mail.handle_receivefields(player, formname, fields)
mail.send({
from = player:get_player_name(),
to = fields.to,
cc = "",
bcc = ""
cc = fields.cc,
bcc = fields.bcc,
subject = fields.subject,
body = fields.body
})

View file

@ -2,7 +2,7 @@
return the field normalized (comma separated, single space)
and add individual player names to recipient list
--]]
function normalize_players_and_add_recipients(field, recipients)
function mail.normalize_players_and_add_recipients(field, recipients)
local separator = ", "
local pattern = "([^" .. separator .. "]+)"