Generate interleaved style when replying/forwarding a message (#120)

This commit is contained in:
Athozus 2023-12-07 22:01:05 +01:00
parent 802f9f727b
commit e32cc6fa6b
No known key found for this signature in database
GPG key ID: B50895022E8484BF

View file

@ -3,6 +3,16 @@ local S = minetest.get_translator("mail")
local FORMNAME = "mail:message"
local function interleaveMsg(body)
local lines = (body or ""):split("\n", true)
local il_lines = {}
for _,l in ipairs(lines) do
il_lines[#il_lines+1] = "> " .. l
end
return table.concat(il_lines, "\n")
end
function mail.show_message(name, id)
local message = mail.get_message(name, id)
if not message then
@ -65,8 +75,7 @@ function mail.reply(name, message)
minetest.log("error", "[mail] current mail-context: " .. dump(mail.selected_idxs))
return
end
local replyfooter = "Type your reply here.\n\n--Original message follows--\n" ..message.body
mail.show_compose(name, message.from, "Re: "..message.subject, replyfooter)
mail.show_compose(name, message.from, "Re: "..message.subject, interleaveMsg(message.body))
end
function mail.replyall(name, message)
@ -77,8 +86,6 @@ function mail.replyall(name, message)
return
end
local replyfooter = "Type your reply here.\n\n--Original message follows--\n" ..message.body
-- new recipients are the sender plus the original recipients, minus ourselves
local recipients = message.to or ""
if message.from ~= nil then
@ -103,12 +110,11 @@ function mail.replyall(name, message)
end
cc = mail.concat_player_list(cc)
mail.show_compose(name, recipients, "Re: "..message.subject, replyfooter, cc)
mail.show_compose(name, recipients, "Re: "..message.subject, interleaveMsg(message.body), cc)
end
function mail.forward(name, message)
local fwfooter = "Type your message here.\n\n--Original message follows--\n" .. (message.body or "")
mail.show_compose(name, "", "Fw: " .. (message.subject or ""), fwfooter)
mail.show_compose(name, "", "Fw: " .. (message.subject or ""), interleaveMsg(message.body))
end
minetest.register_on_player_receive_fields(function(player, formname, fields)