mirror of
https://github.com/mt-mods/mail.git
synced 2025-07-05 14:10:31 -04:00
rename api, add cc and bcc, handle multiple players
rename: src -> from, dst -> to
This commit is contained in:
parent
2d087eaa13
commit
522eb0a9ee
5 changed files with 115 additions and 21 deletions
26
util/normalize.lua
Normal file
26
util/normalize.lua
Normal file
|
@ -0,0 +1,26 @@
|
|||
--[[
|
||||
return the field normalized (comma separated, single space)
|
||||
and add individual player names to recipient list
|
||||
--]]
|
||||
function normalize_players_and_add_recipients(field, recipients)
|
||||
local separator = ", "
|
||||
local pattern = "([^" .. separator .. "]+)"
|
||||
|
||||
-- get individual players
|
||||
local player_set = {}
|
||||
local order = {}
|
||||
field:gsub(pattern, function(c)
|
||||
if player_set[string.lower(c)] ~= nil then
|
||||
player_set[string.lower(c)] = c
|
||||
order[#order+1] = c
|
||||
|
||||
-- also sort into recipients
|
||||
if recipients[string.lower(c)] ~= nil then
|
||||
recipients[string.lower(c)] = c
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- turn list of players back into normalized string
|
||||
return table.concat(order, ", ")
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue