2023-02-24 00:41:41 +03:00
|
|
|
local has_canonical_name = minetest.get_modpath("canonical_name")
|
|
|
|
|
2020-07-31 13:36:28 +03:00
|
|
|
--[[
|
|
|
|
return the field normalized (comma separated, single space)
|
|
|
|
and add individual player names to recipient list
|
|
|
|
--]]
|
2023-02-24 00:41:41 +03:00
|
|
|
function mail.normalize_players_and_add_recipients(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)
|
2023-03-29 18:25:01 +03:00
|
|
|
for _, recipient_name in ipairs(order) do
|
|
|
|
if not minetest.player_exists(recipient_name) then
|
|
|
|
undeliverable[recipient_name] = true
|
2023-02-24 00:41:41 +03:00
|
|
|
else
|
2023-03-29 18:25:01 +03:00
|
|
|
recipients[recipient_name] = true
|
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
|
|
|
end
|
|
|
|
end
|
|
|
|
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
|
|
|
|
|
2020-07-31 13:36:28 +03:00
|
|
|
local separator = ", "
|
|
|
|
local pattern = "([^" .. separator .. "]+)"
|
|
|
|
|
|
|
|
-- get individual players
|
|
|
|
local player_set = {}
|
|
|
|
local order = {}
|
2023-02-24 00:41:41 +03:00
|
|
|
field:gsub(pattern, function(player_name)
|
|
|
|
local lower = string.lower(player_name)
|
|
|
|
if not player_set[lower] then
|
|
|
|
if has_canonical_name then
|
|
|
|
player_name = canonical_name.get(player_name) or player_name
|
|
|
|
end
|
|
|
|
|
|
|
|
player_set[lower] = player_name
|
|
|
|
order[#order+1] = player_name
|
2020-07-31 13:36:28 +03:00
|
|
|
end
|
|
|
|
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
|
|
|
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
|