2024-02-01 22:46:26 +03:00
|
|
|
local S = minetest.get_translator("mail")
|
|
|
|
|
|
|
|
local function recursive_expand_recipient_names(sender, list, is_toplevel, recipients, undeliverable)
|
|
|
|
for _, name in ipairs(list) do
|
|
|
|
if not (recipients[name] or undeliverable[name] or (name == sender and not is_toplevel)) then
|
|
|
|
local succ, value
|
|
|
|
for _, handler in ipairs(mail.registered_recipient_handlers) do
|
|
|
|
succ, value = handler(sender, name)
|
|
|
|
if succ ~= nil then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local vtp = type(value)
|
|
|
|
if succ then
|
|
|
|
if vtp == "string" then
|
|
|
|
recursive_expand_recipient_names(sender, {value}, is_toplevel, recipients, undeliverable)
|
|
|
|
elseif vtp == "table" then
|
|
|
|
recursive_expand_recipient_names(sender, value, false, recipients, undeliverable)
|
|
|
|
elseif vtp == "function" then
|
|
|
|
recipients[name] = value
|
|
|
|
else
|
|
|
|
undeliverable[name] = S("The method of delivery to @1 is invalid.", name)
|
|
|
|
end
|
|
|
|
elseif succ == nil then
|
|
|
|
undeliverable[name] = S("The recipient @1 could not be identified.", name)
|
|
|
|
else
|
|
|
|
local reason = tostring(value) or S("@1 rejected your mail.", name)
|
|
|
|
undeliverable[name] = reason
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-02-24 00:41:41 +03:00
|
|
|
|
2020-07-31 13:36:28 +03:00
|
|
|
--[[
|
|
|
|
return the field normalized (comma separated, single space)
|
|
|
|
and add individual player names to recipient list
|
|
|
|
--]]
|
2024-02-01 22:46:26 +03:00
|
|
|
function mail.normalize_players_and_add_recipients(sender, field, recipients, undeliverable)
|
fix some things, adjust GUI elements
- messages are now actually sent (bug in parse player list)
- no more crashes on sending mail (forgot to make variables local)
- actually handle CC and BCC fields instead of leaving them empty, duh
- make new functions be under the mail namespace
- add util functions to ensure the new format, parse and player list as well as checking whether a player is in that list or not
- rearrange some GUI elements (tighter spacing, grouping, increase window height to be consistent)
- convert mails to new format only as needed (old mails stay intact in case someone reverts to old version)
- mails are shaded differently in inbox, depending on whether the player is in the TO field
- FROM, TO and CC fields are all displayed when reading a mail
- add "Reply All" button (TO includes all original recipients plus the sender, but excluding the player himself, while adopting the CC field. To contrast: "Reply" just sets the original sender as TO and leaves the rest empty)
- move reply, replyall and forward to their own functions in GUI (was duplicated for inbox and show mail)
- don't needlessly set messages table when we do nothing but go back
2020-08-10 12:43:10 +03:00
|
|
|
local order = mail.parse_player_list(field)
|
2024-02-01 22:46:26 +03:00
|
|
|
recursive_expand_recipient_names(sender, order, true, recipients, undeliverable)
|
fix some things, adjust GUI elements
- messages are now actually sent (bug in parse player list)
- no more crashes on sending mail (forgot to make variables local)
- actually handle CC and BCC fields instead of leaving them empty, duh
- make new functions be under the mail namespace
- add util functions to ensure the new format, parse and player list as well as checking whether a player is in that list or not
- rearrange some GUI elements (tighter spacing, grouping, increase window height to be consistent)
- convert mails to new format only as needed (old mails stay intact in case someone reverts to old version)
- mails are shaded differently in inbox, depending on whether the player is in the TO field
- FROM, TO and CC fields are all displayed when reading a mail
- add "Reply All" button (TO includes all original recipients plus the sender, but excluding the player himself, while adopting the CC field. To contrast: "Reply" just sets the original sender as TO and leaves the rest empty)
- move reply, replyall and forward to their own functions in GUI (was duplicated for inbox and show mail)
- don't needlessly set messages table when we do nothing but go back
2020-08-10 12:43:10 +03:00
|
|
|
return mail.concat_player_list(order)
|
|
|
|
end
|
|
|
|
|
|
|
|
function mail.parse_player_list(field)
|
2020-10-30 17:04:18 +03:00
|
|
|
if not field then
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
2024-02-01 22:46:26 +03:00
|
|
|
local separator = ",%s"
|
2020-07-31 13:36:28 +03:00
|
|
|
local pattern = "([^" .. separator .. "]+)"
|
|
|
|
|
|
|
|
-- get individual players
|
|
|
|
local order = {}
|
2024-02-01 22:46:26 +03:00
|
|
|
for name in field:gmatch(pattern) do
|
|
|
|
table.insert(order, name)
|
|
|
|
end
|
2020-07-31 13:36:28 +03:00
|
|
|
|
fix some things, adjust GUI elements
- messages are now actually sent (bug in parse player list)
- no more crashes on sending mail (forgot to make variables local)
- actually handle CC and BCC fields instead of leaving them empty, duh
- make new functions be under the mail namespace
- add util functions to ensure the new format, parse and player list as well as checking whether a player is in that list or not
- rearrange some GUI elements (tighter spacing, grouping, increase window height to be consistent)
- convert mails to new format only as needed (old mails stay intact in case someone reverts to old version)
- mails are shaded differently in inbox, depending on whether the player is in the TO field
- FROM, TO and CC fields are all displayed when reading a mail
- add "Reply All" button (TO includes all original recipients plus the sender, but excluding the player himself, while adopting the CC field. To contrast: "Reply" just sets the original sender as TO and leaves the rest empty)
- move reply, replyall and forward to their own functions in GUI (was duplicated for inbox and show mail)
- don't needlessly set messages table when we do nothing but go back
2020-08-10 12:43:10 +03:00
|
|
|
return order
|
|
|
|
end
|
|
|
|
|
|
|
|
function mail.concat_player_list(order)
|
2020-07-31 13:36:28 +03:00
|
|
|
-- turn list of players back into normalized string
|
|
|
|
return table.concat(order, ", ")
|
|
|
|
end
|
fix some things, adjust GUI elements
- messages are now actually sent (bug in parse player list)
- no more crashes on sending mail (forgot to make variables local)
- actually handle CC and BCC fields instead of leaving them empty, duh
- make new functions be under the mail namespace
- add util functions to ensure the new format, parse and player list as well as checking whether a player is in that list or not
- rearrange some GUI elements (tighter spacing, grouping, increase window height to be consistent)
- convert mails to new format only as needed (old mails stay intact in case someone reverts to old version)
- mails are shaded differently in inbox, depending on whether the player is in the TO field
- FROM, TO and CC fields are all displayed when reading a mail
- add "Reply All" button (TO includes all original recipients plus the sender, but excluding the player himself, while adopting the CC field. To contrast: "Reply" just sets the original sender as TO and leaves the rest empty)
- move reply, replyall and forward to their own functions in GUI (was duplicated for inbox and show mail)
- don't needlessly set messages table when we do nothing but go back
2020-08-10 12:43:10 +03:00
|
|
|
|
|
|
|
function mail.player_in_list(name, list)
|
2020-08-12 13:23:46 +03:00
|
|
|
list = list or {}
|
fix some things, adjust GUI elements
- messages are now actually sent (bug in parse player list)
- no more crashes on sending mail (forgot to make variables local)
- actually handle CC and BCC fields instead of leaving them empty, duh
- make new functions be under the mail namespace
- add util functions to ensure the new format, parse and player list as well as checking whether a player is in that list or not
- rearrange some GUI elements (tighter spacing, grouping, increase window height to be consistent)
- convert mails to new format only as needed (old mails stay intact in case someone reverts to old version)
- mails are shaded differently in inbox, depending on whether the player is in the TO field
- FROM, TO and CC fields are all displayed when reading a mail
- add "Reply All" button (TO includes all original recipients plus the sender, but excluding the player himself, while adopting the CC field. To contrast: "Reply" just sets the original sender as TO and leaves the rest empty)
- move reply, replyall and forward to their own functions in GUI (was duplicated for inbox and show mail)
- don't needlessly set messages table when we do nothing but go back
2020-08-10 12:43:10 +03:00
|
|
|
if type(list) == "string" then
|
|
|
|
list = mail.parse_player_list(list)
|
|
|
|
end
|
2023-02-24 00:41:41 +03:00
|
|
|
for _, player_name in pairs(list) do
|
|
|
|
if name == player_name then
|
fix some things, adjust GUI elements
- messages are now actually sent (bug in parse player list)
- no more crashes on sending mail (forgot to make variables local)
- actually handle CC and BCC fields instead of leaving them empty, duh
- make new functions be under the mail namespace
- add util functions to ensure the new format, parse and player list as well as checking whether a player is in that list or not
- rearrange some GUI elements (tighter spacing, grouping, increase window height to be consistent)
- convert mails to new format only as needed (old mails stay intact in case someone reverts to old version)
- mails are shaded differently in inbox, depending on whether the player is in the TO field
- FROM, TO and CC fields are all displayed when reading a mail
- add "Reply All" button (TO includes all original recipients plus the sender, but excluding the player himself, while adopting the CC field. To contrast: "Reply" just sets the original sender as TO and leaves the rest empty)
- move reply, replyall and forward to their own functions in GUI (was duplicated for inbox and show mail)
- don't needlessly set messages table when we do nothing but go back
2020-08-10 12:43:10 +03:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|