mail/util/normalize.lua
Peter Nerlich 522eb0a9ee rename api, add cc and bcc, handle multiple players
rename: src -> from, dst -> to
2020-07-31 12:36:28 +02:00

27 lines
781 B
Lua

--[[
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