2023-03-31 18:47:36 +03:00
|
|
|
-- translation
|
|
|
|
local S = minetest.get_translator("mail")
|
|
|
|
|
2023-03-29 18:25:01 +03:00
|
|
|
local FORMNAME = "mail:message"
|
|
|
|
|
2023-12-09 02:01:21 +03:00
|
|
|
local function interleaveMsg(body)
|
|
|
|
return "> " .. (body or ""):gsub("\n", "\n> ")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2023-03-29 18:25:01 +03:00
|
|
|
function mail.show_message(name, id)
|
|
|
|
local message = mail.get_message(name, id)
|
2023-10-23 11:08:56 +03:00
|
|
|
if not message then
|
|
|
|
-- message not found or vanished
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-10-16 21:32:06 +03:00
|
|
|
mail.selected_idxs.message[name] = id
|
2023-03-29 18:25:01 +03:00
|
|
|
|
|
|
|
local formspec = [[
|
|
|
|
size[8,9]
|
|
|
|
|
2023-12-06 12:11:12 +03:00
|
|
|
box[0,0;7,1.9;]] .. mail.get_color("highlighted") .. [[]
|
2023-03-29 18:25:01 +03:00
|
|
|
|
|
|
|
button[7.25,0.15;0.75,0.5;back;X]
|
|
|
|
|
2023-03-29 20:23:16 +03:00
|
|
|
label[0.2,0.1;]] .. S("From") .. [[: %s]
|
|
|
|
label[0.2,0.5;]] .. S("To") .. [[: %s]
|
|
|
|
label[0.2,0.9;]] .. S("CC") .. [[: %s]
|
|
|
|
label[0.2,1.3;]] .. S("Date") .. [[: %s]
|
2023-07-16 20:42:08 +03:00
|
|
|
tooltip[0.2,1.3;4.8,0.4;]] .. mail.time_ago(message.time) .. [[]
|
2023-06-25 20:59:38 +03:00
|
|
|
button[5.1,1;2,1;receivers;]] .. S("Receivers") .. [[]
|
2023-03-29 18:25:01 +03:00
|
|
|
|
2023-03-29 20:23:16 +03:00
|
|
|
label[0,2.1;]] .. S("Subject") .. [[: %s]
|
2023-03-29 18:25:01 +03:00
|
|
|
textarea[0.25,2.6;8,7.0;;;%s]
|
|
|
|
|
2023-03-29 20:23:16 +03:00
|
|
|
button[0,8.5;2,1;reply;]] .. S("Reply") .. [[]
|
|
|
|
button[2,8.5;2,1;replyall;]] .. S("Reply all") .. [[]
|
|
|
|
button[4,8.5;2,1;forward;]] .. S("Forward") .. [[]
|
|
|
|
button[6,8.5;2,1;delete;]] .. S("Delete") .. [[]
|
2023-07-16 21:05:23 +03:00
|
|
|
|
|
|
|
tooltip[reply;]] .. S("Reply only to the sender") .. [[]
|
|
|
|
tooltip[replyall;]] .. S("Reply to all involved people") .. [[]
|
|
|
|
tooltip[forward;]] .. S("Transfer message to other people") .. [[]
|
2023-03-29 18:25:01 +03:00
|
|
|
]] .. mail.theme
|
|
|
|
|
|
|
|
local from = minetest.formspec_escape(message.from) or ""
|
|
|
|
local to = minetest.formspec_escape(message.to) or ""
|
2023-06-25 20:59:38 +03:00
|
|
|
if string.len(to) > 70 then to = string.sub(to, 1, 67) .. "..." end
|
2023-03-29 18:25:01 +03:00
|
|
|
local cc = minetest.formspec_escape(message.cc) or ""
|
2023-06-25 20:59:38 +03:00
|
|
|
if string.len(cc) > 50 then cc = string.sub(cc, 1, 47) .. "..." end
|
2023-03-29 18:25:01 +03:00
|
|
|
local date = type(message.time) == "number"
|
2023-07-17 17:45:57 +03:00
|
|
|
and minetest.formspec_escape(os.date(mail.get_setting(name, "date_format"), message.time)) or ""
|
2023-03-29 18:25:01 +03:00
|
|
|
local subject = minetest.formspec_escape(message.subject) or ""
|
|
|
|
local body = minetest.formspec_escape(message.body) or ""
|
|
|
|
formspec = string.format(formspec, from, to, cc, date, subject, body)
|
|
|
|
|
2023-07-16 23:59:56 +03:00
|
|
|
if not message.read and mail.get_setting(name, "auto_marking_read") then
|
2023-03-29 18:25:01 +03:00
|
|
|
-- mark as read
|
|
|
|
mail.mark_read(name, id)
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.show_formspec(name, FORMNAME, formspec)
|
|
|
|
end
|
|
|
|
|
|
|
|
function mail.reply(name, message)
|
2023-05-17 17:16:42 +03:00
|
|
|
if not message then
|
|
|
|
-- TODO: workaround for https://github.com/mt-mods/mail/issues/84
|
|
|
|
minetest.log("error", "[mail] reply called with nil message for player: " .. name)
|
|
|
|
minetest.log("error", "[mail] current mail-context: " .. dump(mail.selected_idxs))
|
|
|
|
return
|
|
|
|
end
|
2023-12-09 02:01:21 +03:00
|
|
|
mail.show_compose(name, message.from, "Re: "..message.subject, interleaveMsg(message.body))
|
2023-03-29 18:25:01 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
function mail.replyall(name, message)
|
2023-05-17 17:16:42 +03:00
|
|
|
if not message then
|
|
|
|
-- TODO: workaround for https://github.com/mt-mods/mail/issues/84
|
|
|
|
minetest.log("error", "[mail] replyall called with nil message for player: " .. name)
|
|
|
|
minetest.log("error", "[mail] current mail-context: " .. dump(mail.selected_idxs))
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-03-29 18:25:01 +03:00
|
|
|
-- new recipients are the sender plus the original recipients, minus ourselves
|
|
|
|
local recipients = message.to or ""
|
|
|
|
if message.from ~= nil then
|
|
|
|
recipients = message.from .. ", " .. recipients
|
|
|
|
end
|
|
|
|
recipients = mail.parse_player_list(recipients)
|
|
|
|
for k,v in pairs(recipients) do
|
|
|
|
if v == name then
|
|
|
|
table.remove(recipients, k)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
recipients = mail.concat_player_list(recipients)
|
|
|
|
|
|
|
|
-- new CC is old CC minus ourselves
|
|
|
|
local cc = mail.parse_player_list(message.cc)
|
|
|
|
for k,v in pairs(cc) do
|
|
|
|
if v == name then
|
|
|
|
table.remove(cc, k)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
cc = mail.concat_player_list(cc)
|
|
|
|
|
2023-12-09 02:01:21 +03:00
|
|
|
mail.show_compose(name, recipients, "Re: "..message.subject, interleaveMsg(message.body), cc)
|
2023-03-29 18:25:01 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
function mail.forward(name, message)
|
2023-12-09 02:01:21 +03:00
|
|
|
mail.show_compose(name, "", "Fw: " .. (message.subject or ""), interleaveMsg(message.body))
|
2023-03-29 18:25:01 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
|
if formname ~= FORMNAME then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local name = player:get_player_name()
|
2023-10-16 21:32:06 +03:00
|
|
|
|
|
|
|
local message = mail.get_message(name, mail.selected_idxs.message[name])
|
2023-06-17 17:24:21 +03:00
|
|
|
|
2023-03-29 18:25:01 +03:00
|
|
|
if fields.back then
|
|
|
|
mail.show_mail_menu(name)
|
|
|
|
return true -- don't uselessly set messages
|
|
|
|
|
|
|
|
elseif fields.reply then
|
|
|
|
mail.reply(name, message)
|
|
|
|
|
|
|
|
elseif fields.replyall then
|
|
|
|
mail.replyall(name, message)
|
|
|
|
|
|
|
|
elseif fields.forward then
|
|
|
|
mail.forward(name, message)
|
|
|
|
|
|
|
|
elseif fields.delete then
|
2023-06-17 17:49:12 +03:00
|
|
|
if mail.get_setting(name, "trash_move_enable") and mail.selected_idxs.boxtab[name] ~= 4 then
|
2023-06-17 17:24:21 +03:00
|
|
|
mail.trash_mail(name, message.id)
|
|
|
|
else
|
2023-06-17 17:49:12 +03:00
|
|
|
mail.delete_mail(name, message.id, true)
|
2023-03-29 18:25:01 +03:00
|
|
|
end
|
|
|
|
mail.show_mail_menu(name)
|
2023-06-25 20:59:38 +03:00
|
|
|
|
|
|
|
elseif fields.receivers then
|
|
|
|
mail.show_receivers(name, message.id)
|
2023-03-29 18:25:01 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
2023-03-29 20:23:16 +03:00
|
|
|
end)
|